package backup import ( "bytes" "os" "path/filepath" "testing" "gitea.dooplex.hu/admin/felhom-controller/internal/stacks" ) // R-1057 (v0.314.0): the unit's app.yaml carries the setup gate as it stood at the backup, in the keys the restore // reads (stacks.ReadGateAtBackup); an app with no gate gets byte-identical bytes to before (the checksum-skip guard). // COMPANION RED-PROOF: drop `SetupGate: info.SetupGate` from buildUnitAppYaml → the read-back says „not known". func TestR1057_TheUnitCarriesTheGateAndTheRestoreReadsIt(t *testing.T) { base := RecoveryInfo{NonSecretEnv: map[string]string{"DOMAIN": "example.hu"}} plain := buildUnitAppYaml(base) if bytes.Contains(plain, []byte("setup_gate")) { t.Fatalf("an app with no gate must not carry a gate record:\n%s", plain) } withNil := base withNil.SetupGate = nil if !bytes.Equal(plain, buildUnitAppYaml(withNil)) { t.Fatal("an ungated app's unit bytes changed") } closed := base closed.SetupGate = &GateState{State: stacks.SetupGateClosed} p := filepath.Join(t.TempDir(), "app.yaml") if err := os.WriteFile(p, buildUnitAppYaml(closed), 0o600); err != nil { t.Fatal(err) } if got := stacks.ReadGateAtBackup(p); !got.Known || !got.Closed { t.Fatalf("the restore must read the closed gate back from the unit, got %+v", got) } }