1 package resourcename
2
3 import (
4 "testing"
5
6 "gotest.tools/v3/assert"
7 )
8
9 func TestHasParent(t *testing.T) {
10 t.Parallel()
11 for _, tt := range []struct {
12 test string
13 name string
14 parent string
15 expected bool
16 }{
17 {
18 test: "valid parent and child",
19 name: "shippers/1/sites/1",
20 parent: "shippers/1",
21 expected: true,
22 },
23
24 {
25 test: "not parent of self",
26 name: "shippers/1/sites/1/settings",
27 parent: "shippers/1/sites/1/settings",
28 expected: false,
29 },
30
31 {
32 test: "empty parent",
33 name: "shippers/1/sites/1",
34 parent: "",
35 expected: false,
36 },
37
38 {
39 test: "empty child and empty parent",
40 name: "",
41 parent: "",
42 expected: false,
43 },
44
45 {
46 test: "singleton child",
47 name: "shippers/1/sites/1/settings",
48 parent: "shippers/1/sites/1",
49 expected: true,
50 },
51
52 {
53 test: "wildcard parent",
54 name: "shippers/1/sites/1",
55 parent: "shippers/-",
56 expected: true,
57 },
58
59 {
60 test: "full child",
61 name: "//freight-example.einride.tech/shippers/1/sites/1",
62 parent: "shippers/-",
63 expected: true,
64 },
65
66 {
67 test: "full parent",
68 name: "shippers/1/sites/1",
69 parent: "//freight-example.einride.tech/shippers/-",
70 expected: true,
71 },
72
73 {
74 test: "full parent",
75 name: "shippers/1/sites/1",
76 parent: "//freight-example.einride.tech/shippers/-",
77 expected: true,
78 },
79
80 {
81 test: "full parent and child with different service names",
82 name: "//other-example.einride.tech/shippers/1/sites/1",
83 parent: "//freight-example.einride.tech/shippers/-",
84 expected: false,
85 },
86
87 {
88 test: "revisioned child",
89 name: "shippers/1/sites/1@beef",
90 parent: "shippers/1/sites/1",
91 expected: true,
92 },
93
94 {
95 test: "revisioned child with other revision",
96 name: "shippers/1/sites/1@beef",
97 parent: "shippers/1/sites/1@dead",
98 expected: false,
99 },
100
101 {
102 test: "identical revisioned child",
103 name: "shippers/1/sites/1@beef",
104 parent: "shippers/1/sites/1@beef",
105 expected: false,
106 },
107
108 {
109 test: "revisioned parent",
110 parent: "datasets/1@beef",
111 name: "datasets/1@beef/tables/1",
112 expected: true,
113 },
114
115 {
116 test: "revisioned parent with non-revisoned child",
117 parent: "datasets/1@beef",
118 name: "datasets/1/tables/1",
119 expected: false,
120 },
121
122 {
123 test: "revisioned parent with non-matching revision child",
124 parent: "datasets/1@beef",
125 name: "datasets/1@dead/tables/1",
126 expected: false,
127 },
128
129 {
130 test: "non-revisioned parent with revisioned child",
131 parent: "datasets/1",
132 name: "datasets/1@beef/tables/1",
133 expected: true,
134 },
135 } {
136 tt := tt
137 t.Run(tt.test, func(t *testing.T) {
138 t.Parallel()
139 assert.Assert(t, HasParent(tt.name, tt.parent) == tt.expected)
140 })
141 }
142 }
143
View as plain text