Skip to content

Commit bff451b

Browse files
committed
Add unit test
1 parent a76937e commit bff451b

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

enterprise/cli/workspaceproxy.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package cli
22

33
import (
44
"fmt"
5+
"strings"
56

7+
"github.com/fatih/color"
68
"golang.org/x/xerrors"
79

810
"github.com/coder/coder/cli/clibase"
@@ -152,7 +154,27 @@ func (r *RootCmd) listProxies() *clibase.Cmd {
152154
formatter = cliui.NewOutputFormatter(
153155
cliui.TableFormat([]codersdk.WorkspaceProxy{}, []string{"name", "url", "status status"}),
154156
cliui.JSONFormat(),
155-
cliui.TextFormat(),
157+
cliui.ChangeFormatterData(cliui.TextFormat(), func(data any) (any, error) {
158+
resp, ok := data.([]codersdk.WorkspaceProxy)
159+
if !ok {
160+
return nil, xerrors.Errorf("unexpected type %T", data)
161+
}
162+
var str strings.Builder
163+
str.WriteString("Workspace Proxies:\n")
164+
sep := ""
165+
for i, proxy := range resp {
166+
str.WriteString(sep)
167+
str.WriteString(fmt.Sprintf("%d: %s %s %s", i, proxy.Name, proxy.URL, proxy.Status.Status))
168+
for _, errMsg := range proxy.Status.Report.Errors {
169+
str.WriteString(color.RedString("\n\tErr: %s", errMsg))
170+
}
171+
for _, warnMsg := range proxy.Status.Report.Errors {
172+
str.WriteString(color.YellowString("\n\tWarn: %s", warnMsg))
173+
}
174+
sep = "\n"
175+
}
176+
return str.String(), nil
177+
}),
156178
)
157179
)
158180

enterprise/cli/workspaceproxy_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ func Test_ProxyCRUD(t *testing.T) {
6565
_, err = uuid.Parse(parts[0])
6666
require.NoError(t, err, "expected token to be a uuid")
6767

68+
// Fetch proxies and check output
69+
inv, conf = newCLI(
70+
t,
71+
"proxy", "ls",
72+
)
73+
74+
pty = ptytest.New(t)
75+
inv.Stdout = pty.Output()
76+
clitest.SetupConfig(t, client, conf)
77+
78+
err = inv.WithContext(ctx).Run()
79+
require.NoError(t, err)
80+
pty.ExpectMatch(expectedName)
81+
82+
// Also check via the api
6883
proxies, err := client.WorkspaceProxies(ctx)
6984
require.NoError(t, err, "failed to get workspace proxies")
7085
require.Len(t, proxies, 1, "expected 1 proxy")

0 commit comments

Comments
 (0)