| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "os" |
| 6 | "os/exec" |
| 7 | "path/filepath" |
| 8 | "strings" |
| 9 | "testing" |
| 10 | |
| 11 | "github.com/carlosframework/platform/internal/release" |
| 12 | "github.com/carlosframework/platform/internal/rootstate" |
| 13 | ) |
| 14 | |
| 15 | func TestR2AdoptFoundationFailureExitsOne(t *testing.T) { |
| 16 | if os.Getenv("PLAN14_FIX3_ADOPT_CHILD") == "1" { |
| 17 | runAdoptWithEnsureSystemUnits([]string{"-stage-only", "-registry", os.Getenv("PLAN14_FIX3_REGISTRY")}, nil, func() {}, noCensusAdoptSource(func() (rootstate.Store, error) { return &rollbackMemory{files: map[string][]byte{}}, nil })) |
| 18 | return |
| 19 | } |
| 20 | if os.Geteuid() == 0 { |
| 21 | t.Skip("this fixture runs the local registry as an unprivileged user") |
| 22 | } |
| 23 | dir := t.TempDir() |
| 24 | data := filepath.Join(dir, "data") |
| 25 | if err := os.MkdirAll(filepath.Join(data, "channel-first-seen.json"), 0755); err != nil { |
| 26 | t.Fatal(err) |
| 27 | } |
| 28 | _, pub, err := release.GenerateKey() |
| 29 | if err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | cmd := exec.Command(os.Args[0], "-test.run=^TestR2AdoptFoundationFailureExitsOne$", "-test.v") |
| 33 | cmd.Dir = dir |
| 34 | cmd.Env = isolatedAdoptOrderEnv(t, |
| 35 | "PLAN14_FIX3_ADOPT_CHILD=1", "PLAN14_FIX3_REGISTRY="+filepath.Join(data, "registry.db"), |
| 36 | "CARLOS_DATA_DIR="+data, "CARLOS_OPT_DIR="+filepath.Join(dir, "opt"), |
| 37 | "CARLOS_DEPLOYMENT_BUCKET=", "CARLOS_DEPLOYMENT_DIR="+filepath.Join(dir, "bucket"), |
| 38 | "CARLOS_HOST_CLAIM=", "CARLOS_REGION_HA=", "CARLOS_MOVES_PHASE1=", "CARLOS_SECRETS_KEY=", "CARLOS_RELEASE_PUBKEY="+pub, |
| 39 | ) |
| 40 | out, err := cmd.CombinedOutput() |
| 41 | var status *exec.ExitError |
| 42 | if !errors.As(err, &status) || status.ExitCode() != 1 || !strings.Contains(string(out), "record bake clock:") { |
| 43 | t.Fatalf("foundation failure lost exit status: %v\n%s", err, out) |
| 44 | } |
| 45 | } |
| 46 | |