Skip to content

Commit 6d93680

Browse files
sjmiller609claude
andcommitted
Add e2e test for /system/standby endpoints
Spins up the headless image via testcontainers and exercises: - Idempotent disable (two consecutive 204s) - A normal request flows while pinned (middleware coexistence) - Idempotent enable (two consecutive 204s) The unikraft control file does not exist inside the docker test container, so the underlying scale-to-zero write is a no-op. The test validates HTTP wiring and handler/middleware coexistence; the deep pin semantics are covered by unit tests against DebouncedController. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent b66403f commit 6d93680

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

server/e2e/e2e_standby_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package e2e
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"os/exec"
7+
"testing"
8+
"time"
9+
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
// TestStandbyDisableEnable exercises POST /system/standby/{disable,enable}
14+
// against the real built image. The unikraft control file does not exist
15+
// inside the docker test container, so the underlying scale-to-zero write
16+
// is a no-op — this test validates HTTP wiring, idempotency, and that the
17+
// scale-to-zero middleware coexists with the pin handlers.
18+
func TestStandbyDisableEnable(t *testing.T) {
19+
t.Parallel()
20+
21+
if _, err := exec.LookPath("docker"); err != nil {
22+
t.Skipf("docker not available: %v", err)
23+
}
24+
25+
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
26+
defer cancel()
27+
28+
c := NewTestContainer(t, headlessImage)
29+
require.NoError(t, c.Start(ctx, ContainerConfig{}), "failed to start container")
30+
defer c.Stop(ctx)
31+
32+
require.NoError(t, c.WaitReady(ctx), "api not ready")
33+
34+
client, err := c.APIClient()
35+
require.NoError(t, err, "failed to create API client")
36+
37+
// Idempotent disable.
38+
r1, err := client.DisableStandbyWithResponse(ctx)
39+
require.NoError(t, err, "DisableStandby request failed")
40+
require.Equal(t, http.StatusNoContent, r1.StatusCode(), "unexpected status: %s body=%s", r1.Status(), string(r1.Body))
41+
42+
r2, err := client.DisableStandbyWithResponse(ctx)
43+
require.NoError(t, err, "second DisableStandby request failed")
44+
require.Equal(t, http.StatusNoContent, r2.StatusCode(), "unexpected status: %s body=%s", r2.Status(), string(r2.Body))
45+
46+
// Normal request must still flow while pinned (scaletozero middleware
47+
// runs on every request — the pin must not deadlock or break it).
48+
readResp, err := client.ReadClipboardWithResponse(ctx)
49+
require.NoError(t, err, "ReadClipboard request failed while pinned")
50+
require.Equal(t, http.StatusOK, readResp.StatusCode(), "unexpected read status while pinned: %s body=%s", readResp.Status(), string(readResp.Body))
51+
52+
// Idempotent enable.
53+
r3, err := client.EnableStandbyWithResponse(ctx)
54+
require.NoError(t, err, "EnableStandby request failed")
55+
require.Equal(t, http.StatusNoContent, r3.StatusCode(), "unexpected status: %s body=%s", r3.Status(), string(r3.Body))
56+
57+
r4, err := client.EnableStandbyWithResponse(ctx)
58+
require.NoError(t, err, "second EnableStandby request failed")
59+
require.Equal(t, http.StatusNoContent, r4.StatusCode(), "unexpected status: %s body=%s", r4.Status(), string(r4.Body))
60+
}

0 commit comments

Comments
 (0)