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

Function TestCreateDynamic

cli/create_test.go:27–328  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestCreateDynamic(t *testing.T) {
28 t.Parallel()
29 owner := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
30 first := coderdtest.CreateFirstUser(t, owner)
31 member, _ := coderdtest.CreateAnotherUser(t, owner, first.OrganizationID)
32
33 // Terraform template with conditional parameters.
34 // The "region" parameter only appears when "enable_region" is true.
35 const conditionalParamTF = `
36 terraform {
37 required_providers {
38 coder = {
39 source = "coder/coder"
40 }
41 }
42 }
43 data "coder_workspace_owner" "me" {}
44 data "coder_parameter" "enable_region" {
45 name = "enable_region"
46 order = 1
47 type = "bool"
48 default = "false"
49 }
50 data "coder_parameter" "region" {
51 name = "region"
52 count = data.coder_parameter.enable_region.value == "true" ? 1 : 0
53 order = 2
54 type = "string"
55 # No default - this makes it required when it appears
56 }
57 `
58
59 // Test conditional parameters: a parameter that only appears when another
60 // parameter has a certain value.
61 t.Run("ConditionalParam", func(t *testing.T) {
62 t.Parallel()
63 ctx := testutil.Context(t, testutil.WaitLong)
64 template, _ := coderdtest.DynamicParameterTemplate(t, owner, first.OrganizationID, coderdtest.DynamicParameterTemplateParams{
65 MainTF: conditionalParamTF,
66 })
67
68 // Test 1: Create without enabling region - region param should not exist
69 args := []string{
70 "create", "ws-no-region",
71 "--template", template.Name,
72 "--parameter", "enable_region=false",
73 "-y",
74 }
75 inv, root := clitest.New(t, args...)
76 clitest.SetupConfig(t, member, root)
77 pty := ptytest.New(t).Attach(inv)
78
79 doneChan := make(chan error)
80 go func() {
81 doneChan <- inv.Run()
82 }()
83
84 pty.ExpectMatchContext(ctx, "has been created")

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
ContextFunction · 0.92
DynamicParameterTemplateFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
RequireReceiveFunction · 0.92
ExpectMatchContextMethod · 0.80
WriteLineMethod · 0.80

Tested by

no test coverage detected