@@ -88,9 +88,9 @@ func TestValidateFormType(t *testing.T) {
8888 }
8989 }
9090
91- // obvious just assumes the FormType in the check is the expected
91+ // expectSameFormType just assumes the FormType in the check is the expected
9292 // FormType. Using `expectType` these fields can differ
93- obvious := func (opts formTypeCheck ) formTypeTestCase {
93+ expectSameFormType := func (opts formTypeCheck ) formTypeTestCase {
9494 return expectType (opts .formType , opts )
9595 }
9696
@@ -145,77 +145,77 @@ func TestValidateFormType(t *testing.T) {
145145
146146 // ---- New Behavior
147147 // String
148- obvious (formTypeCheck {
148+ expectSameFormType (formTypeCheck {
149149 options : true ,
150150 optionType : provider .OptionTypeString ,
151151 formType : provider .ParameterFormTypeDropdown ,
152152 }),
153- obvious (formTypeCheck {
153+ expectSameFormType (formTypeCheck {
154154 options : true ,
155155 optionType : provider .OptionTypeString ,
156156 formType : provider .ParameterFormTypeRadio ,
157157 }),
158- obvious (formTypeCheck {
158+ expectSameFormType (formTypeCheck {
159159 options : false ,
160160 optionType : provider .OptionTypeString ,
161161 formType : provider .ParameterFormTypeInput ,
162162 }),
163- obvious (formTypeCheck {
163+ expectSameFormType (formTypeCheck {
164164 options : false ,
165165 optionType : provider .OptionTypeString ,
166166 formType : provider .ParameterFormTypeTextArea ,
167167 }),
168168 // Number
169- obvious (formTypeCheck {
169+ expectSameFormType (formTypeCheck {
170170 options : true ,
171171 optionType : provider .OptionTypeNumber ,
172172 formType : provider .ParameterFormTypeDropdown ,
173173 }),
174- obvious (formTypeCheck {
174+ expectSameFormType (formTypeCheck {
175175 options : true ,
176176 optionType : provider .OptionTypeNumber ,
177177 formType : provider .ParameterFormTypeRadio ,
178178 }),
179- obvious (formTypeCheck {
179+ expectSameFormType (formTypeCheck {
180180 options : false ,
181181 optionType : provider .OptionTypeNumber ,
182182 formType : provider .ParameterFormTypeInput ,
183183 }),
184- obvious (formTypeCheck {
184+ expectSameFormType (formTypeCheck {
185185 options : false ,
186186 optionType : provider .OptionTypeNumber ,
187187 formType : provider .ParameterFormTypeSlider ,
188188 }),
189189 // Boolean
190- obvious (formTypeCheck {
190+ expectSameFormType (formTypeCheck {
191191 options : true ,
192192 optionType : provider .OptionTypeBoolean ,
193193 formType : provider .ParameterFormTypeRadio ,
194194 }),
195- obvious (formTypeCheck {
195+ expectSameFormType (formTypeCheck {
196196 options : false ,
197197 optionType : provider .OptionTypeBoolean ,
198198 formType : provider .ParameterFormTypeSwitch ,
199199 }),
200- obvious (formTypeCheck {
200+ expectSameFormType (formTypeCheck {
201201 options : false ,
202202 optionType : provider .OptionTypeBoolean ,
203203 formType : provider .ParameterFormTypeCheckbox ,
204204 }),
205205 // List(string)
206- obvious (formTypeCheck {
206+ expectSameFormType (formTypeCheck {
207207 options : true ,
208208 optionType : provider .OptionTypeListString ,
209209 formType : provider .ParameterFormTypeRadio ,
210210 }),
211- obvious (formTypeCheck {
211+ expectSameFormType (formTypeCheck {
212212 options : true ,
213213 optionType : provider .OptionTypeListString ,
214214 formType : provider .ParameterFormTypeMultiSelect ,
215215 customOptions : []string {"red" , "blue" , "green" },
216216 defValue : `["red", "blue"]` ,
217217 }),
218- obvious (formTypeCheck {
218+ expectSameFormType (formTypeCheck {
219219 options : false ,
220220 optionType : provider .OptionTypeListString ,
221221 formType : provider .ParameterFormTypeTagSelect ,
@@ -282,8 +282,7 @@ func TestValidateFormType(t *testing.T) {
282282 }
283283
284284 for _ , check := range requiredChecks {
285- _ , alreadyChecked := formTypesChecked [check .String ()]
286- if alreadyChecked {
285+ if _ , alreadyChecked := formTypesChecked [check .String ()]; alreadyChecked {
287286 continue
288287 }
289288
@@ -308,15 +307,15 @@ func TestValidateFormType(t *testing.T) {
308307 // This is just helpful log output to give the boilerplate
309308 // to write the manual test.
310309 tcText := fmt .Sprintf (`
311- obvious (%s, ezconfigOpts{
310+ expectSameFormType (%s, ezconfigOpts{
312311 Options: %t,
313312 OptionType: %q,
314313 FormType: %q,
315314 }),
316315 //` , "<expected_form_type>" , check .options , check .optionType , check .formType )
317316
318- probablyPassed := formTypeTest (t , fc )
319- if ! probablyPassed {
317+ logDebugInfo := formTypeTest (t , fc )
318+ if ! logDebugInfo {
320319 t .Logf ("To construct this test case:\n %s" , tcText )
321320 }
322321 })
@@ -325,8 +324,8 @@ func TestValidateFormType(t *testing.T) {
325324 })
326325}
327326
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 ) {
330329 options := cfg .customOptions
331330 if cfg .options && len (cfg .customOptions ) == 0 {
332331 switch cfg .optionType {
@@ -385,21 +384,24 @@ func ezconfig(paramName string, cfg formTypeCheck) (defaultValue string, tf stri
385384func formTypeTest (t * testing.T , c formTypeTestCase ) bool {
386385 t .Helper ()
387386 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
390392
391- def , tf := ezconfig (paramName , c .config )
393+ def , tf := createTF (paramName , c .config )
392394 checkFn := func (state * terraform.State ) error {
393395 require .Len (t , state .Modules , 1 )
394396 require .Len (t , state .Modules [0 ].Resources , 1 )
395397
396398 key := strings .Join ([]string {"data" , "coder_parameter" , paramName }, "." )
397399 param := state .Modules [0 ].Resources [key ]
398400
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" )
403405
404406 return nil
405407 }
@@ -419,8 +421,8 @@ func formTypeTest(t *testing.T, c formTypeTestCase) bool {
419421 },
420422 })
421423
422- if ! probablyPassed {
424+ if ! logDebugInfo {
423425 t .Logf ("Terraform config:\n %s" , tf )
424426 }
425- return probablyPassed
427+ return logDebugInfo
426428}
0 commit comments