//go:build linux package host import ( "os" "testing" "github.com/carlosframework/platform/internal/activator" "github.com/carlosframework/platform/internal/hostwrite" "github.com/carlosframework/platform/internal/registry" "github.com/carlosframework/platform/internal/release" ) func TestPlan14ERecoveryOrdinaryPass(t *testing.T) { if !plan14RootFixture(t) { return } for _, shape := range []string{"unstamped", "derived", "exec", "named refusal"} { t.Run(shape, func(t *testing.T) { f := r2Fixture(t, "none") f.rt.Unit = "" f.rt.Backing = registry.BackingUnit if shape == "derived" { f.rt.Unit = activator.UnitName(f.rt.Host) } if shape == "exec" { f.rt.Backing = "exec" } if err := f.e.root.reg.Delete(f.rt.Host); err != nil { t.Fatal(err) } if err := f.e.root.reg.Upsert(f.rt); err != nil { t.Fatal(err) } reads := 0 f.c.legacy = func() (bool, error) { reads++ if shape != "named refusal" { t.Fatal("ordinary pass read census") } return false, os.ErrPermission } if shape == "named refusal" { named := f.rt named.Host = "failed.example.com" named.Unit = "failed.service" if err := f.e.root.reg.Upsert(named); err != nil { t.Fatal(err) } } n := productionNamedUnitRecovery(f.e.store, f.pub, f.u.opt, hostwrite.Config{}) if err := f.pass(t, release.WithRootHistory(nil), n.passOption(f.e.root.reg, f.c, func(string) string { return "5s" })); err != nil { t.Fatal(err) } f.wantLive(t, "v2") if shape == "named refusal" && reads != 1 { t.Fatalf("recovery census reads=%d, want one", reads) } }) } }