Download this file
| 1 | package schedule |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/carlosframework/platform/internal/hostwrite" |
| 9 | "github.com/carlosframework/platform/internal/registry" |
| 10 | ) |
| 11 | |
| 12 | type timerDeny struct{} |
| 13 | |
| 14 | func (timerDeny) With(context.Context, hostwrite.Identity, func() error) error { |
| 15 | return hostwrite.ErrUnavailable |
| 16 | } |
| 17 | func TestSelectedTimerRejectsRetiredProducer(t *testing.T) { |
| 18 | // A nil underlying pointer would panic if a denied write reached the registry. |
| 19 | var reg *registry.Registry |
| 20 | store := SelectedTimers{Store: reg, Work: timerDeny{}, Context: context.Background(), Host: "shop.example"} |
| 21 | if err := store.UpsertTimer(registry.Timer{Host: "shop.example"}); !errors.Is(err, hostwrite.ErrUnavailable) { |
| 22 | t.Fatal(err) |
| 23 | } |
| 24 | if err := store.DeleteTimer("shop.example", "one"); !errors.Is(err, hostwrite.ErrUnavailable) { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | if err := store.DeleteTimer("other.example", "one"); !errors.Is(err, errTimerHost) { |
| 28 | t.Fatal(err) |
| 29 | } |
| 30 | } |
| 31 | |