MCPcopy Index your code
hub / github.com/coder/coder / ignoreNames

Function ignoreNames

coderd/rbac/roles_internal_test.go:174–208  ·  view source on GitHub ↗

ignoreNames sets all names to "ignore" to ensure the values are identical.

(t *testing.T, value ast.Value)

Source from the content-addressed store, hash-verified

172
173// ignoreNames sets all names to "ignore" to ensure the values are identical.
174func ignoreNames(t *testing.T, value ast.Value) {
175 t.Helper()
176
177 // Override the names of the roles
178 ref := ast.Ref{
179 ast.StringTerm("subject"),
180 ast.StringTerm("roles"),
181 }
182 roles, err := value.Find(ref)
183 require.NoError(t, err)
184
185 rolesArray, ok := roles.(*ast.Array)
186 require.True(t, ok, "roles is expected to be an array")
187
188 rolesArray.Foreach(func(term *ast.Term) {
189 obj, _ := term.Value.(ast.Object)
190 // Ignore all names
191 obj.Insert(ast.StringTerm("name"), ast.StringTerm("ignore"))
192 obj.Insert(ast.StringTerm("display_name"), ast.StringTerm("ignore"))
193 })
194
195 // Override the names of the scope role
196 ref = ast.Ref{
197 ast.StringTerm("subject"),
198 ast.StringTerm("scope"),
199 }
200 scope, err := value.Find(ref)
201 require.NoError(t, err)
202
203 scopeObj, ok := scope.(ast.Object)
204 require.True(t, ok, "scope is expected to be an object")
205
206 scopeObj.Insert(ast.StringTerm("name"), ast.StringTerm("ignore"))
207 scopeObj.Insert(ast.StringTerm("display_name"), ast.StringTerm("ignore"))
208}
209
210func TestRoleByName(t *testing.T) {
211 t.Parallel()

Callers 1

TestRegoInputValueFunction · 0.85

Calls 1

HelperMethod · 0.65

Tested by

no test coverage detected