(t *testing.T)
| 1227 | } |
| 1228 | |
| 1229 | func TestBuildSecrets(t *testing.T) { |
| 1230 | t.Parallel() |
| 1231 | |
| 1232 | buildSecretVal := "foo" |
| 1233 | |
| 1234 | srv := gittest.CreateGitServer(t, gittest.Options{ |
| 1235 | Files: map[string]string{ |
| 1236 | ".devcontainer/devcontainer.json": `{ |
| 1237 | "name": "Test", |
| 1238 | "build": { |
| 1239 | "dockerfile": "Dockerfile" |
| 1240 | }, |
| 1241 | }`, |
| 1242 | ".devcontainer/Dockerfile": "FROM " + testImageAlpine + |
| 1243 | // Test whether build secrets are written to the default location |
| 1244 | "\nRUN --mount=type=secret,id=FOO cat /run/secrets/FOO > /foo_from_file" + |
| 1245 | // Test whether: |
| 1246 | // * build secrets are written to env |
| 1247 | // * build secrets are written to a custom target |
| 1248 | // * build secrets are both written to env and target if both are specified |
| 1249 | "\nRUN --mount=type=secret,id=FOO,env=FOO,target=/etc/foo echo $FOO > /foo_from_env && cat /etc/foo > /foo_from_custom_target" + |
| 1250 | // Test what happens when you specify the same secret twice |
| 1251 | "\nRUN --mount=type=secret,id=FOO,target=/etc/duplicate_foo --mount=type=secret,id=FOO,target=/etc/duplicate_foo cat /etc/duplicate_foo > /duplicate_foo_from_custom_target", |
| 1252 | }, |
| 1253 | }) |
| 1254 | |
| 1255 | ctr, err := runEnvbuilder(t, runOpts{env: []string{ |
| 1256 | envbuilderEnv("GIT_URL", srv.URL), |
| 1257 | envbuilderEnv("GIT_PASSWORD", "supersecret"), |
| 1258 | envbuilderEnv("BUILD_SECRETS", fmt.Sprintf("FOO=%s", buildSecretVal)), |
| 1259 | }}) |
| 1260 | require.NoError(t, err) |
| 1261 | |
| 1262 | output := execContainer(t, ctr, "cat /foo_from_file") |
| 1263 | assert.Equal(t, buildSecretVal, strings.TrimSpace(output)) |
| 1264 | |
| 1265 | output = execContainer(t, ctr, "cat /foo_from_env") |
| 1266 | assert.Equal(t, buildSecretVal, strings.TrimSpace(output)) |
| 1267 | |
| 1268 | output = execContainer(t, ctr, "cat /foo_from_custom_target") |
| 1269 | assert.Equal(t, buildSecretVal, strings.TrimSpace(output)) |
| 1270 | |
| 1271 | output = execContainer(t, ctr, "cat /duplicate_foo_from_custom_target") |
| 1272 | assert.Equal(t, buildSecretVal, strings.TrimSpace(output)) |
| 1273 | } |
| 1274 | |
| 1275 | func TestLifecycleScripts(t *testing.T) { |
| 1276 | t.Parallel() |
nothing calls this directly
no test coverage detected