58 lines
1.0 KiB
Go
58 lines
1.0 KiB
Go
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)
|
|
}
|
|
}
|