forked from lei.chen/myxce
feat: P0-2d add no-CGO stubs for heartbeat, select, cleanup
Add four function stubs to backend/stub.go for the !cgo build path: - StartHeartbeat(ctx context.Context) — no-op (heartbeat not available) - SetHeartbeatInterval(secs int) — no-op (interval update not available) - EvalSelectForHost(hostname, selectExpr string) error — returns errNoCGO - Cleanup() — no-op (no C resources to release without CGO) TDD: four tests in stub_funcs_test.go verify stubs behave correctly (no-op functions don't panic, error stubs return errNoCGO). All backend tests passing.
This commit is contained in:
parent
f354a5ec78
commit
dc029a6d14
3 changed files with 58 additions and 3 deletions
|
|
@ -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
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {}
|
||||
|
|
|
|||
41
src/frontend/apiserver/backend/stub_funcs_test.go
Normal file
41
src/frontend/apiserver/backend/stub_funcs_test.go
Normal file
|
|
@ -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()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue