Skip to content

Commit 67adc56

Browse files
committed
Add resid tests.
1 parent 97a771d commit 67adc56

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

pkg/resource/resid_test.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package resource
2+
3+
import (
4+
"testing"
5+
6+
"k8s.io/apimachinery/pkg/runtime/schema"
7+
)
8+
9+
var stringTests = []struct {
10+
x ResId
11+
s string
12+
}{
13+
{ResId{gvk: schema.GroupVersionKind{Group: "g", Version: "v", Kind: "k"},
14+
name: "nm", prefix: "p", namespace: "ns"}, "g_v_k_ns_p_nm.yaml"},
15+
{ResId{gvk: schema.GroupVersionKind{Version: "v", Kind: "k"},
16+
name: "nm", prefix: "p", namespace: "ns"}, "_v_k_ns_p_nm.yaml"},
17+
{ResId{gvk: schema.GroupVersionKind{Kind: "k"},
18+
name: "nm", prefix: "p", namespace: "ns"}, "__k_ns_p_nm.yaml"},
19+
{ResId{gvk: schema.GroupVersionKind{},
20+
name: "nm", prefix: "p", namespace: "ns"}, "___ns_p_nm.yaml"},
21+
{ResId{gvk: schema.GroupVersionKind{},
22+
name: "nm", prefix: "p"}, "____p_nm.yaml"},
23+
{ResId{gvk: schema.GroupVersionKind{},
24+
name: "nm"}, "_____nm.yaml"},
25+
{ResId{gvk: schema.GroupVersionKind{}}, "_____.yaml"},
26+
{ResId{}, "_____.yaml"},
27+
}
28+
29+
func TestString(t *testing.T) {
30+
for _, hey := range stringTests {
31+
if hey.x.String() != hey.s {
32+
t.Fatalf("Actual: %v, Expected: '%s'", hey.x, hey.s)
33+
}
34+
}
35+
}
36+
37+
var gvknStringTests = []struct {
38+
x ResId
39+
s string
40+
}{
41+
{ResId{gvk: schema.GroupVersionKind{Group: "g", Version: "v", Kind: "k"},
42+
name: "nm", prefix: "p", namespace: "ns"}, "g_v_k_nm.yaml"},
43+
{ResId{gvk: schema.GroupVersionKind{Version: "v", Kind: "k"},
44+
name: "nm", prefix: "p", namespace: "ns"}, "v_k_nm.yaml"},
45+
{ResId{gvk: schema.GroupVersionKind{Kind: "k"},
46+
name: "nm", prefix: "p", namespace: "ns"}, "_k_nm.yaml"},
47+
{ResId{gvk: schema.GroupVersionKind{},
48+
name: "nm", prefix: "p", namespace: "ns"}, "__nm.yaml"},
49+
{ResId{gvk: schema.GroupVersionKind{},
50+
name: "nm", prefix: "p"}, "__nm.yaml"},
51+
{ResId{gvk: schema.GroupVersionKind{},
52+
name: "nm"}, "__nm.yaml"},
53+
{ResId{gvk: schema.GroupVersionKind{}}, "__.yaml"},
54+
{ResId{}, "__.yaml"},
55+
}
56+
57+
func TestGvknString(t *testing.T) {
58+
for _, hey := range gvknStringTests {
59+
if hey.x.GvknString() != hey.s {
60+
t.Fatalf("Actual: %s, Expected: '%s'", hey.x.GvknString(), hey.s)
61+
}
62+
}
63+
}
64+
65+
var GvknEqualsTest = []struct {
66+
x1 ResId
67+
x2 ResId
68+
}{
69+
{ResId{gvk: schema.GroupVersionKind{Group: "g", Version: "v", Kind: "k"},
70+
name: "nm", prefix: "AA", namespace: "X"},
71+
ResId{gvk: schema.GroupVersionKind{Group: "g", Version: "v", Kind: "k"},
72+
name: "nm", prefix: "BB", namespace: "Z"}},
73+
{ResId{gvk: schema.GroupVersionKind{Version: "v", Kind: "k"},
74+
name: "nm", prefix: "AA", namespace: "X"},
75+
ResId{gvk: schema.GroupVersionKind{Version: "v", Kind: "k"},
76+
name: "nm", prefix: "BB", namespace: "Z"}},
77+
{ResId{gvk: schema.GroupVersionKind{Kind: "k"},
78+
name: "nm", prefix: "AA", namespace: "X"},
79+
ResId{gvk: schema.GroupVersionKind{Kind: "k"},
80+
name: "nm", prefix: "BB", namespace: "Z"}},
81+
{ResId{name: "nm", prefix: "AA", namespace: "X"},
82+
ResId{name: "nm", prefix: "BB", namespace: "Z"}},
83+
}
84+
85+
func TestEquals(t *testing.T) {
86+
for _, hey := range GvknEqualsTest {
87+
if !hey.x1.GvknEquals(hey.x2) {
88+
t.Fatalf("%v should equal %v", hey.x1, hey.x2)
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)