| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "github.com/carlosframework/platform/internal/hostbox" |
| 7 | "github.com/carlosframework/platform/internal/hostwrite" |
| 8 | "github.com/carlosframework/platform/internal/release" |
| 9 | "testing" |
| 10 | ) |
| 11 | |
| 12 | func TestClaimAssemblyDisabledNeverOpensDependencies(t *testing.T) { |
| 13 | calls := 0 |
| 14 | _, err := claimEntryContext(t.Context(), func(string) string { return "" }, func(context.Context) (release.Store, error) { calls++; return nil, errors.New("opened") }) |
| 15 | if err != nil || calls != 0 { |
| 16 | t.Fatalf("err=%v calls=%d", err, calls) |
| 17 | } |
| 18 | } |
| 19 | func TestClaimAssemblyEnabledOpensStoreBeforeFactory(t *testing.T) { |
| 20 | opened := false |
| 21 | store := release.NewDirStore(t.TempDir()) |
| 22 | ctx, err := claimEntryContext(t.Context(), func(string) string { return "0" }, func(context.Context) (release.Store, error) { opened = true; return store, nil }) |
| 23 | if err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | if !opened || claimStore(ctx) != store { |
| 27 | t.Fatal("missing deployment client") |
| 28 | } |
| 29 | _, err = productionClaimFactory(ctx) |
| 30 | var missing *ClaimDependencyError |
| 31 | if !errors.As(err, &missing) || len(missing.Contracts) == 0 { |
| 32 | t.Fatalf("missing dependency not identified: %v", err) |
| 33 | } |
| 34 | } |
| 35 | func TestClaimAssemblyRefusesIncompleteProviders(t *testing.T) { |
| 36 | if _, err := (ClaimAssembly{}).Build(t.Context()); !errors.Is(err, hostwrite.ErrUnavailable) { |
| 37 | t.Fatal(err) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | func TestClaimWakeCompositionRequiresStopAndInputs(t *testing.T) { |
| 42 | _, err := (&ClaimWakeAssembly{}).Build(t.Context(), hostbox.WorkSource{}, hostbox.Writer{}) |
| 43 | if !errors.Is(err, hostwrite.ErrUnavailable) { |
| 44 | t.Fatal(err) |
| 45 | } |
| 46 | } |
| 47 | |