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

Function TestWorkspaceTemplateParamsChange

enterprise/coderd/workspaces_test.go:3178–3311  ·  view source on GitHub ↗

TestWorkspaceTemplateParamsChange tests a workspace with a parameter that validation changes on apply. The params used in create workspace are invalid according to the static params on import. This is testing that dynamic params defers input validation to terraform. It does not try to do this in co

(t *testing.T)

Source from the content-addressed store, hash-verified

3176// This is testing that dynamic params defers input validation to terraform.
3177// It does not try to do this in coder/coder.
3178func TestWorkspaceTemplateParamsChange(t *testing.T) {
3179 indicatorFile := filepath.ToSlash(filepath.Join(t.TempDir(), "workspace_indicator.txt"))
3180 mainTfTemplate := fmt.Sprintf(`
3181 terraform {
3182 required_providers {
3183 coder = {
3184 source = "coder/coder"
3185 }
3186 }
3187 }
3188 provider "coder" {}
3189 data "coder_workspace" "me" {}
3190 data "coder_workspace_owner" "me" {}
3191
3192 data "coder_parameter" "param_min" {
3193 name = "param_min"
3194 type = "number"
3195 default = 10
3196 }
3197
3198 data "coder_parameter" "param" {
3199 name = "param"
3200 type = "number"
3201 default = 12
3202 validation {
3203 min = data.coder_parameter.param_min.value
3204 }
3205 }
3206
3207 resource "local_file" "workspace_indicator" {
3208 content = "I exist"
3209 filename = "%s"
3210 }
3211 `, indicatorFile)
3212 tfCliConfigPath := downloadProviders(t, mainTfTemplate)
3213 t.Setenv("TF_CLI_CONFIG_FILE", tfCliConfigPath)
3214
3215 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: false})
3216 dv := coderdtest.DeploymentValues(t)
3217
3218 client, owner := coderdenttest.New(t, &coderdenttest.Options{
3219 Options: &coderdtest.Options{
3220 Logger: &logger,
3221 // We intentionally do not run a built-in provisioner daemon here.
3222 IncludeProvisionerDaemon: false,
3223 DeploymentValues: dv,
3224 },
3225 LicenseOptions: &coderdenttest.LicenseOptions{
3226 Features: license.Features{
3227 codersdk.FeatureExternalProvisionerDaemons: 1,
3228 },
3229 },
3230 })
3231 templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin())
3232 member, memberUser := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
3233
3234 _ = coderdenttest.NewExternalProvisionerDaemonTerraform(t, client, owner.OrganizationID, nil)
3235

Callers

nothing calls this directly

Calls 15

DeploymentValuesFunction · 0.92
NewFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleTemplateAdminFunction · 0.92
ContextFunction · 0.92
CreateTarFunction · 0.92
GetRandomNameFunction · 0.92
CreateTemplateFunction · 0.92
RefFunction · 0.92
RandomUsernameFunction · 0.92

Tested by

no test coverage detected