(t *testing.T)
| 1116 | } |
| 1117 | |
| 1118 | func TestProcessLifecycle(t *testing.T) { |
| 1119 | t.Parallel() |
| 1120 | |
| 1121 | t.Run("StartWaitCheckOutput", func(t *testing.T) { |
| 1122 | t.Parallel() |
| 1123 | |
| 1124 | handler := newTestAPI(t) |
| 1125 | |
| 1126 | id := startAndGetID(t, handler, workspacesdk.StartProcessRequest{ |
| 1127 | Command: "echo lifecycle-test && echo second-line", |
| 1128 | }) |
| 1129 | |
| 1130 | resp := waitForExit(t, handler, id) |
| 1131 | require.False(t, resp.Running) |
| 1132 | require.NotNil(t, resp.ExitCode) |
| 1133 | require.Equal(t, 0, *resp.ExitCode) |
| 1134 | require.Contains(t, resp.Output, "lifecycle-test") |
| 1135 | require.Contains(t, resp.Output, "second-line") |
| 1136 | }) |
| 1137 | |
| 1138 | t.Run("NonZeroExitCode", func(t *testing.T) { |
| 1139 | t.Parallel() |
| 1140 | |
| 1141 | handler := newTestAPI(t) |
| 1142 | |
| 1143 | id := startAndGetID(t, handler, workspacesdk.StartProcessRequest{ |
| 1144 | Command: "exit 42", |
| 1145 | }) |
| 1146 | |
| 1147 | resp := waitForExit(t, handler, id) |
| 1148 | require.False(t, resp.Running) |
| 1149 | require.NotNil(t, resp.ExitCode) |
| 1150 | require.Equal(t, 42, *resp.ExitCode) |
| 1151 | }) |
| 1152 | |
| 1153 | t.Run("StartSignalVerifyExit", func(t *testing.T) { |
| 1154 | t.Parallel() |
| 1155 | |
| 1156 | handler := newTestAPI(t) |
| 1157 | |
| 1158 | // Start a long-running background process. |
| 1159 | id := startAndGetID(t, handler, workspacesdk.StartProcessRequest{ |
| 1160 | Command: "sleep 300", |
| 1161 | Background: true, |
| 1162 | }) |
| 1163 | |
| 1164 | // Verify it's running. |
| 1165 | w := getOutput(t, handler, id) |
| 1166 | require.Equal(t, http.StatusOK, w.Code) |
| 1167 | var running workspacesdk.ProcessOutputResponse |
| 1168 | err := json.NewDecoder(w.Body).Decode(&running) |
| 1169 | require.NoError(t, err) |
| 1170 | require.True(t, running.Running) |
| 1171 | |
| 1172 | // Signal it. |
| 1173 | sw := postSignal(t, handler, id, workspacesdk.SignalProcessRequest{ |
| 1174 | Signal: "kill", |
| 1175 | }) |
nothing calls this directly
no test coverage detected