(t *testing.T)
| 945 | } |
| 946 | |
| 947 | func TestSignalProcess(t *testing.T) { |
| 948 | t.Parallel() |
| 949 | |
| 950 | t.Run("KillRunning", func(t *testing.T) { |
| 951 | t.Parallel() |
| 952 | |
| 953 | handler := newTestAPI(t) |
| 954 | |
| 955 | id := startAndGetID(t, handler, workspacesdk.StartProcessRequest{ |
| 956 | Command: "sleep 300", |
| 957 | Background: true, |
| 958 | }) |
| 959 | |
| 960 | w := postSignal(t, handler, id, workspacesdk.SignalProcessRequest{ |
| 961 | Signal: "kill", |
| 962 | }) |
| 963 | require.Equal(t, http.StatusOK, w.Code) |
| 964 | |
| 965 | // Verify the process exits. |
| 966 | resp := waitForExit(t, handler, id) |
| 967 | require.False(t, resp.Running) |
| 968 | }) |
| 969 | |
| 970 | t.Run("TerminateRunning", func(t *testing.T) { |
| 971 | t.Parallel() |
| 972 | |
| 973 | if runtime.GOOS == "windows" { |
| 974 | t.Skip("SIGTERM is not supported on Windows") |
| 975 | } |
| 976 | |
| 977 | handler := newTestAPI(t) |
| 978 | |
| 979 | id := startAndGetID(t, handler, workspacesdk.StartProcessRequest{ |
| 980 | Command: "sleep 300", |
| 981 | Background: true, |
| 982 | }) |
| 983 | |
| 984 | w := postSignal(t, handler, id, workspacesdk.SignalProcessRequest{ |
| 985 | Signal: "terminate", |
| 986 | }) |
| 987 | require.Equal(t, http.StatusOK, w.Code) |
| 988 | |
| 989 | // Verify the process exits. |
| 990 | resp := waitForExit(t, handler, id) |
| 991 | require.False(t, resp.Running) |
| 992 | }) |
| 993 | |
| 994 | t.Run("NonexistentProcess", func(t *testing.T) { |
| 995 | t.Parallel() |
| 996 | |
| 997 | handler := newTestAPI(t) |
| 998 | w := postSignal(t, handler, "nonexistent-id-12345", workspacesdk.SignalProcessRequest{ |
| 999 | Signal: "kill", |
| 1000 | }) |
| 1001 | require.Equal(t, http.StatusNotFound, w.Code) |
| 1002 | }) |
| 1003 | |
| 1004 | t.Run("AlreadyExitedProcess", func(t *testing.T) { |
nothing calls this directly
no test coverage detected