-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathschema_test.go
101 lines (95 loc) · 2.9 KB
/
schema_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package kubernetes //nolint:testpackage
import (
"testing"
"go.arcalot.io/assert"
)
func TestIdentifier(t *testing.T) {
for _, item := range []any{"i", "1", "test"} {
t.Run(item.(string), func(t *testing.T) {
unserializedData, err := identifier.Unserialize(item)
assert.NoError(t, err)
assert.Equals(t, unserializedData.(string), item.(string))
assert.NoError(t, identifier.Validate(item))
})
}
for _, item := range []any{"", "Hello world!", "$"} {
t.Run(item.(string), func(t *testing.T) {
_, err := identifier.Unserialize(item)
if err == nil {
t.Fatalf("No error returned")
}
})
}
}
func TestImageTag(t *testing.T) {
for _, item := range []any{"quay.io/arcalot/example:latest", "quay.io/arcalot/example", "arcalot/example"} {
t.Run(item.(string), func(t *testing.T) {
unserializedData, err := imageTag.Unserialize(item)
assert.NoError(t, err)
assert.Equals(t, unserializedData.(string), item.(string))
assert.NoError(t, imageTag.Validate(item))
})
}
for _, item := range []any{"", "Hello world!", "$"} {
t.Run(item.(string), func(t *testing.T) {
_, err := imageTag.Unserialize(item)
if err == nil {
t.Fatalf("No error returned")
}
})
}
}
func TestLabelName(t *testing.T) {
for _, item := range []any{"kubernetes.io/test", "test"} {
t.Run(item.(string), func(t *testing.T) {
unserializedData, err := labelName.Unserialize(item)
assert.NoError(t, err)
assert.Equals(t, unserializedData.(string), item.(string))
assert.NoError(t, labelName.Validate(item))
})
}
for _, item := range []any{"", "kubernetes.io/test/test", "$"} {
t.Run(item.(string), func(t *testing.T) {
_, err := labelName.Unserialize(item)
if err == nil {
t.Fatalf("No error returned")
}
})
}
}
func TestLabelValue(t *testing.T) {
for _, item := range []any{"", "kubernetes.io_test", "test-1-0"} {
t.Run(item.(string), func(t *testing.T) {
unserializedData, err := labelValue.Unserialize(item)
assert.NoError(t, err)
assert.Equals(t, unserializedData.(string), item.(string))
assert.NoError(t, labelValue.Validate(item))
})
}
for _, item := range []any{"kubernetes.io/test", "kubernetes.io/test/test", "$"} {
t.Run(item.(string), func(t *testing.T) {
_, err := labelValue.Unserialize(item)
if err == nil {
t.Fatalf("No error returned")
}
})
}
}
func TestDNSSubdomainName(t *testing.T) {
for _, item := range []any{"arcalot", "arcalot_io", "arcalot123"} {
t.Run(item.(string), func(t *testing.T) {
unserializedData, err := dnsSubdomainName.Unserialize(item)
assert.NoError(t, err)
assert.Equals(t, unserializedData.(string), item.(string))
assert.NoError(t, dnsSubdomainName.Validate(item))
})
}
for _, item := range []any{"arcalot.", "kubernetes.io/test/test", "$"} {
t.Run(item.(string), func(t *testing.T) {
_, err := dnsSubdomainName.Unserialize(item)
if err == nil {
t.Fatalf("No error returned")
}
})
}
}