Skip to content

Commit a3b0351

Browse files
committed
Add tests to watch.go
This commit adds unit tests for watch.go As of now part of tests are implemented, I'll add additional tests.
1 parent b43c259 commit a3b0351

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/go-logr/logr v0.3.0
1010
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
1111
github.com/prometheus/client_golang v1.7.1
12+
github.com/stretchr/testify v1.5.1
1213
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
1314
golang.org/x/tools v0.0.0-20200714190737-9048b464a08d
1415
k8s.io/api v0.20.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,11 @@ github.com/mailru/easyjson v0.7.0 h1:aizVhC/NAAcKWb+5QsU1iNOZb4Yws5UO2I+aIprQITM
475475
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
476476
github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s=
477477
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
478+
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
478479
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
479480
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
480481
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
482+
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
481483
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
482484
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
483485
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package declarative
2+
3+
import (
4+
"testing"
5+
6+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
7+
"k8s.io/apimachinery/pkg/runtime/schema"
8+
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative/pkg/manifest"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func Test_uniqueGroupVersionKind(t *testing.T) {
14+
sa := &unstructured.Unstructured{
15+
Object: map[string]interface{}{
16+
"apiVersion": "v1",
17+
"kind": "ServiceAccount",
18+
"metadata": map[string]interface{}{
19+
"name": "foo-operator",
20+
"namespace": "kube-system",
21+
},
22+
},
23+
}
24+
saObj, _ := manifest.NewObject(sa)
25+
26+
tests := []struct {
27+
name string
28+
inputObjects *manifest.Objects
29+
expectSchema []schema.GroupVersionKind
30+
}{
31+
{
32+
name: "single object",
33+
inputObjects: &manifest.Objects{
34+
Items: []*manifest.Object{
35+
saObj,
36+
},
37+
},
38+
expectSchema: []schema.GroupVersionKind{
39+
{
40+
Group: "",
41+
Version: "v1",
42+
Kind: "ServiceAccount",
43+
},
44+
},
45+
},
46+
}
47+
48+
for _, tt := range tests {
49+
t.Run(tt.name, func(t *testing.T) {
50+
actualSchema := uniqueGroupVersionKind(tt.inputObjects)
51+
assert.Equal(t, tt.expectSchema, actualSchema)
52+
})
53+
}
54+
}

0 commit comments

Comments
 (0)