(t *testing.T)
| 31 | ) |
| 32 | |
| 33 | func TestAgent(t *testing.T) { |
| 34 | t.Parallel() |
| 35 | |
| 36 | waitLines := func(t *testing.T, output <-chan string, lines ...string) error { |
| 37 | t.Helper() |
| 38 | |
| 39 | var got []string |
| 40 | outerLoop: |
| 41 | for _, want := range lines { |
| 42 | for { |
| 43 | select { |
| 44 | case line := <-output: |
| 45 | got = append(got, line) |
| 46 | if strings.Contains(line, want) { |
| 47 | continue outerLoop |
| 48 | } |
| 49 | case <-time.After(testutil.WaitShort): |
| 50 | assert.Failf(t, "timed out waiting for line", "want: %q; got: %q", want, got) |
| 51 | return xerrors.Errorf("timed out waiting for line: %q; got: %q", want, got) |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | return nil |
| 56 | } |
| 57 | |
| 58 | for _, tc := range []struct { |
| 59 | name string |
| 60 | iter []func(context.Context, *testing.T, *codersdk.WorkspaceAgent, <-chan string, chan []codersdk.WorkspaceAgentLog) error |
| 61 | logs chan []codersdk.WorkspaceAgentLog |
| 62 | opts cliui.AgentOptions |
| 63 | want []string |
| 64 | wantErr bool |
| 65 | }{ |
| 66 | { |
| 67 | name: "Initial connection", |
| 68 | opts: cliui.AgentOptions{ |
| 69 | FetchInterval: time.Millisecond, |
| 70 | }, |
| 71 | iter: []func(context.Context, *testing.T, *codersdk.WorkspaceAgent, <-chan string, chan []codersdk.WorkspaceAgentLog) error{ |
| 72 | func(_ context.Context, _ *testing.T, agent *codersdk.WorkspaceAgent, _ <-chan string, _ chan []codersdk.WorkspaceAgentLog) error { |
| 73 | agent.Status = codersdk.WorkspaceAgentConnecting |
| 74 | return nil |
| 75 | }, |
| 76 | func(_ context.Context, t *testing.T, agent *codersdk.WorkspaceAgent, output <-chan string, _ chan []codersdk.WorkspaceAgentLog) error { |
| 77 | return waitLines(t, output, "⧗ Waiting for the workspace agent to connect") |
| 78 | }, |
| 79 | func(_ context.Context, _ *testing.T, agent *codersdk.WorkspaceAgent, _ <-chan string, _ chan []codersdk.WorkspaceAgentLog) error { |
| 80 | agent.Status = codersdk.WorkspaceAgentConnected |
| 81 | agent.FirstConnectedAt = ptr.Ref(time.Now()) |
| 82 | return nil |
| 83 | }, |
| 84 | }, |
| 85 | want: []string{ |
| 86 | "⧗ Waiting for the workspace agent to connect", |
| 87 | "✔ Waiting for the workspace agent to connect", |
| 88 | "⧗ Running workspace agent startup scripts (non-blocking)", |
| 89 | "Notice: The startup scripts are still running and your workspace may be incomplete.", |
| 90 | "For more information and troubleshooting, see", |
nothing calls this directly
no test coverage detected