-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathassert_test.go
94 lines (83 loc) · 1.56 KB
/
assert_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package testutil
import (
"testing"
"github.com/stretchr/testify/assert"
yaml "gopkg.in/yaml.v2"
)
var actualYAML = `
string: value
string2: "1.0"
list:
- element1
- element2
- element3
map:
key1: value1
key2: value2
number: 1
uuid: 770b8ebe-decb-47e8-89a4-33eb0cef28b3
bool: true
nilValue: null
float: 1.0
uint: 18446744073709551615
`
var test1YAML = `
string: value
string2: "1.0"
list:
- element1
- element2
- element3
map:
key1: value1
number: 1
bool: true
float: 1.0
uint: 18446744073709551615
`
var test2YAML = `
string: value
list:
- element1
- $any
- $any
map:
key1: $any
number: $number
uuid: $uuid
bool: true
nilValue: $null
`
var missingKeys = `
string: value
`
var missingKeysInNestedMap = `
map: {}
`
var nullMapKey = `
map: null
`
func TestAssertEquals(t *testing.T) {
tests := []struct {
name string
expected string
actual string
}{
{name: "test1", expected: test1YAML, actual: actualYAML},
{name: "test2", expected: test2YAML, actual: actualYAML},
{name: "missing keys", expected: missingKeys, actual: actualYAML},
{name: "missing keys in nested map", expected: missingKeysInNestedMap, actual: actualYAML},
{name: "null key", expected: nullMapKey, actual: actualYAML},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var actualData interface{}
err := yaml.Unmarshal([]byte(tt.actual), &actualData)
assert.NoError(t, err)
var testData interface{}
err = yaml.Unmarshal([]byte(tt.expected), &testData)
assert.NoError(t, err)
AssertEqual(t, testData, actualData, "check same data: %s")
})
}
}