@@ -24,149 +24,148 @@ func TestParse(t *testing.T) {
24
24
// error containing this string before a Complete response is returned.
25
25
ErrorContains string
26
26
}{
27
- // {
28
- // Name: "single-variable",
29
- // Files: map[string]string{
30
- // "main.tf": `variable "A" {
31
- // description = "Testing!"
32
- // }`,
33
- // },
34
- // Response: &proto.Parse_Response{
35
- // Type: &proto.Parse_Response_Complete{
36
- // Complete: &proto.Parse_Complete{
37
- // ParameterSchemas: []*proto.ParameterSchema{{
38
- // Name: "A",
39
- // RedisplayValue: true,
40
- // AllowOverrideSource: true,
41
- // Description: "Testing!",
42
- // DefaultDestination: &proto.ParameterDestination{
43
- // Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
44
- // },
45
- // }},
46
- // },
47
- // },
48
- // },
49
- // },
50
- // {
51
- // Name: "default-variable-value",
52
- // Files: map[string]string{
53
- // "main.tf": `variable "A" {
54
- // default = "wow"
55
- // }`,
56
- // },
57
- // Response: &proto.Parse_Response{
58
- // Type: &proto.Parse_Response_Complete{
59
- // Complete: &proto.Parse_Complete{
60
- // ParameterSchemas: []*proto.ParameterSchema{{
61
- // Name: "A",
62
- // RedisplayValue: true,
63
- // AllowOverrideSource: true,
64
- // DefaultSource: &proto.ParameterSource{
65
- // Scheme: proto.ParameterSource_DATA,
66
- // Value: "wow",
67
- // },
68
- // DefaultDestination: &proto.ParameterDestination{
69
- // Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
70
- // },
71
- // }},
72
- // },
73
- // },
74
- // },
75
- // },
76
- // {
77
- // Name: "variable-validation",
78
- // Files: map[string]string{
79
- // "main.tf": `variable "A" {
80
- // validation {
81
- // condition = var.A == "value"
82
- // }
83
- // }`,
84
- // },
85
- // Response: &proto.Parse_Response{
86
- // Type: &proto.Parse_Response_Complete{
87
- // Complete: &proto.Parse_Complete{
88
- // ParameterSchemas: []*proto.ParameterSchema{{
89
- // Name: "A",
90
- // RedisplayValue: true,
91
- // ValidationCondition: `var.A == "value"`,
92
- // ValidationTypeSystem: proto.ParameterSchema_HCL,
93
- // AllowOverrideSource: true,
94
- // DefaultDestination: &proto.ParameterDestination{
95
- // Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
96
- // },
97
- // }},
98
- // },
99
- // },
100
- // },
101
- // },
102
- // {
103
- // Name: "bad-syntax",
104
- // Files: map[string]string{
105
- // "main.tf": "a;sd;ajsd;lajsd;lasjdf;a",
106
- // },
107
- // ErrorContains: `The ";" character is not valid.`,
108
- // },
109
- // {
110
- // Name: "multiple-variables",
111
- // Files: map[string]string{
112
- // "main1.tf": `variable "foo" { }
113
- // variable "bar" { }`,
114
- // "main2.tf": `variable "baz" { }
115
- // variable "quux" { }`,
116
- // },
117
- // Response: &proto.Parse_Response{
118
- // Type: &proto.Parse_Response_Complete{
119
- // Complete: &proto.Parse_Complete{
120
- // ParameterSchemas: []*proto.ParameterSchema{
121
- // {
122
- // Name: "foo",
123
- // RedisplayValue: true,
124
- // AllowOverrideSource: true,
125
- // Description: "",
126
- // DefaultDestination: &proto.ParameterDestination{
127
- // Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
128
- // },
129
- // },
130
- // {
131
- // Name: "bar",
132
- // RedisplayValue: true,
133
- // AllowOverrideSource: true,
134
- // Description: "",
135
- // DefaultDestination: &proto.ParameterDestination{
136
- // Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
137
- // },
138
- // },
139
- // {
140
- // Name: "baz",
141
- // RedisplayValue: true,
142
- // AllowOverrideSource: true,
143
- // Description: "",
144
- // DefaultDestination: &proto.ParameterDestination{
145
- // Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
146
- // },
147
- // },
148
- // {
149
- // Name: "quux",
150
- // RedisplayValue: true,
151
- // AllowOverrideSource: true,
152
- // Description: "",
153
- // DefaultDestination: &proto.ParameterDestination{
154
- // Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
155
- // },
156
- // },
157
- // },
158
- // },
159
- // },
160
- // },
161
- // },
162
27
{
163
- Name : "enable-managed-variables " ,
28
+ Name : "single-variable " ,
164
29
Files : map [string ]string {
165
30
"main.tf" : `variable "A" {
166
31
description = "Testing!"
167
- type = "string"
32
+ }` ,
33
+ },
34
+ Response : & proto.Parse_Response {
35
+ Type : & proto.Parse_Response_Complete {
36
+ Complete : & proto.Parse_Complete {
37
+ ParameterSchemas : []* proto.ParameterSchema {{
38
+ Name : "A" ,
39
+ RedisplayValue : true ,
40
+ AllowOverrideSource : true ,
41
+ Description : "Testing!" ,
42
+ DefaultDestination : & proto.ParameterDestination {
43
+ Scheme : proto .ParameterDestination_PROVISIONER_VARIABLE ,
44
+ },
45
+ }},
46
+ },
47
+ },
48
+ },
49
+ },
50
+ {
51
+ Name : "default-variable-value" ,
52
+ Files : map [string ]string {
53
+ "main.tf" : `variable "A" {
54
+ default = "wow"
55
+ }` ,
56
+ },
57
+ Response : & proto.Parse_Response {
58
+ Type : & proto.Parse_Response_Complete {
59
+ Complete : & proto.Parse_Complete {
60
+ ParameterSchemas : []* proto.ParameterSchema {{
61
+ Name : "A" ,
62
+ RedisplayValue : true ,
63
+ AllowOverrideSource : true ,
64
+ DefaultSource : & proto.ParameterSource {
65
+ Scheme : proto .ParameterSource_DATA ,
66
+ Value : "wow" ,
67
+ },
68
+ DefaultDestination : & proto.ParameterDestination {
69
+ Scheme : proto .ParameterDestination_PROVISIONER_VARIABLE ,
70
+ },
71
+ }},
72
+ },
73
+ },
74
+ },
75
+ },
76
+ {
77
+ Name : "variable-validation" ,
78
+ Files : map [string ]string {
79
+ "main.tf" : `variable "A" {
80
+ validation {
81
+ condition = var.A == "value"
82
+ }
83
+ }` ,
84
+ },
85
+ Response : & proto.Parse_Response {
86
+ Type : & proto.Parse_Response_Complete {
87
+ Complete : & proto.Parse_Complete {
88
+ ParameterSchemas : []* proto.ParameterSchema {{
89
+ Name : "A" ,
90
+ RedisplayValue : true ,
91
+ ValidationCondition : `var.A == "value"` ,
92
+ ValidationTypeSystem : proto .ParameterSchema_HCL ,
93
+ AllowOverrideSource : true ,
94
+ DefaultDestination : & proto.ParameterDestination {
95
+ Scheme : proto .ParameterDestination_PROVISIONER_VARIABLE ,
96
+ },
97
+ }},
98
+ },
99
+ },
100
+ },
101
+ },
102
+ {
103
+ Name : "bad-syntax" ,
104
+ Files : map [string ]string {
105
+ "main.tf" : "a;sd;ajsd;lajsd;lasjdf;a" ,
106
+ },
107
+ ErrorContains : `The ";" character is not valid.` ,
108
+ },
109
+ {
110
+ Name : "multiple-variables" ,
111
+ Files : map [string ]string {
112
+ "main1.tf" : `variable "foo" { }
113
+ variable "bar" { }` ,
114
+ "main2.tf" : `variable "baz" { }
115
+ variable "quux" { }` ,
116
+ },
117
+ Response : & proto.Parse_Response {
118
+ Type : & proto.Parse_Response_Complete {
119
+ Complete : & proto.Parse_Complete {
120
+ ParameterSchemas : []* proto.ParameterSchema {
121
+ {
122
+ Name : "foo" ,
123
+ RedisplayValue : true ,
124
+ AllowOverrideSource : true ,
125
+ Description : "" ,
126
+ DefaultDestination : & proto.ParameterDestination {
127
+ Scheme : proto .ParameterDestination_PROVISIONER_VARIABLE ,
128
+ },
129
+ },
130
+ {
131
+ Name : "bar" ,
132
+ RedisplayValue : true ,
133
+ AllowOverrideSource : true ,
134
+ Description : "" ,
135
+ DefaultDestination : & proto.ParameterDestination {
136
+ Scheme : proto .ParameterDestination_PROVISIONER_VARIABLE ,
137
+ },
138
+ },
139
+ {
140
+ Name : "baz" ,
141
+ RedisplayValue : true ,
142
+ AllowOverrideSource : true ,
143
+ Description : "" ,
144
+ DefaultDestination : & proto.ParameterDestination {
145
+ Scheme : proto .ParameterDestination_PROVISIONER_VARIABLE ,
146
+ },
147
+ },
148
+ {
149
+ Name : "quux" ,
150
+ RedisplayValue : true ,
151
+ AllowOverrideSource : true ,
152
+ Description : "" ,
153
+ DefaultDestination : & proto.ParameterDestination {
154
+ Scheme : proto .ParameterDestination_PROVISIONER_VARIABLE ,
155
+ },
156
+ },
157
+ },
158
+ },
159
+ },
160
+ },
161
+ },
162
+ {
163
+ Name : "enable-managed-variables-with-default-value" ,
164
+ Files : map [string ]string {
165
+ "main.tf" : `variable "A" {
166
+ description = "Testing!"
167
+ type = string
168
168
default = "abc"
169
- required = true
170
169
sensitive = true
171
170
}
172
171
@@ -191,6 +190,35 @@ func TestParse(t *testing.T) {
191
190
},
192
191
},
193
192
},
193
+ {
194
+ Name : "enable-managed-variables-without-default" ,
195
+ Files : map [string ]string {
196
+ "main.tf" : `variable "A" {
197
+ description = "Testing!"
198
+ type = string
199
+ sensitive = true
200
+ }
201
+
202
+ provider "coder" {
203
+ feature_use_managed_variables = true
204
+ }` ,
205
+ },
206
+ Response : & proto.Parse_Response {
207
+ Type : & proto.Parse_Response_Complete {
208
+ Complete : & proto.Parse_Complete {
209
+ TemplateVariables : []* proto.TemplateVariable {
210
+ {
211
+ Name : "A" ,
212
+ Description : "Testing!" ,
213
+ Type : "string" ,
214
+ Required : true ,
215
+ Sensitive : true ,
216
+ },
217
+ },
218
+ },
219
+ },
220
+ },
221
+ },
194
222
}
195
223
196
224
for _ , testCase := range testCases {
0 commit comments