mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
feat(cli): add open app <workspace> <app-slug> command (#17032)
Fixes https://github.com/coder/coder/issues/17009 Adds a CLI command `coder open app <workspace> <app-slug>` that allows opening arbitrary `coder_apps` via the CLI. Users can optionally specify a region for workspace applications.
This commit is contained in:
103
cli/open_test.go
103
cli/open_test.go
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -33,7 +34,7 @@ func TestOpenVSCode(t *testing.T) {
|
||||
})
|
||||
|
||||
_ = agenttest.New(t, client.URL, agentToken)
|
||||
_ = coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
|
||||
_ = coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait()
|
||||
|
||||
insideWorkspaceEnv := map[string]string{
|
||||
"CODER": "true",
|
||||
@ -168,7 +169,7 @@ func TestOpenVSCode_NoAgentDirectory(t *testing.T) {
|
||||
})
|
||||
|
||||
_ = agenttest.New(t, client.URL, agentToken)
|
||||
_ = coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
|
||||
_ = coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait()
|
||||
|
||||
insideWorkspaceEnv := map[string]string{
|
||||
"CODER": "true",
|
||||
@ -283,3 +284,101 @@ func TestOpenVSCode_NoAgentDirectory(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenApp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client, ws, _ := setupWorkspaceForAgent(t, func(agents []*proto.Agent) []*proto.Agent {
|
||||
agents[0].Apps = []*proto.App{
|
||||
{
|
||||
Slug: "app1",
|
||||
Url: "https://example.com/app1",
|
||||
},
|
||||
}
|
||||
return agents
|
||||
})
|
||||
|
||||
inv, root := clitest.New(t, "open", "app", ws.Name, "app1", "--test.open-error")
|
||||
clitest.SetupConfig(t, client, root)
|
||||
pty := ptytest.New(t)
|
||||
inv.Stdin = pty.Input()
|
||||
inv.Stdout = pty.Output()
|
||||
|
||||
w := clitest.StartWithWaiter(t, inv)
|
||||
w.RequireError()
|
||||
w.RequireContains("test.open-error")
|
||||
})
|
||||
|
||||
t.Run("OnlyWorkspaceName", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client, ws, _ := setupWorkspaceForAgent(t)
|
||||
inv, root := clitest.New(t, "open", "app", ws.Name)
|
||||
clitest.SetupConfig(t, client, root)
|
||||
var sb strings.Builder
|
||||
inv.Stdout = &sb
|
||||
inv.Stderr = &sb
|
||||
|
||||
w := clitest.StartWithWaiter(t, inv)
|
||||
w.RequireSuccess()
|
||||
|
||||
require.Contains(t, sb.String(), "Available apps in")
|
||||
})
|
||||
|
||||
t.Run("WorkspaceNotFound", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client, _, _ := setupWorkspaceForAgent(t)
|
||||
inv, root := clitest.New(t, "open", "app", "not-a-workspace", "app1")
|
||||
clitest.SetupConfig(t, client, root)
|
||||
pty := ptytest.New(t)
|
||||
inv.Stdin = pty.Input()
|
||||
inv.Stdout = pty.Output()
|
||||
w := clitest.StartWithWaiter(t, inv)
|
||||
w.RequireError()
|
||||
w.RequireContains("Resource not found or you do not have access to this resource")
|
||||
})
|
||||
|
||||
t.Run("AppNotFound", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client, ws, _ := setupWorkspaceForAgent(t)
|
||||
|
||||
inv, root := clitest.New(t, "open", "app", ws.Name, "app1")
|
||||
clitest.SetupConfig(t, client, root)
|
||||
pty := ptytest.New(t)
|
||||
inv.Stdin = pty.Input()
|
||||
inv.Stdout = pty.Output()
|
||||
|
||||
w := clitest.StartWithWaiter(t, inv)
|
||||
w.RequireError()
|
||||
w.RequireContains("app not found")
|
||||
})
|
||||
|
||||
t.Run("RegionNotFound", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client, ws, _ := setupWorkspaceForAgent(t, func(agents []*proto.Agent) []*proto.Agent {
|
||||
agents[0].Apps = []*proto.App{
|
||||
{
|
||||
Slug: "app1",
|
||||
Url: "https://example.com/app1",
|
||||
},
|
||||
}
|
||||
return agents
|
||||
})
|
||||
|
||||
inv, root := clitest.New(t, "open", "app", ws.Name, "app1", "--region", "bad-region")
|
||||
clitest.SetupConfig(t, client, root)
|
||||
pty := ptytest.New(t)
|
||||
inv.Stdin = pty.Input()
|
||||
inv.Stdout = pty.Output()
|
||||
|
||||
w := clitest.StartWithWaiter(t, inv)
|
||||
w.RequireError()
|
||||
w.RequireContains("region not found")
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user