(t *testing.T)
| 83 | } |
| 84 | |
| 85 | func TestClaimPrebuild(t *testing.T) { |
| 86 | t.Parallel() |
| 87 | |
| 88 | const ( |
| 89 | desiredInstances = 1 |
| 90 | presetCount = 2 |
| 91 | ) |
| 92 | |
| 93 | unexpectedClaimingError := xerrors.New("unexpected claiming error") |
| 94 | |
| 95 | cases := map[string]struct { |
| 96 | expectPrebuildClaimed bool |
| 97 | markPrebuildsClaimable bool |
| 98 | // if claimingErr is not nil - error will be returned when ClaimPrebuiltWorkspace is called |
| 99 | claimingErr error |
| 100 | }{ |
| 101 | "no eligible prebuilds to claim": { |
| 102 | expectPrebuildClaimed: false, |
| 103 | markPrebuildsClaimable: false, |
| 104 | }, |
| 105 | "claiming an eligible prebuild should succeed": { |
| 106 | expectPrebuildClaimed: true, |
| 107 | markPrebuildsClaimable: true, |
| 108 | }, |
| 109 | "no claimable prebuilt workspaces error is returned": { |
| 110 | expectPrebuildClaimed: false, |
| 111 | markPrebuildsClaimable: true, |
| 112 | claimingErr: agplprebuilds.ErrNoClaimablePrebuiltWorkspaces, |
| 113 | }, |
| 114 | "AGPL does not support prebuilds error is returned": { |
| 115 | expectPrebuildClaimed: false, |
| 116 | markPrebuildsClaimable: true, |
| 117 | claimingErr: agplprebuilds.ErrAGPLDoesNotSupportPrebuiltWorkspaces, |
| 118 | }, |
| 119 | "unexpected claiming error is returned": { |
| 120 | expectPrebuildClaimed: false, |
| 121 | markPrebuildsClaimable: true, |
| 122 | claimingErr: unexpectedClaimingError, |
| 123 | }, |
| 124 | } |
| 125 | |
| 126 | for name, tc := range cases { |
| 127 | // Ensure that prebuilt workspaces can be claimed in non-default organizations: |
| 128 | for _, useDefaultOrg := range []bool{true, false} { |
| 129 | t.Run(name, func(t *testing.T) { |
| 130 | t.Parallel() |
| 131 | |
| 132 | // Setup |
| 133 | clock := quartz.NewMock(t) |
| 134 | clock.Set(dbtime.Now()) |
| 135 | ctx := testutil.Context(t, testutil.WaitSuperLong) |
| 136 | db, pubsub := dbtestutil.NewDB(t) |
| 137 | |
| 138 | spy := newStoreSpy(db, tc.claimingErr) |
| 139 | expectedPrebuildsCount := desiredInstances * presetCount |
| 140 | |
| 141 | logger := testutil.Logger(t) |
| 142 | client, _, api, owner := coderdenttest.NewWithAPI(t, &coderdenttest.Options{ |
nothing calls this directly
no test coverage detected