forked from fluxcd/flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resourceid_test.go
39 lines (36 loc) · 929 Bytes
/
resourceid_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
package flux
import (
"testing"
)
func TestResourceIDParsing(t *testing.T) {
type test struct {
name, id string
}
valid := []test{
{"full", "namespace:kind/name"},
{"legacy", "namespace/service"},
{"dots", "namespace:kind/name.with.dots"},
{"colons", "namespace:kind/name:with:colons"},
{"punctuation in general", "name-space:ki_nd/punc_tu:a.tion-rules"},
{"cluster-scope resource", "<cluster>:namespace/foo"},
}
invalid := []test{
{"unqualified", "justname"},
{"dots in namespace", "name.space:kind/name"},
{"too many colons", "namespace:kind:name"},
}
for _, tc := range valid {
t.Run(tc.name, func(t *testing.T) {
if _, err := ParseResourceID(tc.id); err != nil {
t.Error(err)
}
})
}
for _, tc := range invalid {
t.Run(tc.name, func(t *testing.T) {
if _, err := ParseResourceID(tc.id); err == nil {
t.Errorf("expected %q to be considered invalid", tc.id)
}
})
}
}