Skip to content

Commit e42b933

Browse files
committed
feat!: drop yaml v2 support
Signed-off-by: Mark Sagi-Kazar <[email protected]>
1 parent 9e46b76 commit e42b933

File tree

10 files changed

+89
-272
lines changed

10 files changed

+89
-272
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
matrix:
4545
os: [ubuntu-latest, macos-latest, windows-latest]
4646
go: ['1.16', '1.17', '1.18', '1.19']
47-
tags: ['', 'viper_yaml2', 'viper_toml1']
47+
tags: ['', 'viper_toml1']
4848
env:
4949
GOFLAGS: -mod=readonly
5050

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ require (
1717
github.com/stretchr/testify v1.8.1
1818
github.com/subosito/gotenv v1.4.1
1919
gopkg.in/ini.v1 v1.67.0
20-
gopkg.in/yaml.v2 v2.4.0
2120
gopkg.in/yaml.v3 v3.0.1
2221
)
2322

internal/encoding/yaml/codec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package yaml
22

3-
// import "gopkg.in/yaml.v2"
3+
import "gopkg.in/yaml.v3"
44

55
// Codec implements the encoding.Encoder and encoding.Decoder interfaces for YAML encoding.
66
type Codec struct{}

internal/encoding/yaml/codec_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,93 @@ import (
55
"testing"
66
)
77

8+
// original form of the data
9+
const original = `# key-value pair
10+
key: value
11+
list:
12+
- item1
13+
- item2
14+
- item3
15+
map:
16+
key: value
17+
18+
# nested
19+
# map
20+
nested_map:
21+
map:
22+
key: value
23+
list:
24+
- item1
25+
- item2
26+
- item3
27+
`
28+
29+
// encoded form of the data
30+
const encoded = `key: value
31+
list:
32+
- item1
33+
- item2
34+
- item3
35+
map:
36+
key: value
37+
nested_map:
38+
map:
39+
key: value
40+
list:
41+
- item1
42+
- item2
43+
- item3
44+
`
45+
46+
// decoded form of the data
47+
//
48+
// in case of YAML it's slightly different from Viper's internal representation
49+
// (eg. map is decoded into a map with interface key)
50+
var decoded = map[string]interface{}{
51+
"key": "value",
52+
"list": []interface{}{
53+
"item1",
54+
"item2",
55+
"item3",
56+
},
57+
"map": map[string]interface{}{
58+
"key": "value",
59+
},
60+
"nested_map": map[string]interface{}{
61+
"map": map[string]interface{}{
62+
"key": "value",
63+
"list": []interface{}{
64+
"item1",
65+
"item2",
66+
"item3",
67+
},
68+
},
69+
},
70+
}
71+
72+
// Viper's internal representation
73+
var data = map[string]interface{}{
74+
"key": "value",
75+
"list": []interface{}{
76+
"item1",
77+
"item2",
78+
"item3",
79+
},
80+
"map": map[string]interface{}{
81+
"key": "value",
82+
},
83+
"nested_map": map[string]interface{}{
84+
"map": map[string]interface{}{
85+
"key": "value",
86+
"list": []interface{}{
87+
"item1",
88+
"item2",
89+
"item3",
90+
},
91+
},
92+
},
93+
}
94+
895
func TestCodec_Encode(t *testing.T) {
996
codec := Codec{}
1097

internal/encoding/yaml/yaml2.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

internal/encoding/yaml/yaml2_test.go

Lines changed: 0 additions & 91 deletions
This file was deleted.

internal/encoding/yaml/yaml3.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

internal/encoding/yaml/yaml3_test.go

Lines changed: 0 additions & 91 deletions
This file was deleted.

viper_yaml2_test.go

Lines changed: 0 additions & 56 deletions
This file was deleted.

viper_yaml3_test.go renamed to viper_yaml_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//go:build !viper_yaml2
2-
// +build !viper_yaml2
3-
41
package viper
52

63
var yamlExample = []byte(`Hacker: true

0 commit comments

Comments
 (0)