MCPcopy Create free account
hub / github.com/coder/coder / TestClaimPrebuild

Function TestClaimPrebuild

enterprise/coderd/prebuilds/claim_test.go:85–390  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

83}
84
85func 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{

Callers

nothing calls this directly

Calls 15

SnapshotStateMethod · 0.95
CalculateActionsMethod · 0.95
ReconcilePresetMethod · 0.95
NowFunction · 0.92
ContextFunction · 0.92
NewDBFunction · 0.92
LoggerFunction · 0.92
NewWithAPIFunction · 0.92
OrganizationFunction · 0.92
NewFunction · 0.92
NewStoreReconcilerFunction · 0.92

Tested by

no test coverage detected