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:
Rongsong Shen 2026-04-17 10:02:11 +00:00
parent f354a5ec78
commit dc029a6d14
3 changed files with 58 additions and 3 deletions

View file

@ -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() {}

View 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()
}