diff --git a/src/docs/apiserver-backend-tasks.md b/src/docs/apiserver-backend-tasks.md index 12a04b3..feeb62b 100644 --- a/src/docs/apiserver-backend-tasks.md +++ b/src/docs/apiserver-backend-tasks.md @@ -76,9 +76,10 @@ - `controllers/rbac_check_test.go` — 3 new TDD tests: `TestRBAC_HostControl_ClusterAdminOnly`, `TestRBAC_HostView_BasicUserHasAccess`, `TestRBAC_HostControl_DomainTypeIsAll` - All tests passing (`controllers` package) -- [ ] **#9 P0-2d: Update stub.go with new function stubs** - - `backend/stub.go` — Keep `ControlHost` stub (return `errNoCGO`), add `StartHeartbeat(ctx context.Context){}`, `SetHeartbeatInterval(secs int){}`, `EvalSelectForHost(...)` returning `errNoCGO`, `Cleanup(){}` - - Add `"context"` to import block +- [x] **#9 P0-2d: Update stub.go with new function stubs** + - `backend/stub.go` — Added `StartHeartbeat(_ context.Context){}`, `SetHeartbeatInterval(_ int){}`, `EvalSelectForHost(_, _ string) error` (returns `errNoCGO`), `Cleanup(){}`, added `"context"` to imports + - `backend/stub_funcs_test.go` — 4 TDD tests: `TestStartHeartbeat_StubNoOp`, `TestSetHeartbeatInterval_StubNoOp` (3 edge values), `TestEvalSelectForHost_StubErrNoCGO`, `TestCleanup_StubNoOp` + - All backend tests passing --- diff --git a/src/frontend/apiserver/backend/stub.go b/src/frontend/apiserver/backend/stub.go index f17cade..1520d76 100644 --- a/src/frontend/apiserver/backend/stub.go +++ b/src/frontend/apiserver/backend/stub.go @@ -4,6 +4,7 @@ package backend import ( "apiserver/models" + "context" "errors" ) @@ -31,3 +32,15 @@ func ControlQueue(queuename string, action int) error { return errNoCGO } // ControlHost stub — real implementation in clib.go (requires CGO). func ControlHost(hostname string, action int) error { return errNoCGO } + +// StartHeartbeat stub — real implementation in clib.go (requires CGO). +func StartHeartbeat(_ context.Context) {} + +// SetHeartbeatInterval stub — real implementation in clib.go (requires CGO). +func SetHeartbeatInterval(_ int) {} + +// EvalSelectForHost stub — real implementation in clib.go (requires CGO). +func EvalSelectForHost(_, _ string) error { return errNoCGO } + +// Cleanup stub — real implementation in clib.go (requires CGO). +func Cleanup() {} diff --git a/src/frontend/apiserver/backend/stub_funcs_test.go b/src/frontend/apiserver/backend/stub_funcs_test.go new file mode 100644 index 0000000..042107a --- /dev/null +++ b/src/frontend/apiserver/backend/stub_funcs_test.go @@ -0,0 +1,41 @@ +//go:build !cgo + +package backend + +import ( + "context" + "testing" +) + +// TestStartHeartbeat_StubNoOp verifies the no-CGO stub for StartHeartbeat +// is a no-op that does not panic or return an error. +func TestStartHeartbeat_StubNoOp(t *testing.T) { + // Should not panic and completes immediately + StartHeartbeat(context.Background()) +} + +// TestSetHeartbeatInterval_StubNoOp verifies the no-CGO stub for +// SetHeartbeatInterval is a no-op that does not panic. +func TestSetHeartbeatInterval_StubNoOp(t *testing.T) { + // Should not panic and completes immediately + SetHeartbeatInterval(30) + SetHeartbeatInterval(0) + SetHeartbeatInterval(-1) +} + +// TestEvalSelectForHost_StubErrNoCGO verifies the no-CGO stub for +// EvalSelectForHost returns errNoCGO, blocking callers from using +// select expressions without the real CGO backend. +func TestEvalSelectForHost_StubErrNoCGO(t *testing.T) { + err := EvalSelectForHost("host01", "mem>4") + if err != errNoCGO { + t.Errorf("EvalSelectForHost stub should return errNoCGO, got %v", err) + } +} + +// TestCleanup_StubNoOp verifies the no-CGO stub for Cleanup +// is a no-op that does not panic (the real CGO version frees C resources). +func TestCleanup_StubNoOp(t *testing.T) { + // Should not panic and completes immediately + Cleanup() +} \ No newline at end of file