forked from jmespath/go-jmespath
-
Notifications
You must be signed in to change notification settings - Fork 10
/
util_test.go
74 lines (64 loc) · 1.69 KB
/
util_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
package jmespath
import (
"testing"
"github.com/kyverno/go-jmespath/internal/testify/assert"
)
func TestSlicePositiveStep(t *testing.T) {
assert := assert.New(t)
input := make([]interface{}, 5)
input[0] = 0
input[1] = 1
input[2] = 2
input[3] = 3
input[4] = 4
result, err := slice(input, []sliceParam{{0, true}, {3, true}, {1, true}})
assert.Nil(err)
assert.Equal(input[:3], result)
}
func TestIsFalseJSONTypes(t *testing.T) {
assert := assert.New(t)
assert.True(isFalse(false))
assert.True(isFalse(""))
var empty []interface{}
assert.True(isFalse(empty))
m := make(map[string]interface{})
assert.True(isFalse(m))
assert.True(isFalse(nil))
}
func TestIsFalseWithUserDefinedStructs(t *testing.T) {
assert := assert.New(t)
type nilStructType struct {
SliceOfPointers []*string
}
nilStruct := nilStructType{SliceOfPointers: nil}
assert.True(isFalse(nilStruct.SliceOfPointers))
// A user defined struct will never be false though,
// even if it's fields are the zero type.
assert.False(isFalse(nilStruct))
}
func TestIsFalseWithNilInterface(t *testing.T) {
assert := assert.New(t)
var a *int
var nilInterface interface{}
nilInterface = a
assert.True(isFalse(nilInterface))
}
func TestIsFalseWithMapOfUserStructs(t *testing.T) {
assert := assert.New(t)
type foo struct {
Bar string
Baz string
}
m := make(map[int]foo)
assert.True(isFalse(m))
}
func TestObjsEqual(t *testing.T) {
assert := assert.New(t)
assert.True(objsEqual("foo", "foo"))
assert.True(objsEqual(20, 20))
assert.True(objsEqual([]int{1, 2, 3}, []int{1, 2, 3}))
assert.True(objsEqual(nil, nil))
assert.True(!objsEqual(nil, "foo"))
assert.True(objsEqual([]int{}, []int{}))
assert.True(!objsEqual([]int{}, nil))
}