|
5 | 5 | "fmt"
|
6 | 6 | "math"
|
7 | 7 | "net/url"
|
| 8 | + "os" |
8 | 9 | "regexp"
|
9 | 10 | "testing"
|
10 | 11 | "time"
|
@@ -36,6 +37,61 @@ func cleanupEnv(t *testing.T, client *coder.Client, envID string) func() {
|
36 | 37 | }
|
37 | 38 | }
|
38 | 39 |
|
| 40 | +// this is a stopgap until we have support for a `coder images` subcommand |
| 41 | +// until then, we want can use the *coder.Client to ensure our integration tests |
| 42 | +// work on fresh deployments. |
| 43 | +func ensureImageImported(ctx context.Context, t *testing.T, client *coder.Client, img string) { |
| 44 | + orgs, err := client.Organizations(ctx) |
| 45 | + assert.Success(t, "get orgs", err) |
| 46 | + |
| 47 | + var org *coder.Organization |
| 48 | +search: |
| 49 | + for _, o := range orgs { |
| 50 | + for _, m := range o.Members { |
| 51 | + if m.Email == os.Getenv("CODER_EMAIL") { |
| 52 | + o := o |
| 53 | + org = &o |
| 54 | + break search |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + if org == nil { |
| 59 | + slogtest.Fatal(t, "failed to find org of current user") |
| 60 | + return // help the linter out a bit |
| 61 | + } |
| 62 | + |
| 63 | + registries, err := client.Registries(ctx, org.ID) |
| 64 | + assert.Success(t, "get registries", err) |
| 65 | + |
| 66 | + var dockerhubID string |
| 67 | + for _, r := range registries { |
| 68 | + if r.Registry == "index.docker.io" { |
| 69 | + dockerhubID = r.ID |
| 70 | + } |
| 71 | + } |
| 72 | + assert.True(t, "docker hub registry found", dockerhubID != "") |
| 73 | + |
| 74 | + imgs, err := client.OrganizationImages(ctx, org.ID) |
| 75 | + assert.Success(t, "get org images", err) |
| 76 | + found := false |
| 77 | + for _, i := range imgs { |
| 78 | + if i.Repository == img { |
| 79 | + found = true |
| 80 | + } |
| 81 | + } |
| 82 | + if !found { |
| 83 | + // ignore this error for now as it causes a race with other parallel tests |
| 84 | + _, _ = client.ImportImage(ctx, org.ID, coder.ImportImageReq{ |
| 85 | + RegistryID: &dockerhubID, |
| 86 | + Repository: img, |
| 87 | + Tag: "latest", |
| 88 | + DefaultCPUCores: 2.5, |
| 89 | + DefaultDiskGB: 22, |
| 90 | + DefaultMemoryGB: 3, |
| 91 | + }) |
| 92 | + } |
| 93 | +} |
| 94 | + |
39 | 95 | func TestEnvsCLI(t *testing.T) {
|
40 | 96 | t.Parallel()
|
41 | 97 |
|
@@ -68,6 +124,8 @@ func TestEnvsCLI(t *testing.T) {
|
68 | 124 | tcli.Error(),
|
69 | 125 | )
|
70 | 126 |
|
| 127 | + ensureImageImported(ctx, t, client, "ubuntu") |
| 128 | + |
71 | 129 | name := randString(10)
|
72 | 130 | cpu := 2.3
|
73 | 131 | c.Run(ctx, fmt.Sprintf("coder envs create %s --image ubuntu --cpu %f", name, cpu)).Assert(t,
|
@@ -103,6 +161,8 @@ func TestEnvsCLI(t *testing.T) {
|
103 | 161 | headlessLogin(ctx, t, c)
|
104 | 162 | client := cleanupClient(ctx, t)
|
105 | 163 |
|
| 164 | + ensureImageImported(ctx, t, client, "ubuntu") |
| 165 | + |
106 | 166 | name := randString(10)
|
107 | 167 | c.Run(ctx, fmt.Sprintf("coder envs create %s --image ubuntu --follow", name)).Assert(t,
|
108 | 168 | tcli.Success(),
|
|
0 commit comments