Skip to content

Commit

Permalink
Test against the alt toml array syntax (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
FollowTheProcess committed Oct 26, 2022
1 parent 3260933 commit 77857ad
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,36 @@ func TestLoad(t *testing.T) {
}
}

func TestLoadAlt(t *testing.T) {
path := makeAltConfigFile(t)

got, err := config.Load(path)
if err != nil {
t.Fatalf("config.Load returned an error: %v", err)
}

want := &config.Config{
Tag: config.Tag{
Files: []config.File{
{
Path: "hello.go",
Search: "version {{.Current}}",
Replace: "version {{.Next}}",
},
{
Path: "another.go",
Search: "version {{.Current}}",
Replace: "version {{.Next}}",
},
},
},
}

if !reflect.DeepEqual(got, want) {
t.Errorf("got %#v, wanted %#v", got, want)
}
}

func TestRender(t *testing.T) {
conf := &config.Config{
Tag: config.Tag{
Expand Down Expand Up @@ -98,3 +128,25 @@ func makeConfigFile(t *testing.T) string {

return file.Name()
}

// makeAltConfigFile creates a temporary config file with alternative TOML syntax
// returning it's path.
func makeAltConfigFile(t *testing.T) string {
file, err := os.CreateTemp("", "tag.toml")
if err != nil {
t.Fatalf("CreateTemp returned an error: %v", err)
}
defer file.Close()
doc := `
[tag]
files = [
{ path = "hello.go", search = "version {{.Current}}", replace = "version {{.Next}}"},
{ path = "another.go", search = "version {{.Current}}", replace = "version {{.Next}}"},
]`
_, err = file.WriteString(doc)
if err != nil {
t.Fatalf("Could not write to tmp file: %v", err)
}

return file.Name()
}

0 comments on commit 77857ad

Please sign in to comment.