| 66 | } |
| 67 | |
| 68 | func TestStartupLogsWriter_Write(t *testing.T) { |
| 69 | t.Parallel() |
| 70 | |
| 71 | canceledCtx, cancel := context.WithCancel(context.Background()) |
| 72 | cancel() |
| 73 | |
| 74 | tests := []struct { |
| 75 | name string |
| 76 | ctx context.Context |
| 77 | level codersdk.LogLevel |
| 78 | source codersdk.WorkspaceAgentLogSource |
| 79 | writes []string |
| 80 | want []agentsdk.Log |
| 81 | wantErr bool |
| 82 | closeFirst bool |
| 83 | }{ |
| 84 | { |
| 85 | name: "single line", |
| 86 | ctx: context.Background(), |
| 87 | level: codersdk.LogLevelInfo, |
| 88 | writes: []string{"hello world\n"}, |
| 89 | want: []agentsdk.Log{ |
| 90 | { |
| 91 | Level: codersdk.LogLevelInfo, |
| 92 | Output: "hello world", |
| 93 | }, |
| 94 | }, |
| 95 | }, |
| 96 | { |
| 97 | name: "multiple lines", |
| 98 | ctx: context.Background(), |
| 99 | level: codersdk.LogLevelInfo, |
| 100 | writes: []string{"hello world\n", "goodbye world\n"}, |
| 101 | want: []agentsdk.Log{ |
| 102 | { |
| 103 | Level: codersdk.LogLevelInfo, |
| 104 | Output: "hello world", |
| 105 | }, |
| 106 | { |
| 107 | Level: codersdk.LogLevelInfo, |
| 108 | Output: "goodbye world", |
| 109 | }, |
| 110 | }, |
| 111 | }, |
| 112 | { |
| 113 | name: "multiple newlines", |
| 114 | ctx: context.Background(), |
| 115 | level: codersdk.LogLevelInfo, |
| 116 | writes: []string{"\n\n", "hello world\n\n\n", "goodbye world\n"}, |
| 117 | want: []agentsdk.Log{ |
| 118 | { |
| 119 | Level: codersdk.LogLevelInfo, |
| 120 | Output: "", |
| 121 | }, |
| 122 | { |
| 123 | Level: codersdk.LogLevelInfo, |
| 124 | Output: "", |
| 125 | }, |