|
| 1 | +package integration |
| 2 | + |
| 3 | +import ( |
| 4 | +"context" |
| 5 | +"testing" |
| 6 | +"time" |
| 7 | + |
| 8 | +"cdr.dev/coder-cli/ci/tcli" |
| 9 | +"cdr.dev/slog/sloggers/slogtest/assert" |
| 10 | +) |
| 11 | + |
| 12 | +funcTestDevURLCLI(t*testing.T) { |
| 13 | +t.Parallel() |
| 14 | +ctx,cancel:=context.WithTimeout(context.Background(),time.Minute*5) |
| 15 | +defercancel() |
| 16 | + |
| 17 | +c,err:=tcli.NewContainerRunner(ctx,&tcli.ContainerConfig{ |
| 18 | +Image:"codercom/enterprise-dev", |
| 19 | +Name:"coder-cli-devurl-tests", |
| 20 | +BindMounts:map[string]string{ |
| 21 | +binpath:"/bin/coder", |
| 22 | +}, |
| 23 | +}) |
| 24 | +assert.Success(t,"new run container",err) |
| 25 | +deferc.Close() |
| 26 | + |
| 27 | +c.Run(ctx,"which coder").Assert(t, |
| 28 | +tcli.Success(), |
| 29 | +tcli.StdoutMatches("/usr/sbin/coder"), |
| 30 | +tcli.StderrEmpty(), |
| 31 | +) |
| 32 | + |
| 33 | +c.Run(ctx,"coder urls ls").Assert(t, |
| 34 | +tcli.Error(), |
| 35 | +) |
| 36 | + |
| 37 | +// The following cannot be enabled nor verified until either the |
| 38 | +// integration testing dogfood target has environments created, or |
| 39 | +// we implement the 'env create' command for coder-cli to create our |
| 40 | +// own here. |
| 41 | + |
| 42 | +// If we were to create an env ourselves ... we could test devurls something like |
| 43 | + |
| 44 | +// // == Login |
| 45 | +// headlessLogin(ctx, t, c) |
| 46 | + |
| 47 | +// // == urls ls should fail w/o supplying an envname |
| 48 | +// c.Run(ctx, "coder urls ls").Assert(t, |
| 49 | +// tcli.Error(), |
| 50 | +// ) |
| 51 | + |
| 52 | +// // == env creation should succeed |
| 53 | +// c.Run(ctx, "coder envs create env1 --from image1 --cores 1 --ram 2gb --disk 10gb --nogpu").Assert(t, |
| 54 | +// tcli.Success()) |
| 55 | + |
| 56 | +// // == urls ls should succeed for a newly-created environment |
| 57 | +// var durl entclient.DevURL |
| 58 | +// c.Run(ctx, `coder urls ls -o json`).Assert(t, |
| 59 | +// tcli.Success(), |
| 60 | +// jsonUnmarshals(&durl), // though if a new env, durl should be empty |
| 61 | +// ) |
| 62 | + |
| 63 | +// // == devurl creation w/default PRIVATE access |
| 64 | +// c.Run(ctx, `coder urls create env1 3000`).Assert(t, |
| 65 | +// tcli.Success()) |
| 66 | + |
| 67 | +// // == devurl create w/access == AUTHED |
| 68 | +// c.Run(ctx, `coder urls create env1 3001 --access=AUTHED`).Assert(t, |
| 69 | +// tcli.Success()) |
| 70 | + |
| 71 | +// // == devurl create with name |
| 72 | +// c.Run(ctx, `coder urls create env1 3002 --access=PUBLIC --name=foobar`).Assert(t, |
| 73 | +// tcli.Success()) |
| 74 | + |
| 75 | +// // == devurl ls should return well-formed entries incl. one with AUTHED access |
| 76 | +// c.Run(ctx, `coder urls ls env1 -o json | jq -c '.[] | select( .access == "AUTHED")'`).Assert(t, |
| 77 | +// tcli.Success(), |
| 78 | +// jsonUnmarshals(&durl)) |
| 79 | + |
| 80 | +// // == devurl ls should return well-formed entries incl. one with name 'foobar' |
| 81 | +// c.Run(ctx, `coder urls ls env1 -o json | jq -c '.[] | select( .name == "foobar")'`).Assert(t, |
| 82 | +// tcli.Success(), |
| 83 | +// jsonUnmarshals(&durl)) |
| 84 | + |
| 85 | +// // == devurl rm should function |
| 86 | +// c.Run(ctx, `coder urls rm env1 3002`).Assert(t, |
| 87 | +// tcli.Success()) |
| 88 | + |
| 89 | +// // == removed devurl should no longer be there |
| 90 | +// c.Run(ctx, `coder urls ls env1 -o json | jq -c '.[] | select( .name == "foobar")'`).Assert(t, |
| 91 | +// tcli.Error(), |
| 92 | +// jsonUnmarshals(&durl)) |
| 93 | + |
| 94 | +} |