(t *testing.T)
| 29 | ) |
| 30 | |
| 31 | func TestPublishChecks(t *testing.T) { |
| 32 | c := NewParallelCLI(t) |
| 33 | const projectName = "compose-e2e-explicit-profiles" |
| 34 | |
| 35 | t.Run("publish prompt env_file declined", func(t *testing.T) { |
| 36 | cmd := c.NewDockerComposeCmd(t, "-f", "./fixtures/publish/compose-env-file.yml", |
| 37 | "-p", projectName, "publish", "test/test", "--dry-run") |
| 38 | cmd.Stdin = strings.NewReader("n\n") |
| 39 | res := icmd.RunCmd(cmd) |
| 40 | res.Assert(t, icmd.Expected{ExitCode: 130}) |
| 41 | out := res.Combined() |
| 42 | assert.Assert(t, strings.Contains(out, "you are about to publish env-related declarations within your OCI artifact."), out) |
| 43 | assert.Assert(t, strings.Contains(out, `service "serviceA": env_file declared`), out) |
| 44 | assert.Assert(t, strings.Contains(out, "Are you ok to publish these env declarations?"), out) |
| 45 | assert.Assert(t, !strings.Contains(out, "test/test published"), out) |
| 46 | }) |
| 47 | |
| 48 | t.Run("publish prompt suspicious env declined", func(t *testing.T) { |
| 49 | cmd := c.NewDockerComposeCmd(t, "-f", "./fixtures/publish/compose-environment.yml", |
| 50 | "-p", projectName, "publish", "test/test", "--dry-run") |
| 51 | cmd.Stdin = strings.NewReader("n\n") |
| 52 | res := icmd.RunCmd(cmd) |
| 53 | res.Assert(t, icmd.Expected{ExitCode: 130}) |
| 54 | out := res.Combined() |
| 55 | assert.Assert(t, strings.Contains(out, `service "serviceA": literal value for "MYSQL_ROOT_PASSWORD"`), out) |
| 56 | }) |
| 57 | |
| 58 | t.Run("publish success interpolated env", func(t *testing.T) { |
| 59 | res := c.RunDockerComposeCmd(t, "-f", "./fixtures/publish/compose-interpolated-env.yml", |
| 60 | "-p", projectName, "publish", "test/test", "-y", "--dry-run") |
| 61 | assert.Assert(t, strings.Contains(res.Combined(), "test/test publishing"), res.Combined()) |
| 62 | assert.Assert(t, strings.Contains(res.Combined(), "test/test published"), res.Combined()) |
| 63 | }) |
| 64 | |
| 65 | t.Run("publish prompt aggregates env_file and suspicious literals", func(t *testing.T) { |
| 66 | cmd := c.NewDockerComposeCmd(t, "-f", "./fixtures/publish/compose-multi-env-config.yml", |
| 67 | "-p", projectName, "publish", "test/test", "--dry-run") |
| 68 | cmd.Stdin = strings.NewReader("n\n") |
| 69 | res := icmd.RunCmd(cmd) |
| 70 | res.Assert(t, icmd.Expected{ExitCode: 130}) |
| 71 | out := res.Combined() |
| 72 | // Order is non-deterministic between services; assert each line independently. |
| 73 | assert.Assert(t, strings.Contains(out, `service "serviceB": env_file declared`), out) |
| 74 | assert.Assert(t, strings.Contains(out, `service "serviceA": literal value for "DB_PASSWORD"`), out) |
| 75 | assert.Assert(t, strings.Contains(out, `service "serviceB": literal value for "API_KEY"`), out) |
| 76 | assert.Assert(t, strings.Contains(out, "Use --with-env to silence this prompt"), out) |
| 77 | }) |
| 78 | |
| 79 | t.Run("publish success environment", func(t *testing.T) { |
| 80 | res := c.RunDockerComposeCmd(t, "-f", "./fixtures/publish/compose-environment.yml", |
| 81 | "-p", projectName, "publish", "test/test", "--with-env", "-y", "--dry-run") |
| 82 | assert.Assert(t, strings.Contains(res.Combined(), "test/test publishing"), res.Combined()) |
| 83 | assert.Assert(t, strings.Contains(res.Combined(), "test/test published"), res.Combined()) |
| 84 | }) |
| 85 | |
| 86 | t.Run("publish success env_file", func(t *testing.T) { |
| 87 | res := c.RunDockerComposeCmd(t, "-f", "./fixtures/publish/compose-env-file.yml", |
| 88 | "-p", projectName, "publish", "test/test", "--with-env", "-y", "--dry-run") |
nothing calls this directly
no test coverage detected