MCPcopy Index your code
hub / github.com/coder/coder / TestTemplateVersionByName

Function TestTemplateVersionByName

coderd/templateversions_test.go:1273–1313  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1271}
1272
1273func TestTemplateVersionByName(t *testing.T) {
1274 t.Parallel()
1275
1276 // Single instance shared across all sub-tests. Each sub-test
1277 // creates its own template version and template with unique
1278 // IDs so parallel execution is safe.
1279 client := coderdtest.New(t, nil)
1280 user := coderdtest.CreateFirstUser(t, client)
1281 t.Run("NotFound", func(t *testing.T) {
1282 t.Parallel()
1283 version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
1284 template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
1285
1286 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
1287 defer cancel()
1288
1289 _, err := client.TemplateVersionByName(ctx, template.ID, "nothing")
1290 var apiErr *codersdk.Error
1291 require.ErrorAs(t, err, &apiErr)
1292 require.Equal(t, http.StatusNotFound, apiErr.StatusCode())
1293 })
1294
1295 t.Run("Found", func(t *testing.T) {
1296 t.Parallel()
1297 version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
1298 template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
1299
1300 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
1301 defer cancel()
1302
1303 tv, err := client.TemplateVersionByName(ctx, template.ID, version.Name)
1304 require.NoError(t, err)
1305
1306 if assert.Equal(t, tv.Job.Status, codersdk.ProvisionerJobPending) {
1307 assert.NotNil(t, tv.MatchedProvisioners)
1308 assert.Zero(t, tv.MatchedProvisioners.Available)
1309 assert.Zero(t, tv.MatchedProvisioners.Count)
1310 assert.False(t, tv.MatchedProvisioners.MostRecentlySeen.Valid)
1311 }
1312 })
1313}
1314
1315func TestPatchActiveTemplateVersion(t *testing.T) {
1316 t.Parallel()

Callers

nothing calls this directly

Calls 8

StatusCodeMethod · 0.95
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
TemplateVersionByNameMethod · 0.80
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected