Skip to content

Commit

Permalink
feat!: drop yaml v2 support
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
  • Loading branch information
sagikazarmark committed Jan 19, 2023
1 parent 9e46b76 commit e42b933
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 272 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion internal/encoding/yaml/codec.go
Original file line number Diff line number Diff line change
@@ -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{}
Expand Down
87 changes: 87 additions & 0 deletions internal/encoding/yaml/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down
14 changes: 0 additions & 14 deletions internal/encoding/yaml/yaml2.go

This file was deleted.

91 changes: 0 additions & 91 deletions internal/encoding/yaml/yaml2_test.go

This file was deleted.

14 changes: 0 additions & 14 deletions internal/encoding/yaml/yaml3.go

This file was deleted.

91 changes: 0 additions & 91 deletions internal/encoding/yaml/yaml3_test.go

This file was deleted.

56 changes: 0 additions & 56 deletions viper_yaml2_test.go

This file was deleted.

3 changes: 0 additions & 3 deletions viper_yaml3_test.go → viper_yaml_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !viper_yaml2
// +build !viper_yaml2

package viper

var yamlExample = []byte(`Hacker: true
Expand Down

0 comments on commit e42b933

Please sign in to comment.