| 1 | package release |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "testing" |
| 7 | "time" |
| 8 | ) |
| 9 | |
| 10 | // Review Focus 5. |
| 11 | func TestPruneThenReshipGetsAFreshRecord(t *testing.T) { |
| 12 | s := NewDirStore(t.TempDir()) |
| 13 | ctx := context.Background() |
| 14 | priv, pub := testKeys(t) |
| 15 | shipRelease(t, s, "bab", "km", "v1", adoptPlatform, []byte("one")) |
| 16 | if err := Promote(ctx, s, priv, "bab", "km", "canary/x", "v1"); err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | if err := DeleteVersion(ctx, s, "bab", "km", "v1"); err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | if _, err := ReadPromotionRecord(ctx, s, pub, "bab", "km", "v1"); !errors.Is(err, ErrNoPromotionRecord) { |
| 23 | t.Fatalf("the pruned version's record survived: %v", err) |
| 24 | } |
| 25 | shipRelease(t, s, "bab", "km", "v1", adoptPlatform, []byte("one again, other bytes")) |
| 26 | if err := Promote(ctx, s, priv, "bab", "km", "canary/y", "v1"); err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | if _, err := AuthorizedManifest(ctx, s, pub, "bab", "km", "v1"); err != nil { |
| 30 | t.Fatalf("the reshipped, promoted name has no valid record: %v", err) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func TestPurgeRemovesEveryRecord(t *testing.T) { |
| 35 | s := NewDirStore(t.TempDir()) |
| 36 | ctx := context.Background() |
| 37 | priv, pub := testKeys(t) |
| 38 | shipRelease(t, s, "bab", "km", "v1", adoptPlatform, []byte("one")) |
| 39 | if err := Promote(ctx, s, priv, "bab", "km", "canary/x", "v1"); err != nil { |
| 40 | t.Fatal(err) |
| 41 | } |
| 42 | // Make the app purgeable: trash it and backdate the tombstone |
| 43 | if err := TrashApp(ctx, s, "bab", "km", "paul@keymail.dev", time.Now()); err != nil { |
| 44 | t.Fatal(err) |
| 45 | } |
| 46 | if err := PurgeApp(ctx, s, pub, "bab", "km", time.Now().Add(31*24*time.Hour)); err != nil { |
| 47 | t.Fatal(err) |
| 48 | } |
| 49 | keys, _ := s.List(ctx, PromotedPrefix("bab", "km")) |
| 50 | if len(keys) != 0 { |
| 51 | t.Fatalf("records survived the purge: %v", keys) |
| 52 | } |
| 53 | } |
| 54 | |