package release import ( "os" "path/filepath" "testing" "time" ) func (s *healthyRetryStore) Names() ([]string, error) { entries, err := os.ReadDir(s.dir) if err != nil { return nil, err } var names []string for _, entry := range entries { names = append(names, entry.Name()) } return names, nil } func TestPlan14RootHistoryMintInventory(t *testing.T) { for _, state := range []string{"complete", "missing", "unknown-host", "missing-host", "pending", "sync"} { t.Run(state, func(t *testing.T) { h, disk, b := rootHistoryFixture(t) if err := h.writeApp(historyApp{Schema: 1, Account: b.Account, App: b.App, Revision: 1, Complete: true, Hosts: []string{b.Host}}); err != nil { t.Fatal(err) } ref := Refusal{Host: b.Host, App: b.App, Version: "bad", RefusedAt: time.Now(), SHA256: "bad", Recovered: true} if err := h.AddRefusal(b, ref); err != nil { t.Fatal(err) } switch state { case "missing": if err := os.Remove(filepath.Join(disk.dir, historyAppKey(b.Account, b.App))); err != nil { t.Fatal(err) } case "missing-host": if err := os.Remove(filepath.Join(disk.dir, historyKey(b))); err != nil { t.Fatal(err) } case "unknown-host": other := b other.Host = "another.example.com" ref.Host = other.Host if err := h.AddRefusal(other, ref); err != nil { t.Fatal(err) } case "pending": if err := h.Begin(b, HistoryAttempt{ID: "a", Version: "bad", Source: "record", Started: time.Now()}); err != nil { t.Fatal(err) } case "sync": disk.fail = 1 } refs, err := h.AppRefusals(b.Account, b.App) if state == "complete" { if err != nil || len(refs) != 1 || refs[0].SHA256 != "bad" { t.Fatalf("inventory = %v, %v", refs, err) } } else if err == nil { t.Fatalf("%s inventory allowed minting: %v", state, refs) } }) } }