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

Function TestDynamicParameterTemplate

enterprise/coderd/dynamicparameters_test.go:516–623  ·  view source on GitHub ↗

TestDynamicParameterTemplate uses a template with some dynamic elements, and tests the parameters, values, etc are all as expected.

(t *testing.T)

Source from the content-addressed store, hash-verified

514// TestDynamicParameterTemplate uses a template with some dynamic elements, and
515// tests the parameters, values, etc are all as expected.
516func TestDynamicParameterTemplate(t *testing.T) {
517 t.Parallel()
518
519 owner, _, api, first := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
520 Options: &coderdtest.Options{IncludeProvisionerDaemon: true},
521 LicenseOptions: &coderdenttest.LicenseOptions{
522 Features: license.Features{
523 codersdk.FeatureTemplateRBAC: 1,
524 },
525 },
526 })
527
528 orgID := first.OrganizationID
529
530 _, userData := coderdtest.CreateAnotherUser(t, owner, orgID)
531 templateAdmin, templateAdminData := coderdtest.CreateAnotherUser(t, owner, orgID, rbac.ScopedRoleOrgTemplateAdmin(orgID))
532 userAdmin, userAdminData := coderdtest.CreateAnotherUser(t, owner, orgID, rbac.ScopedRoleOrgUserAdmin(orgID))
533 _, auditorData := coderdtest.CreateAnotherUser(t, owner, orgID, rbac.ScopedRoleOrgAuditor(orgID))
534
535 coderdtest.CreateGroup(t, owner, orgID, "developer", auditorData, userData)
536 coderdtest.CreateGroup(t, owner, orgID, "admin", templateAdminData, userAdminData)
537 coderdtest.CreateGroup(t, owner, orgID, "auditor", auditorData, templateAdminData, userAdminData)
538
539 dynamicParametersTerraformSource, err := os.ReadFile("testdata/parameters/dynamic/main.tf")
540 require.NoError(t, err)
541
542 _, version := coderdtest.DynamicParameterTemplate(t, templateAdmin, orgID, coderdtest.DynamicParameterTemplateParams{
543 MainTF: string(dynamicParametersTerraformSource),
544 Plan: nil,
545 ModulesArchive: nil,
546 StaticParams: nil,
547 })
548
549 _ = userAdmin
550
551 ctx := testutil.Context(t, testutil.WaitLong)
552
553 stream, err := templateAdmin.TemplateVersionDynamicParameters(ctx, userData.ID.String(), version.ID)
554 require.NoError(t, err)
555 defer func() {
556 _ = stream.Close(websocket.StatusNormalClosure)
557
558 // Wait until the cache ends up empty. This verifies the cache does not
559 // leak any files.
560 require.Eventually(t, func() bool {
561 return api.AGPL.FileCache.Count() == 0
562 }, testutil.WaitShort, testutil.IntervalFast, "file cache should be empty after the test")
563 }()
564
565 // Initial response
566 preview, pop := coderdtest.SynchronousStream(stream)
567 init := pop()
568 require.Len(t, init.Diagnostics, 0, "no top level diags")
569 coderdtest.AssertParameter(t, "isAdmin", init.Parameters).
570 Exists().Value("false")
571 coderdtest.AssertParameter(t, "adminonly", init.Parameters).
572 NotExists()
573 coderdtest.AssertParameter(t, "groups", init.Parameters).

Callers

nothing calls this directly

Calls 15

NewWithAPIFunction · 0.92
CreateAnotherUserFunction · 0.92
ScopedRoleOrgUserAdminFunction · 0.92
ScopedRoleOrgAuditorFunction · 0.92
CreateGroupFunction · 0.92
DynamicParameterTemplateFunction · 0.92
ContextFunction · 0.92
SynchronousStreamFunction · 0.92
AssertParameterFunction · 0.92
CountMethod · 0.80

Tested by

no test coverage detected