feat: bootstrap supply intelligence baseline
This commit is contained in:
124
internal/control/module_test.go
Normal file
124
internal/control/module_test.go
Normal file
@@ -0,0 +1,124 @@
|
||||
package control
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestModuleGate_IsEnabled(t *testing.T) {
|
||||
g := NewModuleGate(true)
|
||||
if !g.IsEnabled() {
|
||||
t.Fatal("expected enabled")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleGate_IsDisabled(t *testing.T) {
|
||||
g := NewModuleGate(false)
|
||||
if g.IsEnabled() {
|
||||
t.Fatal("expected disabled")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleGate_Close(t *testing.T) {
|
||||
g := NewModuleGate(true)
|
||||
g.Close()
|
||||
if g.State() != ModuleStateClosing {
|
||||
t.Fatalf("expected closing, got: %s", g.State())
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleGate_MarkClosed(t *testing.T) {
|
||||
g := NewModuleGate(true)
|
||||
g.Close()
|
||||
g.MarkClosed()
|
||||
if g.State() != ModuleStateClosed {
|
||||
t.Fatalf("expected closed, got: %s", g.State())
|
||||
}
|
||||
if g.IsEnabled() {
|
||||
t.Fatal("expected not enabled after closed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleGate_RejectIfNotEnabled(t *testing.T) {
|
||||
g := NewModuleGate(true)
|
||||
err := g.RejectIfNotEnabled("test")
|
||||
if err != nil {
|
||||
t.Fatal("expected no error when enabled")
|
||||
}
|
||||
|
||||
g.Close()
|
||||
err = g.RejectIfNotEnabled("test")
|
||||
if err == nil {
|
||||
t.Fatal("expected error when closing")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleController_ShutdownInitiate(t *testing.T) {
|
||||
c := NewModuleController(true)
|
||||
c.ShutdownInitiate()
|
||||
|
||||
if c.probes.State() != ModuleStateClosing {
|
||||
t.Fatalf("probes should be closing, got: %s", c.probes.State())
|
||||
}
|
||||
if c.discovery.State() != ModuleStateClosing {
|
||||
t.Fatalf("discovery should be closing, got: %s", c.discovery.State())
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleController_ShutdownComplete(t *testing.T) {
|
||||
c := NewModuleController(true)
|
||||
c.ShutdownInitiate()
|
||||
c.ShutdownComplete()
|
||||
|
||||
if c.probes.State() != ModuleStateClosed {
|
||||
t.Fatalf("probes should be closed, got: %s", c.probes.State())
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleController_IsInflight(t *testing.T) {
|
||||
c := NewModuleController(true)
|
||||
c.ShutdownInitiate()
|
||||
|
||||
if !c.IsInflight() {
|
||||
t.Fatal("expected in-flight during closing")
|
||||
}
|
||||
|
||||
c.ShutdownComplete()
|
||||
|
||||
if c.IsInflight() {
|
||||
t.Fatal("expected not in-flight after closed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleController_GetModuleState(t *testing.T) {
|
||||
c := NewModuleController(true)
|
||||
|
||||
if c.GetModuleState("probes") != ModuleStateActive {
|
||||
t.Fatalf("expected active, got: %s", c.GetModuleState("probes"))
|
||||
}
|
||||
if c.GetModuleState("unknown") != "" {
|
||||
t.Fatalf("expected empty for unknown module")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleController_Status(t *testing.T) {
|
||||
c := NewModuleController(true)
|
||||
status := c.Status()
|
||||
|
||||
if status.Probes != ModuleStateActive {
|
||||
t.Fatalf("expected active, got: %s", status.Probes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleGate_ClosedAt(t *testing.T) {
|
||||
g := NewModuleGate(true)
|
||||
g.Close()
|
||||
|
||||
if g.State() != ModuleStateClosing {
|
||||
t.Fatal("expected closing state")
|
||||
}
|
||||
|
||||
// closedAt should be set when entering closing state
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
_ = g.closedAt // not nil when closing
|
||||
}
|
||||
Reference in New Issue
Block a user