feat: Add fallback troubleshooting URL for coder agents (#5005)

This commit is contained in:
Mathias Fredriksson
2022-11-16 12:53:02 +02:00
committed by GitHub
parent 1f4f0cee2a
commit c1ecc91aab
11 changed files with 163 additions and 54 deletions
+48
View File
@@ -12,6 +12,7 @@ import (
"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/pty/ptytest"
"github.com/coder/coder/testutil"
)
func TestAgent(t *testing.T) {
@@ -49,3 +50,50 @@ func TestAgent(t *testing.T) {
disconnected.Store(true)
<-done
}
func TestAgentTimeoutWithTroubleshootingURL(t *testing.T) {
t.Parallel()
ctx, _ := testutil.Context(t)
wantURL := "https://coder.com/troubleshoot"
var connected, timeout atomic.Bool
cmd := &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
err := cliui.Agent(cmd.Context(), cmd.OutOrStdout(), cliui.AgentOptions{
WorkspaceName: "example",
Fetch: func(ctx context.Context) (codersdk.WorkspaceAgent, error) {
agent := codersdk.WorkspaceAgent{
Status: codersdk.WorkspaceAgentConnecting,
TroubleshootingURL: "https://coder.com/troubleshoot",
}
switch {
case connected.Load():
agent.Status = codersdk.WorkspaceAgentConnected
case timeout.Load():
agent.Status = codersdk.WorkspaceAgentTimeout
}
return agent, nil
},
FetchInterval: time.Millisecond,
WarnInterval: 5 * time.Millisecond,
})
return err
},
}
ptty := ptytest.New(t)
cmd.SetOutput(ptty.Output())
cmd.SetIn(ptty.Input())
done := make(chan struct{})
go func() {
defer close(done)
err := cmd.ExecuteContext(ctx)
assert.NoError(t, err)
}()
ptty.ExpectMatch("Don't panic")
timeout.Store(true)
ptty.ExpectMatch(wantURL)
connected.Store(true)
<-done
}