Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce68fe2

Browse files
committed
check for types
1 parent 22cd79a commit ce68fe2

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

provisioner/terraform/tfparse/tfparse_test.go

+93
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,99 @@ func Test_WorkspaceTagDefaultsFromFile(t *testing.T) {
446446
expectTags: nil,
447447
expectError: `Function calls not allowed; Functions may not be called here.`,
448448
},
449+
{
450+
name: "supported types",
451+
files: map[string]string{
452+
"main.tf": `
453+
variable "stringvar" {
454+
type = string
455+
default = "a"
456+
}
457+
variable "numvar" {
458+
type = number
459+
default = 1
460+
}
461+
variable "boolvar" {
462+
type = bool
463+
default = true
464+
}
465+
data "coder_parameter" "stringparam" {
466+
name = "stringparam"
467+
type = "string"
468+
default = "a"
469+
}
470+
data "coder_parameter" "numparam" {
471+
name = "numparam"
472+
type = "number"
473+
default = 1
474+
}
475+
data "coder_parameter" "boolparam" {
476+
name = "boolparam"
477+
type = "bool"
478+
default = true
479+
}
480+
data "coder_parameter" "listparam" {
481+
name = "listparam"
482+
type = "list(string)"
483+
default = "[\"a\", \"b\"]"
484+
}
485+
data "coder_workspace_tags" "tags" {
486+
tags = {
487+
"stringvar" = var.stringvar
488+
"numvar" = var.numvar
489+
"boolvar" = var.boolvar
490+
"stringparam" = data.coder_parameter.stringparam.value
491+
"numparam" = data.coder_parameter.numparam.value
492+
"boolparam" = data.coder_parameter.boolparam.value
493+
"listparam" = data.coder_parameter.listparam.value
494+
}
495+
}`,
496+
},
497+
expectTags: map[string]string{
498+
"stringvar": "a",
499+
"numvar": "1",
500+
"boolvar": "true",
501+
"stringparam": "a",
502+
"numparam": "1",
503+
"boolparam": "true",
504+
"listparam": `["a", "b"]`,
505+
},
506+
expectError: ``,
507+
},
508+
{
509+
name: "unsupported list variable",
510+
files: map[string]string{
511+
"main.tf": `
512+
variable "listvar" {
513+
type = list(string)
514+
default = ["a"]
515+
}
516+
data "coder_workspace_tags" "tags" {
517+
tags = {
518+
listvar = var.listvar
519+
}
520+
}`,
521+
},
522+
expectTags: nil,
523+
expectError: `can't convert variable default value to string: unsupported type []interface {}`,
524+
},
525+
{
526+
name: "unsupported map variable",
527+
files: map[string]string{
528+
"main.tf": `
529+
variable "mapvar" {
530+
type = map(string)
531+
default = {"a": "b"}
532+
}
533+
data "coder_workspace_tags" "tags" {
534+
tags = {
535+
mapvar = var.mapvar
536+
}
537+
}`,
538+
},
539+
expectTags: nil,
540+
expectError: `can't convert variable default value to string: unsupported type map[string]interface {}`,
541+
},
449542
} {
450543
tc := tc
451544
t.Run(tc.name+"/tar", func(t *testing.T) {

0 commit comments

Comments
 (0)