package host import ( "bytes" "os" "path/filepath" "testing" ) // 6b-N2, adopt's half: repairing the system units keeps an enabled control // unit when host.env cannot be parsed. A flag-off one is still restored to // main's bytes (TestClaimBadUnitSettingsStillRepairSystemUnits). func TestPlan9AAdoptKeepsEnabledControlUnitOnHostEnvError(t *testing.T) { for _, env := range plan9aOddHostEnv { t.Run(env, func(t *testing.T) { etc := t.TempDir() plan9aWriteFile(t, filepath.Join(etc, "carlos", "host.env"), []byte(env)) installed := plan9aEnabledControl(t) live := filepath.Join(etc, "systemd", "system", claimControlUnit) plan9aWriteFile(t, live, installed) ctl := func(args ...string) (string, error) { return "", nil } probe := func(args ...string) (string, error) { return "inactive\n", nil } ensureSystemUnits(etc, filepath.Join(t.TempDir(), "lock"), ctl, probe, t.Logf) if got, _ := os.ReadFile(live); !bytes.Equal(got, installed) { t.Fatalf("adopt flipped the enabled control unit:\n%s", got) } for _, name := range systemUnitFiles { if _, err := os.Stat(filepath.Join(etc, "systemd", "system", name)); err != nil { t.Fatal(err) } } }) } }