@@ -88,9 +88,9 @@ func TestValidateFormType(t *testing.T) {
88
88
}
89
89
}
90
90
91
- // obvious just assumes the FormType in the check is the expected
91
+ // expectSameFormType just assumes the FormType in the check is the expected
92
92
// FormType. Using `expectType` these fields can differ
93
- obvious := func (opts formTypeCheck ) formTypeTestCase {
93
+ expectSameFormType := func (opts formTypeCheck ) formTypeTestCase {
94
94
return expectType (opts .formType , opts )
95
95
}
96
96
@@ -145,77 +145,77 @@ func TestValidateFormType(t *testing.T) {
145
145
146
146
// ---- New Behavior
147
147
// String
148
- obvious (formTypeCheck {
148
+ expectSameFormType (formTypeCheck {
149
149
options : true ,
150
150
optionType : provider .OptionTypeString ,
151
151
formType : provider .ParameterFormTypeDropdown ,
152
152
}),
153
- obvious (formTypeCheck {
153
+ expectSameFormType (formTypeCheck {
154
154
options : true ,
155
155
optionType : provider .OptionTypeString ,
156
156
formType : provider .ParameterFormTypeRadio ,
157
157
}),
158
- obvious (formTypeCheck {
158
+ expectSameFormType (formTypeCheck {
159
159
options : false ,
160
160
optionType : provider .OptionTypeString ,
161
161
formType : provider .ParameterFormTypeInput ,
162
162
}),
163
- obvious (formTypeCheck {
163
+ expectSameFormType (formTypeCheck {
164
164
options : false ,
165
165
optionType : provider .OptionTypeString ,
166
166
formType : provider .ParameterFormTypeTextArea ,
167
167
}),
168
168
// Number
169
- obvious (formTypeCheck {
169
+ expectSameFormType (formTypeCheck {
170
170
options : true ,
171
171
optionType : provider .OptionTypeNumber ,
172
172
formType : provider .ParameterFormTypeDropdown ,
173
173
}),
174
- obvious (formTypeCheck {
174
+ expectSameFormType (formTypeCheck {
175
175
options : true ,
176
176
optionType : provider .OptionTypeNumber ,
177
177
formType : provider .ParameterFormTypeRadio ,
178
178
}),
179
- obvious (formTypeCheck {
179
+ expectSameFormType (formTypeCheck {
180
180
options : false ,
181
181
optionType : provider .OptionTypeNumber ,
182
182
formType : provider .ParameterFormTypeInput ,
183
183
}),
184
- obvious (formTypeCheck {
184
+ expectSameFormType (formTypeCheck {
185
185
options : false ,
186
186
optionType : provider .OptionTypeNumber ,
187
187
formType : provider .ParameterFormTypeSlider ,
188
188
}),
189
189
// Boolean
190
- obvious (formTypeCheck {
190
+ expectSameFormType (formTypeCheck {
191
191
options : true ,
192
192
optionType : provider .OptionTypeBoolean ,
193
193
formType : provider .ParameterFormTypeRadio ,
194
194
}),
195
- obvious (formTypeCheck {
195
+ expectSameFormType (formTypeCheck {
196
196
options : false ,
197
197
optionType : provider .OptionTypeBoolean ,
198
198
formType : provider .ParameterFormTypeSwitch ,
199
199
}),
200
- obvious (formTypeCheck {
200
+ expectSameFormType (formTypeCheck {
201
201
options : false ,
202
202
optionType : provider .OptionTypeBoolean ,
203
203
formType : provider .ParameterFormTypeCheckbox ,
204
204
}),
205
205
// List(string)
206
- obvious (formTypeCheck {
206
+ expectSameFormType (formTypeCheck {
207
207
options : true ,
208
208
optionType : provider .OptionTypeListString ,
209
209
formType : provider .ParameterFormTypeRadio ,
210
210
}),
211
- obvious (formTypeCheck {
211
+ expectSameFormType (formTypeCheck {
212
212
options : true ,
213
213
optionType : provider .OptionTypeListString ,
214
214
formType : provider .ParameterFormTypeMultiSelect ,
215
215
customOptions : []string {"red" , "blue" , "green" },
216
216
defValue : `["red", "blue"]` ,
217
217
}),
218
- obvious (formTypeCheck {
218
+ expectSameFormType (formTypeCheck {
219
219
options : false ,
220
220
optionType : provider .OptionTypeListString ,
221
221
formType : provider .ParameterFormTypeTagSelect ,
@@ -282,8 +282,7 @@ func TestValidateFormType(t *testing.T) {
282
282
}
283
283
284
284
for _ , check := range requiredChecks {
285
- _ , alreadyChecked := formTypesChecked [check .String ()]
286
- if alreadyChecked {
285
+ if _ , alreadyChecked := formTypesChecked [check .String ()]; alreadyChecked {
287
286
continue
288
287
}
289
288
@@ -308,15 +307,15 @@ func TestValidateFormType(t *testing.T) {
308
307
// This is just helpful log output to give the boilerplate
309
308
// to write the manual test.
310
309
tcText := fmt .Sprintf (`
311
- obvious (%s, ezconfigOpts{
310
+ expectSameFormType (%s, ezconfigOpts{
312
311
Options: %t,
313
312
OptionType: %q,
314
313
FormType: %q,
315
314
}),
316
315
//` , "<expected_form_type>" , check .options , check .optionType , check .formType )
317
316
318
- probablyPassed := formTypeTest (t , fc )
319
- if ! probablyPassed {
317
+ logDebugInfo := formTypeTest (t , fc )
318
+ if ! logDebugInfo {
320
319
t .Logf ("To construct this test case:\n %s" , tcText )
321
320
}
322
321
})
@@ -325,8 +324,8 @@ func TestValidateFormType(t *testing.T) {
325
324
})
326
325
}
327
326
328
- // ezconfig converts a formTypeCheck into a terraform config string.
329
- func ezconfig (paramName string , cfg formTypeCheck ) (defaultValue string , tf string ) {
327
+ // createTF converts a formTypeCheck into a terraform config string.
328
+ func createTF (paramName string , cfg formTypeCheck ) (defaultValue string , tf string ) {
330
329
options := cfg .customOptions
331
330
if cfg .options && len (cfg .customOptions ) == 0 {
332
331
switch cfg .optionType {
@@ -385,21 +384,24 @@ func ezconfig(paramName string, cfg formTypeCheck) (defaultValue string, tf stri
385
384
func formTypeTest (t * testing.T , c formTypeTestCase ) bool {
386
385
t .Helper ()
387
386
const paramName = "test_param"
388
- // probablyPassed is just a guess used for logging. It's not important.
389
- probablyPassed := true
387
+ // logDebugInfo is just a guess used for logging. It's not important. It cannot
388
+ // determine for sure if the test passed because the terraform test runner is a
389
+ // black box. It does not indicate if the test passed or failed. Since this is
390
+ // just used for logging, this is good enough.
391
+ logDebugInfo := true
390
392
391
- def , tf := ezconfig (paramName , c .config )
393
+ def , tf := createTF (paramName , c .config )
392
394
checkFn := func (state * terraform.State ) error {
393
395
require .Len (t , state .Modules , 1 )
394
396
require .Len (t , state .Modules [0 ].Resources , 1 )
395
397
396
398
key := strings .Join ([]string {"data" , "coder_parameter" , paramName }, "." )
397
399
param := state .Modules [0 ].Resources [key ]
398
400
399
- probablyPassed = probablyPassed && assert .Equal (t , def , param .Primary .Attributes ["default" ], "default value" )
400
- probablyPassed = probablyPassed && assert .Equal (t , string (c .assert .FormType ), param .Primary .Attributes ["form_type" ], "form_type" )
401
- probablyPassed = probablyPassed && assert .Equal (t , string (c .assert .Type ), param .Primary .Attributes ["type" ], "type" )
402
- probablyPassed = probablyPassed && assert .JSONEq (t , string (c .assert .Styling ), param .Primary .Attributes ["styling" ], "styling" )
401
+ logDebugInfo = logDebugInfo && assert .Equal (t , def , param .Primary .Attributes ["default" ], "default value" )
402
+ logDebugInfo = logDebugInfo && assert .Equal (t , string (c .assert .FormType ), param .Primary .Attributes ["form_type" ], "form_type" )
403
+ logDebugInfo = logDebugInfo && assert .Equal (t , string (c .assert .Type ), param .Primary .Attributes ["type" ], "type" )
404
+ logDebugInfo = logDebugInfo && assert .JSONEq (t , string (c .assert .Styling ), param .Primary .Attributes ["styling" ], "styling" )
403
405
404
406
return nil
405
407
}
@@ -419,8 +421,8 @@ func formTypeTest(t *testing.T, c formTypeTestCase) bool {
419
421
},
420
422
})
421
423
422
- if ! probablyPassed {
424
+ if ! logDebugInfo {
423
425
t .Logf ("Terraform config:\n %s" , tf )
424
426
}
425
- return probablyPassed
427
+ return logDebugInfo
426
428
}
0 commit comments