(t *testing.T)
| 78 | } |
| 79 | |
| 80 | func TestExternalWorkspaces(t *testing.T) { |
| 81 | t.Parallel() |
| 82 | |
| 83 | t.Run("Create", func(t *testing.T) { |
| 84 | t.Parallel() |
| 85 | client, owner := coderdenttest.New(t, &coderdenttest.Options{ |
| 86 | Options: &coderdtest.Options{ |
| 87 | IncludeProvisionerDaemon: true, |
| 88 | }, |
| 89 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 90 | Features: license.Features{ |
| 91 | codersdk.FeatureWorkspaceExternalAgent: 1, |
| 92 | }, |
| 93 | }, |
| 94 | }) |
| 95 | member, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID) |
| 96 | version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, completeWithExternalAgent()) |
| 97 | coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
| 98 | template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID) |
| 99 | |
| 100 | args := []string{ |
| 101 | "external-workspaces", |
| 102 | "create", |
| 103 | "my-external-workspace", |
| 104 | "--template", template.Name, |
| 105 | } |
| 106 | inv, root := newCLI(t, args...) |
| 107 | clitest.SetupConfig(t, member, root) |
| 108 | doneChan := make(chan struct{}) |
| 109 | pty := ptytest.New(t).Attach(inv) |
| 110 | go func() { |
| 111 | defer close(doneChan) |
| 112 | err := inv.Run() |
| 113 | assert.NoError(t, err) |
| 114 | }() |
| 115 | |
| 116 | // Expect the workspace creation confirmation |
| 117 | pty.ExpectMatch("coder_external_agent.main") |
| 118 | pty.ExpectMatch("external-agent (linux, amd64)") |
| 119 | pty.ExpectMatch("Confirm create") |
| 120 | pty.WriteLine("yes") |
| 121 | |
| 122 | // Expect the external agent instructions |
| 123 | pty.ExpectMatch("Please run the following command to attach external agent") |
| 124 | pty.ExpectRegexMatch("curl -fsSL .* | CODER_AGENT_TOKEN=.* sh") |
| 125 | |
| 126 | ctx := testutil.Context(t, testutil.WaitLong) |
| 127 | testutil.TryReceive(ctx, t, doneChan) |
| 128 | |
| 129 | // Verify the workspace was created |
| 130 | ws, err := member.WorkspaceByOwnerAndName(context.Background(), codersdk.Me, "my-external-workspace", codersdk.WorkspaceOptions{}) |
| 131 | require.NoError(t, err) |
| 132 | assert.Equal(t, template.Name, ws.TemplateName) |
| 133 | }) |
| 134 | |
| 135 | t.Run("CreateWithoutTemplate", func(t *testing.T) { |
| 136 | t.Parallel() |
| 137 | client, owner := coderdenttest.New(t, &coderdenttest.Options{ |
nothing calls this directly
no test coverage detected