| 1 | package provision |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/carlosframework/platform/internal/release" |
| 9 | ) |
| 10 | |
| 11 | type retireSpy struct{ calls int } |
| 12 | |
| 13 | func (s *retireSpy) RetireRecord(context.Context, RetireRef) error { |
| 14 | s.calls++ |
| 15 | return errors.New("claim path") |
| 16 | } |
| 17 | func TestRetireRecordFlagOffAndRequiredProvider(t *testing.T) { |
| 18 | ctx := context.Background() |
| 19 | store := release.NewDirStore(t.TempDir()) |
| 20 | spy := &retireSpy{} |
| 21 | for _, family := range []string{"instance", "sidecar"} { |
| 22 | ref := RetireRef{Family: family, Account: "bab", App: "jam", Host: "shop.bab.example.com"} |
| 23 | if family == "sidecar" { |
| 24 | ref.Name = "job" |
| 25 | ref.Host = SidecarHost(ref.Name, ref.App, ref.Account) |
| 26 | } |
| 27 | if err := RetireRecord(ctx, store, ref, RetireOptions{Claims: spy}); err != nil { |
| 28 | t.Fatal(err) |
| 29 | } |
| 30 | if spy.calls != 0 { |
| 31 | t.Fatal("flag off called claims") |
| 32 | } |
| 33 | if err := RetireRecord(ctx, store, ref, RetireOptions{HostClaim: true}); !errors.Is(err, ErrClaimRetirer) { |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | } |
| 37 | ref := RetireRef{Family: "instance", Account: "bab", App: "jam", Host: "shop.bab.example.com"} |
| 38 | if err := RetireRecord(ctx, store, ref, RetireOptions{HostClaim: true, Claims: spy}); err == nil || spy.calls != 1 { |
| 39 | t.Fatal("claim path not required") |
| 40 | } |
| 41 | } |
| 42 | |