Skip to content

Commit

Permalink
test(encoding): fix failing tests due to the yaml library update
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 1, 2022
1 parent ea18671 commit e3b5e08
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 111 deletions.
87 changes: 0 additions & 87 deletions internal/encoding/yaml/codec_test.go
Expand Up @@ -5,93 +5,6 @@ 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[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",
},
},
},
}

func TestCodec_Encode(t *testing.T) {
codec := Codec{}

Expand Down
91 changes: 91 additions & 0 deletions internal/encoding/yaml/yaml2_test.go
@@ -0,0 +1,91 @@
//go:build !viper_yaml3
// +build !viper_yaml3

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",
},
},
},
}
91 changes: 91 additions & 0 deletions internal/encoding/yaml/yaml3_test.go
@@ -0,0 +1,91 @@
//go:build viper_yaml3
// +build viper_yaml3

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",
},
},
},
}
48 changes: 24 additions & 24 deletions viper_test.go
Expand Up @@ -36,14 +36,14 @@ import (
var yamlExample = []byte(`Hacker: true
name: steve
hobbies:
- skateboarding
- snowboarding
- go
- skateboarding
- snowboarding
- go
clothing:
jacket: leather
trousers: denim
pants:
size: large
jacket: leather
trousers: denim
pants:
size: large
age: 35
eyes : brown
beard: true
Expand Down Expand Up @@ -1561,16 +1561,16 @@ p_batters.batter.type = Regular
var yamlWriteExpected = []byte(`age: 35
beard: true
clothing:
jacket: leather
pants:
size: large
trousers: denim
jacket: leather
pants:
size: large
trousers: denim
eyes: brown
hacker: true
hobbies:
- skateboarding
- snowboarding
- go
- skateboarding
- snowboarding
- go
name: steve
`)

Expand Down Expand Up @@ -2413,21 +2413,21 @@ func TestUnmarshal_DotSeparatorBackwardCompatibility(t *testing.T) {
var yamlExampleWithDot = []byte(`Hacker: true
name: steve
hobbies:
- skateboarding
- snowboarding
- go
- skateboarding
- snowboarding
- go
clothing:
jacket: leather
trousers: denim
pants:
size: large
jacket: leather
trousers: denim
pants:
size: large
age: 35
eyes : brown
beard: true
emails:
steve@hacker.com:
created: 01/02/03
active: true
steve@hacker.com:
created: 01/02/03
active: true
`)

func TestKeyDelimiter(t *testing.T) {
Expand Down

0 comments on commit e3b5e08

Please sign in to comment.