carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package console
2
3import (
4 "github.com/carlosframework/platform/internal/hostops"
5 "github.com/carlosframework/platform/internal/release"
6 "testing"
7 "time"
8)
9
10func TestPlan9SQLRecoveryWithoutSQLNeedsNoDatabase(t *testing.T) {
11 raw := release.NewDirStore(t.TempDir())
12 w := claimTestWriter(t, raw)
13 seedClaimAdmission(t, raw, "bab", "demo", hostops.AppAdmission{V: 1, AppID: "app", Revision: 1, Epoch: 1, State: "closed", Op: &hostops.AppOperation{ID: "unused", Kind: hostops.OpAppMutation, AppID: "app", Intent: map[string]string{"action": "settings"}}, Registrations: map[string]hostops.Registration{}, Effects: map[string]hostops.Effect{}})
14 st := openGatedStore(t)
15 if err := st.rawBoot.Close(); err != nil {
16 t.Fatal(err)
17 }
18 s := &Server{store: st, cfg: Config{HostClaimOps: &hostops.Controller{Store: raw, Control: w, Now: time.Now}}}
19 if err := s.sweepOneClaimAdmission(t.Context(), hostops.App{Account: "bab", Name: "demo"}); err != nil {
20 t.Fatalf("unrelated operation stopped by SQL receipt failure: %v", err)
21 }
22 a, err := hostops.ReadAdmission(t.Context(), raw, "bab", "demo", "app")
23 if err != nil {
24 t.Fatal(err)
25 }
26 if a.Value.Op != nil || a.Value.State != "open" {
27 t.Fatal("unissued operation did not recover")
28 }
29}
30
31func TestPlan9SQLRecoveryFailureStillDrainsIndependentRegistration(t *testing.T) {
32 raw := release.NewDirStore(t.TempDir())
33 w := claimTestWriter(t, raw)
34 reg := hostops.Registration{Kind: hostops.RegistrationIngest, Owner: claimTestOwner, AppID: "app", Epoch: 1, Expires: time.Now().Add(-time.Hour)}
35 other := reg
36 other.Kind = "create"
37 other.Host = "unused.example"
38 other.Claim = hostops.SavedClaim{Absent: true}
39 seedClaimAdmission(t, raw, "bab", "demo", hostops.AppAdmission{V: 1, AppID: "app", Revision: 1, Epoch: 1, State: "open", Registrations: map[string]hostops.Registration{"sql": reg, "non-sql": other}, Effects: map[string]hostops.Effect{"sql": {ID: "sql", OperationID: "sql", AppID: "app", Resource: "app-sql:sql", Action: "sql-ingest", Owner: claimTestOwner, State: "issued", Inputs: map[string]string{"sql_database": "original"}}}})
40 st := openGatedStore(t)
41 if err := st.rawBoot.Close(); err != nil {
42 t.Fatal(err)
43 }
44 s := &Server{store: st, cfg: Config{HostClaimOps: &hostops.Controller{Store: raw, Control: w, Now: time.Now}}}
45 if err := s.sweepOneClaimAdmission(t.Context(), hostops.App{Account: "bab", Name: "demo"}); err == nil {
46 t.Fatal("SQL identity error disappeared")
47 }
48 a, err := hostops.ReadAdmission(t.Context(), raw, "bab", "demo", "app")
49 if err != nil {
50 t.Fatal(err)
51 }
52 if _, ok := a.Value.Registrations["non-sql"]; ok {
53 t.Fatal("unrelated non-SQL registration was not drained")
54 }
55 if a.Value.Effects["sql"].State != "issued" {
56 t.Fatal("SQL failure settled uncertain work")
57 }
58}
59