-
Notifications
You must be signed in to change notification settings - Fork 0
/
conditions_test.go
64 lines (55 loc) · 1.36 KB
/
conditions_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
package hypermatch
import (
"encoding/json"
"gotest.tools/v3/assert"
"log"
"testing"
)
func TestConditions_MarshalJSON(t *testing.T) {
r := ConditionSet{
{
Path: "name",
Pattern: Pattern{
Type: PatternAllOf,
Sub: []Pattern{
{Type: PatternEquals, Value: "hallo"},
{Type: PatternWildcard, Value: "hallo*"},
{Type: PatternAnythingBut, Sub: []Pattern{
{Type: PatternSuffix, Value: "test"},
{Type: PatternPrefix, Value: "st"},
}},
{Type: PatternAnyOf, Sub: []Pattern{
{Type: PatternSuffix, Value: "te"},
{Type: PatternPrefix, Value: "tet"},
}},
},
},
},
{
Path: "type",
Pattern: Pattern{
Type: PatternEquals,
Value: "test",
},
},
}
data1, err := json.Marshal(r)
assert.NilError(t, err)
log.Println(string(data1))
var u ConditionSet
assert.NilError(t, json.Unmarshal(data1, &u))
assert.Check(t, len(r) == len(u))
data2, err := json.Marshal(u)
assert.NilError(t, err)
assert.Check(t, string(data1) == string(data2))
}
func TestConditions_UnmarshalJSON(t *testing.T) {
data := []byte(`{"production": {"equals": true}}`)
var c ConditionSet
err := json.Unmarshal(data, &c)
assert.NilError(t, err)
assert.Check(t, len(c) == 1)
assert.Check(t, c[0].Path == "production")
assert.Check(t, c[0].Pattern.Type == PatternEquals)
assert.Check(t, c[0].Pattern.Value == "true")
}