MCPcopy Create free account
hub / github.com/docker/buildx / testPolicyTestNestedPath

Function testPolicyTestNestedPath

tests/policy_test.go:140–185  ·  view source on GitHub ↗
(t *testing.T, sb integration.Sandbox)

Source from the content-addressed store, hash-verified

138}
139
140func testPolicyTestNestedPath(t *testing.T, sb integration.Sandbox) {
141 skipNoCompatBuildKit(t, sb, ">= 0.26.0-0", "policy input requires BuildKit v0.26.0+")
142 dir := tmpdir(
143 t,
144 fstest.CreateFile("Dockerfile.rego", []byte(`
145package docker
146
147default allow = false
148
149allow if input.image.repo == "example/allowlist"
150
151decision := {"allow": allow}
152`), 0600),
153 fstest.CreateDir("scripts", 0700),
154 fstest.CreateFile("scripts/policy_test.rego", []byte(`
155package docker
156
157test_allowlisted_repo if {
158 result := data.docker.decision with input as {"image": {"repo": "example/allowlist"}}
159 result.allow
160}
161`), 0600),
162 )
163
164 cmd := buildxCmd(sb, withDir(dir), withArgs(
165 "policy",
166 "test",
167 "--filename",
168 "Dockerfile",
169 "scripts/policy_test.rego",
170 ))
171 out, err := cmd.CombinedOutput()
172 require.NoError(t, err, string(out))
173 require.Contains(t, string(out), "test_allowlisted_repo: PASS")
174
175 cmd = buildxCmd(sb, withDir(dir), withArgs(
176 "policy",
177 "test",
178 "--filename",
179 "Dockerfile",
180 "scripts",
181 ))
182 out, err = cmd.CombinedOutput()
183 require.NoError(t, err, string(out))
184 require.Contains(t, string(out), "test_allowlisted_repo: PASS")
185}
186
187func testPolicyTestDockerGitHubBuilder(t *testing.T, sb integration.Sandbox) {
188 skipNoCompatBuildKit(t, sb, ">= 0.26.0-0", "policy input requires BuildKit v0.26.0+")

Callers

nothing calls this directly

Calls 5

skipNoCompatBuildKitFunction · 0.85
tmpdirFunction · 0.85
buildxCmdFunction · 0.85
withDirFunction · 0.85
withArgsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…