diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4bcdcde..4fc1a10 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -44,7 +44,7 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] go: ['1.16', '1.17', '1.18', '1.19'] - tags: ['', 'viper_yaml2', 'viper_toml1'] + tags: ['', 'viper_toml1'] env: GOFLAGS: -mod=readonly diff --git a/go.mod b/go.mod index 485a944..5ad60b7 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,6 @@ require ( github.com/stretchr/testify v1.8.1 github.com/subosito/gotenv v1.4.1 gopkg.in/ini.v1 v1.67.0 - gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/internal/encoding/yaml/codec.go b/internal/encoding/yaml/codec.go index 24cc19d..82dc136 100644 --- a/internal/encoding/yaml/codec.go +++ b/internal/encoding/yaml/codec.go @@ -1,6 +1,6 @@ package yaml -// import "gopkg.in/yaml.v2" +import "gopkg.in/yaml.v3" // Codec implements the encoding.Encoder and encoding.Decoder interfaces for YAML encoding. type Codec struct{} diff --git a/internal/encoding/yaml/codec_test.go b/internal/encoding/yaml/codec_test.go index d24a013..9fe3838 100644 --- a/internal/encoding/yaml/codec_test.go +++ b/internal/encoding/yaml/codec_test.go @@ -5,6 +5,93 @@ import ( "testing" ) +// original form of the data +const original = `# key-value pair +key: value +list: + - item1 + - item2 + - item3 +map: + key: value + +# nested +# map +nested_map: + map: + key: value + list: + - item1 + - item2 + - item3 +` + +// encoded form of the data +const encoded = `key: value +list: + - item1 + - item2 + - item3 +map: + key: value +nested_map: + map: + key: value + list: + - item1 + - item2 + - item3 +` + +// decoded form of the data +// +// in case of YAML it's slightly different from Viper's internal representation +// (eg. map is decoded into a map with interface key) +var decoded = map[string]interface{}{ + "key": "value", + "list": []interface{}{ + "item1", + "item2", + "item3", + }, + "map": map[string]interface{}{ + "key": "value", + }, + "nested_map": map[string]interface{}{ + "map": map[string]interface{}{ + "key": "value", + "list": []interface{}{ + "item1", + "item2", + "item3", + }, + }, + }, +} + +// Viper's internal representation +var data = map[string]interface{}{ + "key": "value", + "list": []interface{}{ + "item1", + "item2", + "item3", + }, + "map": map[string]interface{}{ + "key": "value", + }, + "nested_map": map[string]interface{}{ + "map": map[string]interface{}{ + "key": "value", + "list": []interface{}{ + "item1", + "item2", + "item3", + }, + }, + }, +} + func TestCodec_Encode(t *testing.T) { codec := Codec{} diff --git a/internal/encoding/yaml/yaml2.go b/internal/encoding/yaml/yaml2.go deleted file mode 100644 index 4c398c2..0000000 --- a/internal/encoding/yaml/yaml2.go +++ /dev/null @@ -1,14 +0,0 @@ -//go:build viper_yaml2 -// +build viper_yaml2 - -package yaml - -import yamlv2 "gopkg.in/yaml.v2" - -var yaml = struct { - Marshal func(in interface{}) (out []byte, err error) - Unmarshal func(in []byte, out interface{}) (err error) -}{ - Marshal: yamlv2.Marshal, - Unmarshal: yamlv2.Unmarshal, -} diff --git a/internal/encoding/yaml/yaml2_test.go b/internal/encoding/yaml/yaml2_test.go deleted file mode 100644 index 8b4fdd2..0000000 --- a/internal/encoding/yaml/yaml2_test.go +++ /dev/null @@ -1,91 +0,0 @@ -//go:build viper_yaml2 -// +build viper_yaml2 - -package yaml - -// original form of the data -const original = `# key-value pair -key: value -list: -- item1 -- item2 -- item3 -map: - key: value - -# nested -# map -nested_map: - map: - key: value - list: - - item1 - - item2 - - item3 -` - -// encoded form of the data -const encoded = `key: value -list: -- item1 -- item2 -- item3 -map: - key: value -nested_map: - map: - key: value - list: - - item1 - - item2 - - item3 -` - -// decoded form of the data -// -// in case of YAML it's slightly different from Viper's internal representation -// (eg. map is decoded into a map with interface key) -var decoded = map[string]interface{}{ - "key": "value", - "list": []interface{}{ - "item1", - "item2", - "item3", - }, - "map": map[interface{}]interface{}{ - "key": "value", - }, - "nested_map": map[interface{}]interface{}{ - "map": map[interface{}]interface{}{ - "key": "value", - "list": []interface{}{ - "item1", - "item2", - "item3", - }, - }, - }, -} - -// Viper's internal representation -var data = map[string]interface{}{ - "key": "value", - "list": []interface{}{ - "item1", - "item2", - "item3", - }, - "map": map[string]interface{}{ - "key": "value", - }, - "nested_map": map[string]interface{}{ - "map": map[string]interface{}{ - "key": "value", - "list": []interface{}{ - "item1", - "item2", - "item3", - }, - }, - }, -} diff --git a/internal/encoding/yaml/yaml3.go b/internal/encoding/yaml/yaml3.go deleted file mode 100644 index 3a4775c..0000000 --- a/internal/encoding/yaml/yaml3.go +++ /dev/null @@ -1,14 +0,0 @@ -//go:build !viper_yaml2 -// +build !viper_yaml2 - -package yaml - -import yamlv3 "gopkg.in/yaml.v3" - -var yaml = struct { - Marshal func(in interface{}) (out []byte, err error) - Unmarshal func(in []byte, out interface{}) (err error) -}{ - Marshal: yamlv3.Marshal, - Unmarshal: yamlv3.Unmarshal, -} diff --git a/internal/encoding/yaml/yaml3_test.go b/internal/encoding/yaml/yaml3_test.go deleted file mode 100644 index e6a86c2..0000000 --- a/internal/encoding/yaml/yaml3_test.go +++ /dev/null @@ -1,91 +0,0 @@ -//go:build !viper_yaml2 -// +build !viper_yaml2 - -package yaml - -// original form of the data -const original = `# key-value pair -key: value -list: - - item1 - - item2 - - item3 -map: - key: value - -# nested -# map -nested_map: - map: - key: value - list: - - item1 - - item2 - - item3 -` - -// encoded form of the data -const encoded = `key: value -list: - - item1 - - item2 - - item3 -map: - key: value -nested_map: - map: - key: value - list: - - item1 - - item2 - - item3 -` - -// decoded form of the data -// -// in case of YAML it's slightly different from Viper's internal representation -// (eg. map is decoded into a map with interface key) -var decoded = map[string]interface{}{ - "key": "value", - "list": []interface{}{ - "item1", - "item2", - "item3", - }, - "map": map[string]interface{}{ - "key": "value", - }, - "nested_map": map[string]interface{}{ - "map": map[string]interface{}{ - "key": "value", - "list": []interface{}{ - "item1", - "item2", - "item3", - }, - }, - }, -} - -// Viper's internal representation -var data = map[string]interface{}{ - "key": "value", - "list": []interface{}{ - "item1", - "item2", - "item3", - }, - "map": map[string]interface{}{ - "key": "value", - }, - "nested_map": map[string]interface{}{ - "map": map[string]interface{}{ - "key": "value", - "list": []interface{}{ - "item1", - "item2", - "item3", - }, - }, - }, -} diff --git a/viper_yaml2_test.go b/viper_yaml2_test.go deleted file mode 100644 index fa12a74..0000000 --- a/viper_yaml2_test.go +++ /dev/null @@ -1,56 +0,0 @@ -//go:build viper_yaml2 -// +build viper_yaml2 - -package viper - -var yamlExample = []byte(`Hacker: true -name: steve -hobbies: -- skateboarding -- snowboarding -- go -clothing: - jacket: leather - trousers: denim - pants: - size: large -age: 35 -eyes : brown -beard: true -`) - -var yamlWriteExpected = []byte(`age: 35 -beard: true -clothing: - jacket: leather - pants: - size: large - trousers: denim -eyes: brown -hacker: true -hobbies: -- skateboarding -- snowboarding -- go -name: steve -`) - -var yamlExampleWithDot = []byte(`Hacker: true -name: steve -hobbies: -- skateboarding -- snowboarding -- go -clothing: - jacket: leather - trousers: denim - pants: - size: large -age: 35 -eyes : brown -beard: true -emails: - steve@hacker.com: - created: 01/02/03 - active: true -`) diff --git a/viper_yaml3_test.go b/viper_yaml_test.go similarity index 94% rename from viper_yaml3_test.go rename to viper_yaml_test.go index ba2d8d7..264446b 100644 --- a/viper_yaml3_test.go +++ b/viper_yaml_test.go @@ -1,6 +1,3 @@ -//go:build !viper_yaml2 -// +build !viper_yaml2 - package viper var yamlExample = []byte(`Hacker: true