MCPcopy Create free account
hub / github.com/coder/envbuilder / TestPrivateRegistry

Function TestPrivateRegistry

integration/integration_test.go:1404–1489  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1402}
1403
1404func TestPrivateRegistry(t *testing.T) {
1405 t.Parallel()
1406 t.Run("NoAuth", func(t *testing.T) {
1407 t.Parallel()
1408 // Even if something goes wrong with auth,
1409 // the pull will fail as "scratch" is a reserved name.
1410 image := setupPassthroughRegistry(t, "scratch", &setupPassthroughRegistryOptions{
1411 Username: "user",
1412 Password: "test",
1413 })
1414
1415 // Ensures that a Git repository with a Dockerfile is cloned and built.
1416 srv := gittest.CreateGitServer(t, gittest.Options{
1417 Files: map[string]string{
1418 "Dockerfile": "FROM " + image,
1419 },
1420 })
1421 _, err := runEnvbuilder(t, runOpts{env: []string{
1422 envbuilderEnv("GIT_URL", srv.URL),
1423 envbuilderEnv("DOCKERFILE_PATH", "Dockerfile"),
1424 }})
1425 require.ErrorContains(t, err, "Unauthorized")
1426 })
1427 t.Run("Auth", func(t *testing.T) {
1428 t.Parallel()
1429 image := setupPassthroughRegistry(t, "envbuilder-test-alpine:latest", &setupPassthroughRegistryOptions{
1430 Username: "user",
1431 Password: "test",
1432 })
1433
1434 // Ensures that a Git repository with a Dockerfile is cloned and built.
1435 srv := gittest.CreateGitServer(t, gittest.Options{
1436 Files: map[string]string{
1437 "Dockerfile": "FROM " + image,
1438 },
1439 })
1440 config, err := json.Marshal(envbuilder.DockerConfig{
1441 AuthConfigs: map[string]clitypes.AuthConfig{
1442 image: {
1443 Username: "user",
1444 Password: "test",
1445 },
1446 },
1447 })
1448 require.NoError(t, err)
1449
1450 _, err = runEnvbuilder(t, runOpts{env: []string{
1451 envbuilderEnv("GIT_URL", srv.URL),
1452 envbuilderEnv("DOCKERFILE_PATH", "Dockerfile"),
1453 envbuilderEnv("DOCKER_CONFIG_BASE64", base64.StdEncoding.EncodeToString(config)),
1454 }})
1455 require.NoError(t, err)
1456 })
1457 t.Run("InvalidAuth", func(t *testing.T) {
1458 t.Parallel()
1459 // Even if something goes wrong with auth,
1460 // the pull will fail as "scratch" is a reserved name.
1461 image := setupPassthroughRegistry(t, "scratch", &setupPassthroughRegistryOptions{

Callers

nothing calls this directly

Calls 4

CreateGitServerFunction · 0.92
setupPassthroughRegistryFunction · 0.85
runEnvbuilderFunction · 0.85
envbuilderEnvFunction · 0.85

Tested by

no test coverage detected