(t *testing.T, sb integration.Sandbox)
| 138 | } |
| 139 | |
| 140 | func 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(` |
| 145 | package docker |
| 146 | |
| 147 | default allow = false |
| 148 | |
| 149 | allow if input.image.repo == "example/allowlist" |
| 150 | |
| 151 | decision := {"allow": allow} |
| 152 | `), 0600), |
| 153 | fstest.CreateDir("scripts", 0700), |
| 154 | fstest.CreateFile("scripts/policy_test.rego", []byte(` |
| 155 | package docker |
| 156 | |
| 157 | test_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 | |
| 187 | func testPolicyTestDockerGitHubBuilder(t *testing.T, sb integration.Sandbox) { |
| 188 | skipNoCompatBuildKit(t, sb, ">= 0.26.0-0", "policy input requires BuildKit v0.26.0+") |
nothing calls this directly
no test coverage detected
searching dependent graphs…