Builds: design 47 G §297, A-98 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
46 lines
1.6 KiB
Go
46 lines
1.6 KiB
Go
package apply
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/novox/mesh-host/internal/store"
|
|
)
|
|
|
|
// Stop stops a module's timer, then its service, then its container, and leaves every record, and another module's
|
|
// units, as they are (design 47 G A-98).
|
|
func TestStopModuleStopsAModulesUnitsAndContainersAndRemovesNothing(t *testing.T) {
|
|
m := unitsMachine(map[string]*fakeUnit{
|
|
"app.service": {active: "active", enabled: "enabled"},
|
|
"app.timer": {active: "active", enabled: "enabled"},
|
|
"other.service": {active: "active", enabled: "enabled"},
|
|
})
|
|
state := store.State{}
|
|
for _, r := range []store.Applied{
|
|
{ID: "app.run", Type: "service", Target: "app.service"},
|
|
{ID: "app.tick", Type: "service", Target: "app.timer"},
|
|
{ID: "app.c", Type: "container", Target: "app-box"},
|
|
{ID: "other.run", Type: "service", Target: "other.service"},
|
|
{ID: "other.c", Type: "container", Target: "other-box"},
|
|
} {
|
|
state.Record(r)
|
|
}
|
|
got, err := StopModule(context.Background(), archHost(t), state, "app", m.run)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := []string{"app.timer", "app.service", "app-box"}; !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("stopped %v, want %v, the timer first", got, want)
|
|
}
|
|
if m.units["app.service"].active != "inactive" || m.units["app.timer"].active != "inactive" || m.units["other.service"].active != "active" {
|
|
t.Fatalf("units are %+v", m.units)
|
|
}
|
|
if !m.did("docker stop app-box") || m.did("docker stop other-box") || m.did("docker rm") {
|
|
t.Fatalf("the machine was asked %v", m.asked)
|
|
}
|
|
if len(state.Resources) != 5 {
|
|
t.Fatalf("a record was removed: %d left", len(state.Resources))
|
|
}
|
|
}
|