Skip to content

Commit a94c15b

Browse files
committed
refactor testTomlStr to be reusable in test functions; drop copy-pasta comment
1 parent d682d6e commit a94c15b

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

cuecfg/cuecfg_test.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,44 @@ import (
66
"github.com/stretchr/testify/require"
77
)
88

9+
type Metadata struct {
10+
Tags []string
11+
}
12+
913
type MyConfig struct {
1014
Version int
1115
Name string
12-
Tags []string
16+
Meta *Metadata
1317
}
1418

1519
var testTomlCfg = &MyConfig{
1620
Version: 2,
1721
Name: "go-toml",
18-
Tags: []string{"go", "toml"},
22+
Meta: &Metadata{
23+
Tags: []string{"go", "toml"},
24+
},
1925
}
2026

27+
var testTomlStr = `Version = 2
28+
Name = 'go-toml'
29+
30+
[Meta]
31+
Tags = ['go', 'toml']
32+
`
33+
2134
func TestMarshalToml(t *testing.T) {
2235
req := require.New(t)
2336

2437
bytes, err := Marshal(testTomlCfg, ".toml")
2538
req.NoError(err)
2639

27-
expected := `Version = 2
28-
Name = 'go-toml'
29-
Tags = ['go', 'toml']
30-
`
31-
req.Equal(expected, string(bytes))
40+
req.Equal(testTomlStr, string(bytes))
3241
}
3342

3443
func TestUnmarshalToml(t *testing.T) {
3544
req := require.New(t)
36-
tomlStr := `Version = 2
37-
Name = 'go-toml'
38-
Tags = ['go', 'toml']
39-
`
4045
cfg := &MyConfig{}
41-
err := Unmarshal([]byte(tomlStr), ".toml", cfg)
46+
err := Unmarshal([]byte(testTomlStr), ".toml", cfg)
4247
req.NoError(err)
4348
req.Equal(testTomlCfg, cfg)
4449
}

cuecfg/toml.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import (
77
"github.com/pelletier/go-toml/v2"
88
)
99

10-
// TODO: consider using cue's JSON marshaller instead of
11-
// "encoding/json" ... it might have extra functionality related
12-
// to the cue language.
1310
func MarshalToml(v interface{}) ([]byte, error) {
1411
return toml.Marshal(v)
1512
}

0 commit comments

Comments
 (0)