feat(modules): add hello toy module as engine smoke test
This commit is contained in:
57
internal/modules/hello/hello_test.go
Normal file
57
internal/modules/hello/hello_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package hello
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/engine"
|
||||
)
|
||||
|
||||
func TestHelloFullLifecycle(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "hello.ok")
|
||||
m := Module{Path: path}
|
||||
ctx := context.Background()
|
||||
|
||||
st, err := m.Detect(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if st.(state).Present {
|
||||
t.Fatal("marker should be absent on fresh tmpdir")
|
||||
}
|
||||
|
||||
plan, err := m.Plan(ctx, st)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if plan.IsEmpty() {
|
||||
t.Fatal("plan should have one action")
|
||||
}
|
||||
|
||||
if err := m.Apply(ctx, plan, engine.NewBufferedReporter()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := m.Verify(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
st2, _ := m.Detect(ctx)
|
||||
if !st2.(state).Present {
|
||||
t.Fatal("marker should be present after apply")
|
||||
}
|
||||
|
||||
plan2, _ := m.Plan(ctx, st2)
|
||||
if !plan2.IsEmpty() {
|
||||
t.Fatal("second plan should be empty (idempotent)")
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(data) != markerContent {
|
||||
t.Fatalf("content = %q", data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user