Debian Codegraph @

common/containers/container_test.go

raw symbols SCIP
1 // Copyright 2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package containersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/
16
17 import (
18 "fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/"
19 "reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/"
20 "testingscip-go gomod github.com/golang/go/src go1.23.0 testing/"
21
22 "github.com/google/cel-go/common/astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/"
23 )
24
25 func TestContainers_ResolveCandidateNamesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/TestContainers_ResolveCandidateNames().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
26 c, err := NewContainerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/NewContainer().(Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Name().("a.b.c.M.N"))
27 if err != nil {
28 t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err)
29 }
30 names := c.ResolveCandidateNamesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#ResolveCandidateNames().("R.s")
31 want := []string{
32 "a.b.c.M.N.R.s",
33 "a.b.c.M.R.s",
34 "a.b.c.R.s",
35 "a.b.R.s",
36 "a.R.s",
37 "R.s",
38 }
39 if !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(names, want) {
40 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %v, wanted %v", names, want)
41 }
42 }
43
44 func TestContainers_ResolveCandidateNames_FullyQualifiedNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/TestContainers_ResolveCandidateNames_FullyQualifiedName().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
45 c, err := NewContainerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/NewContainer().(Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Name().("a.b.c.M.N"))
46 if err != nil {
47 t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err)
48 }
49 // The leading '.' indicates the name is already fully-qualified.
50 names := c.ResolveCandidateNamesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#ResolveCandidateNames().(".R.s")
51 want := []string{"R.s"}
52 if !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(names, want) {
53 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %v, wanted %v", names, want)
54 }
55 }
56
57 func TestContainers_ResolveCandidateNames_EmptyContainerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/TestContainers_ResolveCandidateNames_EmptyContainer().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
58 names := DefaultContainerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/DefaultContainer..ResolveCandidateNamesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#ResolveCandidateNames().("R.s")
59 want := []string{"R.s"}
60 if !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(names, want) {
61 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %v, wanted %v", names, want)
62 }
63 }
64
65 func TestContainers_Aliasscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/TestContainers_Alias().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
66 cont, err := DefaultContainerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/DefaultContainer..Extendscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Extend().(Aliasscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Alias().("my.example.pkg.verbose", "bigex"))
67 if err != nil {
68 t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("Extend() failed: %v", err)
69 }
70 if !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(cont.ResolveCandidateNamesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#ResolveCandidateNames().("bigex.Execute"), []string{"my.example.pkg.verbose.Execute"}) {
71 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ResolveCandidateNames() got %s, wanted %s", cont.ResolveCandidateNamesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#ResolveCandidateNames().("bigex.Execute"), "my.example.pkg.verbose.Execute")
72 }
73 }
74
75 func TestContainers_Abbrevsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/TestContainers_Abbrevs().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
76 abbr, err := DefaultContainerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/DefaultContainer..Extendscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Extend().(Abbrevsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Abbrevs().("my.alias.R"))
77 if err != nil {
78 t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err)
79 }
80 names := abbr.ResolveCandidateNamesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#ResolveCandidateNames().("R")
81 want := []string{
82 "my.alias.R",
83 }
84 if !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(names, want) {
85 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %v, wanted %v", names, want)
86 }
87 c, err := NewContainerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/NewContainer().(Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Name().("a.b.c"), Abbrevsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Abbrevs().("my.alias.R"))
88 if err != nil {
89 t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err)
90 }
91 names = c.ResolveCandidateNamesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#ResolveCandidateNames().("R")
92 want = []string{
93 "my.alias.R",
94 }
95 if !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(names, want) {
96 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %v, wanted %v", names, want)
97 }
98 names = c.ResolveCandidateNamesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#ResolveCandidateNames().("R.S.T")
99 want = []string{
100 "my.alias.R.S.T",
101 }
102 if !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(names, want) {
103 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %v, wanted %v", names, want)
104 }
105 names = c.ResolveCandidateNamesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#ResolveCandidateNames().("S")
106 want = []string{
107 "a.b.c.S",
108 "a.b.S",
109 "a.S",
110 "S",
111 }
112 if !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(names, want) {
113 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %v, wanted %v", names, want)
114 }
115 }
116
117 func TestContainers_Aliasing_Errorsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/TestContainers_Aliasing_Errors().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
118 type aliasDef struct {
119 name string
120 alias string
121 }
122 tests := []struct {
123 container string
124 abbrevs []string
125 aliases []aliasDef
126 err string
127 }{
128 {
129 abbrevs: []string{"my.alias.R", "yer.other.R"},
130 err: "abbreviation collides with existing reference: " +
131 "name=yer.other.R, abbreviation=R, existing=my.alias.R",
132 },
133 {
134 container: "a.b.c.M.N",
135 abbrevs: []string{"my.alias.a", "yer.other.b"},
136 err: "abbreviation collides with container name: name=my.alias.a, " +
137 "abbreviation=a, container=a.b.c.M.N",
138 },
139 {
140 abbrevs: []string{".bad"},
141 err: "invalid qualified name: .bad, wanted name of the form 'qualified.name'",
142 },
143 {
144 abbrevs: []string{"bad.alias."},
145 err: "invalid qualified name: bad.alias., wanted name of the form 'qualified.name'",
146 },
147 {
148 abbrevs: []string{" bad_alias1"},
149 err: "invalid qualified name: bad_alias1, wanted name of the form 'qualified.name'",
150 },
151 {
152 abbrevs: []string{" bad.alias! "},
153 err: "invalid qualified name: bad.alias!, wanted name of the form 'qualified.name'",
154 },
155 {
156 aliases: []aliasDef{{name: "a", alias: "b"}},
157 err: "alias must refer to a valid qualified name: a",
158 },
159 {
160 aliases: []aliasDef{{name: "my.alias", alias: "b.c"}},
161 err: "alias must be non-empty and simple (not qualified): alias=b.c",
162 },
163 {
164 aliases: []aliasDef{{name: ".my.qual.name", alias: "a'"}},
165 err: "qualified name must not begin with a leading '.': .my.qual.name",
166 },
167 }
168 for i, tst := range tests {
169 tc := tst
170 t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("[%d]", i), func(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
171 opts := []ContainerOptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/ContainerOption#{}
172 if tc.container != "" {
173 opts = append(opts, Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Name().(tc.container))
174 }
175 if len(tc.abbrevs) != 0 {
176 opts = append(opts, Abbrevsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Abbrevs().(tc.abbrevs...))
177 }
178 if len(tc.aliases) != 0 {
179 for _, a := range tc.aliases {
180 opts = append(opts, Aliasscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Alias().(a.name, a.alias))
181 }
182 }
183 _, err := NewContainerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/NewContainer().(opts...)
184 if err == nil {
185 t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("NewContainer() succeeded, wanted err %s", tc.err)
186 }
187 if err.Error() != tc.err {
188 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("NewContainer() got error %s, wanted error %s", err.Error(), tc.err)
189 }
190 })
191 }
192 }
193
194 func TestContainers_Extend_Aliasscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/TestContainers_Extend_Alias().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
195 c, err := DefaultContainerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/DefaultContainer..Extendscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Extend().(Aliasscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Alias().("test.alias", "alias"))
196 if err != nil {
197 t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err)
198 }
199 if c.AliasSetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#AliasSet().()["alias"] != "test.alias" {
200 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got alias %v wanted 'test.alias'", c.AliasSetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#AliasSet().())
201 }
202 c, err = c.Extendscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Extend().(Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Name().("with.container"))
203 if err != nil {
204 t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err)
205 }
206 if c.Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Name().() != "with.container" {
207 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got container name %s, wanted 'with.container'", c.Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Name().())
208 }
209 if c.AliasSetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#AliasSet().()["alias"] != "test.alias" {
210 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got alias %v wanted 'test.alias'", c.AliasSetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#AliasSet().())
211 }
212 }
213
214 func TestContainers_Extend_Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/TestContainers_Extend_Name().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
215 c, err := DefaultContainerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/DefaultContainer..Extendscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Extend().(Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Name().(""))
216 if err != nil {
217 t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err)
218 }
219 if c.Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Name().() != "" {
220 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %v, wanted empty name", c.Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Name().())
221 }
222 c, err = DefaultContainerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/DefaultContainer..Extendscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Extend().(Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Name().("hello.container"))
223 if err != nil {
224 t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err)
225 }
226 if c.Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Name().() != "hello.container" {
227 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got container name %s, wanted 'hello.container'", c.Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Name().())
228 }
229 c, err = c.Extendscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Extend().(Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Name().("goodbye.container"))
230 if err != nil {
231 t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err)
232 }
233 if c.Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Name().() != "goodbye.container" {
234 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got container name %s, wanted 'goodbye.container'", c.Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Name().())
235 }
236 c, err = c.Extendscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Extend().(Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Name().(".bad.container"))
237 if err == nil {
238 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %v, wanted error", c.Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/Container#Name().())
239 }
240 }
241
242 func TestContainers_ToQualifiedNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/TestContainers_ToQualifiedName().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
243 fac := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NewExprFactoryscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NewExprFactory().()
244 ident := fac.NewIdentscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ExprFactory#NewIdent.(1, "var")
245 idName, found := ToQualifiedNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/ToQualifiedName().(ident)
246 if !found {
247 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got not found from %v expr, wanted found", ident)
248 }
249 if idName != "var" {
250 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %v, wanted 'var'", idName)
251 }
252 sel := fac.NewSelectscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ExprFactory#NewSelect.(2, ident, "qualifier")
253 qualName, found := ToQualifiedNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/ToQualifiedName().(sel)
254 if !found {
255 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got not found from %v expr, wanted found", sel)
256 }
257 if qualName != "var.qualifier" {
258 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %v, wanted 'var.qualifier'", qualName)
259 }
260
261 pres := fac.NewPresenceTestscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ExprFactory#NewPresenceTest.(2, ident, "qualifier")
262 _, found = ToQualifiedNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/ToQualifiedName().(pres)
263 if found {
264 t.Errorscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Error().("got found, wanted not found for test-only expression")
265 }
266
267 unary := fac.NewCallscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ExprFactory#NewCall.(2, "!_", ident)
268 sel = fac.NewSelectscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ExprFactory#NewSelect.(3, unary, "qualifier")
269 _, found = ToQualifiedNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/containers`/ToQualifiedName().(sel)
270 if found {
271 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got found, wanted not found for %v", sel)
272 }
273 }