carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package release
2
3import (
4 "os"
5 "path/filepath"
6 "testing"
7 "time"
8)
9
10func (s *healthyRetryStore) Names() ([]string, error) {
11 entries, err := os.ReadDir(s.dir)
12 if err != nil {
13 return nil, err
14 }
15 var names []string
16 for _, entry := range entries {
17 names = append(names, entry.Name())
18 }
19 return names, nil
20}
21
22func TestPlan14RootHistoryMintInventory(t *testing.T) {
23 for _, state := range []string{"complete", "missing", "unknown-host", "missing-host", "pending", "sync"} {
24 t.Run(state, func(t *testing.T) {
25 h, disk, b := rootHistoryFixture(t)
26 if err := h.writeApp(historyApp{Schema: 1, Account: b.Account, App: b.App, Revision: 1, Complete: true, Hosts: []string{b.Host}}); err != nil {
27 t.Fatal(err)
28 }
29 ref := Refusal{Host: b.Host, App: b.App, Version: "bad", RefusedAt: time.Now(), SHA256: "bad", Recovered: true}
30 if err := h.AddRefusal(b, ref); err != nil {
31 t.Fatal(err)
32 }
33 switch state {
34 case "missing":
35 if err := os.Remove(filepath.Join(disk.dir, historyAppKey(b.Account, b.App))); err != nil {
36 t.Fatal(err)
37 }
38 case "missing-host":
39 if err := os.Remove(filepath.Join(disk.dir, historyKey(b))); err != nil {
40 t.Fatal(err)
41 }
42 case "unknown-host":
43 other := b
44 other.Host = "another.example.com"
45 ref.Host = other.Host
46 if err := h.AddRefusal(other, ref); err != nil {
47 t.Fatal(err)
48 }
49 case "pending":
50 if err := h.Begin(b, HistoryAttempt{ID: "a", Version: "bad", Source: "record", Started: time.Now()}); err != nil {
51 t.Fatal(err)
52 }
53 case "sync":
54 disk.fail = 1
55 }
56 refs, err := h.AppRefusals(b.Account, b.App)
57 if state == "complete" {
58 if err != nil || len(refs) != 1 || refs[0].SHA256 != "bad" {
59 t.Fatalf("inventory = %v, %v", refs, err)
60 }
61 } else if err == nil {
62 t.Fatalf("%s inventory allowed minting: %v", state, refs)
63 }
64 })
65 }
66}
67