|
| 1 | +package integration |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "regexp" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "cdr.dev/coder-cli/ci/tcli" |
| 10 | +) |
| 11 | + |
| 12 | +// From Coder organization images |
| 13 | +const ubuntuImgID = "5f443b16-30652892427b955601330fa5" |
| 14 | + |
| 15 | +func TestEnvsCLI(t *testing.T) { |
| 16 | + t.Parallel() |
| 17 | + |
| 18 | + run(t, "coder-cli-env-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) { |
| 19 | + headlessLogin(ctx, t, c) |
| 20 | + |
| 21 | + // Ensure binary is present. |
| 22 | + c.Run(ctx, "which coder").Assert(t, |
| 23 | + tcli.Success(), |
| 24 | + tcli.StdoutMatches("/usr/sbin/coder"), |
| 25 | + tcli.StderrEmpty(), |
| 26 | + ) |
| 27 | + |
| 28 | + // Minimum args not received. |
| 29 | + c.Run(ctx, "coder envs create").Assert(t, |
| 30 | + tcli.StderrMatches(regexp.QuoteMeta("Error: accepts 1 arg(s), received 0")), |
| 31 | + tcli.Error(), |
| 32 | + ) |
| 33 | + |
| 34 | + // Successfully output help. |
| 35 | + c.Run(ctx, "coder envs create --help").Assert(t, |
| 36 | + tcli.Success(), |
| 37 | + tcli.StdoutMatches(regexp.QuoteMeta("Create a new environment under the active user.")), |
| 38 | + tcli.StderrEmpty(), |
| 39 | + ) |
| 40 | + |
| 41 | + // Successfully create environment. |
| 42 | + c.Run(ctx, "coder envs create --image "+ubuntuImgID+" test-ubuntu").Assert(t, |
| 43 | + tcli.Success(), |
| 44 | + // why does flog.Success write to stderr? |
| 45 | + tcli.StderrMatches(regexp.QuoteMeta("Successfully created environment \"test-ubuntu\"")), |
| 46 | + ) |
| 47 | + |
| 48 | + // Invalid environment name should fail. |
| 49 | + c.Run(ctx, "coder envs create --image "+ubuntuImgID+" this-IS-an-invalid-EnvironmentName").Assert(t, |
| 50 | + tcli.Error(), |
| 51 | + tcli.StderrMatches(regexp.QuoteMeta("HTTP/2.0 400 Bad Request")), |
| 52 | + tcli.StderrMatches(regexp.QuoteMeta("environment name must conform to regex ^[a-z0-9]([a-z0-9-]+)?")), |
| 53 | + ) |
| 54 | + |
| 55 | + // Successfully provision environment with fractional resource amounts |
| 56 | + c.Run(ctx, fmt.Sprintf(`coder envs create -i %s -c 1.2 -m 1.4 non-whole-resource-amounts`, ubuntuImgID)).Assert(t, |
| 57 | + tcli.Success(), |
| 58 | + tcli.StderrMatches(regexp.QuoteMeta("Successfully created environment \"non-whole-resource-amounts\"")), |
| 59 | + ) |
| 60 | + |
| 61 | + // Image does not exist should fail. |
| 62 | + c.Run(ctx, "coder envs create --image does-not-exist env-will-not-be-created").Assert(t, |
| 63 | + tcli.Error(), |
| 64 | + tcli.StderrMatches(regexp.QuoteMeta("does not exist")), |
| 65 | + ) |
| 66 | + }) |
| 67 | +} |
0 commit comments