-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniversal_workload_test.go
61 lines (53 loc) · 1.52 KB
/
universal_workload_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
package main
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)
func TestMarshalLabels(t *testing.T) {
type testStruct struct {
Hello bool `json:"hello"`
World bool `json:"world"`
Shit bool `json:"shit"`
}
ts := testStruct{Hello: true, World: false, Shit: true}
s, err := marshalLabels(ts)
require.NoError(t, err)
assert.Equal(t, "hello,shit", s)
}
func TestUnmarshalLabels(t *testing.T) {
type testStruct struct {
Hello bool `json:"hello"`
World bool `json:"world"`
Shit bool `json:"shit"`
}
var ts testStruct
s := "hello,world"
err := unmarshalLabels(s, &ts)
require.NoError(t, err)
assert.True(t, ts.Hello)
assert.True(t, ts.World)
assert.False(t, ts.Shit)
}
func TestUniversalWorkload_Set(t *testing.T) {
w := &UniversalWorkload{}
err := w.Set("test-cluster/test-ns/deployment/whoa?no_check")
require.NoError(t, err)
assert.Equal(t, "test-cluster", w.Cluster)
assert.Equal(t, "test-ns", w.Namespace)
assert.Equal(t, "deployment", w.Type)
assert.Equal(t, "whoa", w.Name)
assert.Equal(t, "whoa", w.Container)
assert.True(t, w.Labels.NoCheck)
assert.False(t, w.Labels.Init)
w = &UniversalWorkload{}
err = w.Set("test-cluster/test-ns/deployment/whoa/whoa2?no_check,init")
require.NoError(t, err)
assert.Equal(t, "test-cluster", w.Cluster)
assert.Equal(t, "test-ns", w.Namespace)
assert.Equal(t, "deployment", w.Type)
assert.Equal(t, "whoa", w.Name)
assert.Equal(t, "whoa2", w.Container)
assert.True(t, w.Labels.NoCheck)
assert.True(t, w.Labels.Init)
}