@@ -5,50 +5,66 @@ import (
55 "math"
66 "reflect"
77 "testing"
8+ "time"
89
910 "github.com/dcarbone/terraform-plugin-framework-utils/acctest"
1011)
1112
1213func TestConfigValue_Defaults (t * testing.T ) {
1314 type convTest struct {
14- in interface {}
15- out interface {}
15+ name string
16+ in interface {}
17+ out interface {}
1618 }
1719
1820 theTests := []convTest {
1921 {
20- in : nil ,
21- out : "null" ,
22+ name : "nil" ,
23+ in : nil ,
24+ out : "null" ,
2225 },
2326 {
24- in : acctest .ConfigLiteral ("local.whateverthing" ),
25- out : "local.whateverthing" ,
27+ name : "config-literal" ,
28+ in : acctest .ConfigLiteral ("local.whateverthing" ),
29+ out : "local.whateverthing" ,
2630 },
2731 {
28- in : true ,
29- out : "true" ,
32+ name : "bool-true" ,
33+ in : true ,
34+ out : "true" ,
3035 },
3136 {
32- in : false ,
33- out : "false" ,
37+ name : "bool-false" ,
38+ in : false ,
39+ out : "false" ,
3440 },
3541 {
36- in : math .MaxInt16 ,
37- out : fmt .Sprintf ("%d" , math .MaxInt16 ),
42+ name : "int-positive" ,
43+ in : math .MaxInt16 ,
44+ out : fmt .Sprintf ("%d" , math .MaxInt16 ),
3845 },
3946 {
40- in : - 5 ,
41- out : "-5" ,
47+ name : "int-negative" ,
48+ in : - 5 ,
49+ out : "-5" ,
4250 },
4351 {
44- in : 0.5 ,
45- out : fmt .Sprintf ("%f" , 0.5 ),
52+ name : "float-positive" ,
53+ in : 0.5 ,
54+ out : fmt .Sprintf ("%f" , 0.5 ),
4655 },
4756 {
48- in : "single-line" ,
49- out : `"single-line"` ,
57+ name : "float-negative" ,
58+ in : - 0.5 ,
59+ out : fmt .Sprintf ("%f" , - 0.5 ),
5060 },
5161 {
62+ name : "string-literal" ,
63+ in : "single-line" ,
64+ out : `"single-line"` ,
65+ },
66+ {
67+ name : "string-heredoc" ,
5268 in : `multi
5369line` ,
5470 out : `<<EOD
5773EOD` ,
5874 },
5975 {
60- in : []interface {}{"hello" , 5 },
76+ name : "duration-to-string" ,
77+ in : time .Nanosecond ,
78+ out : `"1ns"` ,
79+ },
80+ {
81+ name : "slice-interface" ,
82+ in : []interface {}{"hello" , 5 },
6183 out : `[
6284"hello",
63855
6486]` ,
6587 },
6688 {
67- in : []string {"hello" , "there" },
89+ name : "slice-string" ,
90+ in : []string {"hello" , "there" },
6891 out : `[
6992"hello",
7093"there"
7194]` ,
7295 },
7396 {
74- in : []int {1 , 5 },
97+ name : "slice-int" ,
98+ in : []int {1 , 5 },
7599 out : `[
761001,
771015
78102]` ,
79103 },
80104 {
81- in : []float64 {1 , 5 },
105+ name : "slice-float64" ,
106+ in : []float64 {1 , 5 },
82107 out : `[
83108` + fmt .Sprintf ("%f" , float64 (1 )) + `,
84109` + fmt .Sprintf ("%f" , float64 (5 )) + `
@@ -89,14 +114,16 @@ EOD`,
89114 // todo: use biggerer brain to figure out how to test map -> string verification
90115
91116 for _ , theT := range theTests {
92- out := acctest .ConfigValue (theT .in )
93- if ! reflect .DeepEqual (out , theT .out ) {
94- t .Log ("Output does not match expected" )
95- t .Logf ("Input: %v" , theT .in )
96- t .Logf ("Expected: %v" , theT .out )
97- t .Logf ("Actual: %v" , out )
98- t .Fail ()
99- }
117+ t .Run (theT .name , func (t * testing.T ) {
118+ out := acctest .ConfigValue (theT .in )
119+ if ! reflect .DeepEqual (out , theT .out ) {
120+ t .Log ("Output does not match expected" )
121+ t .Logf ("Input: %v" , theT .in )
122+ t .Logf ("Expected: %v" , theT .out )
123+ t .Logf ("Actual: %v" , out )
124+ t .Fail ()
125+ }
126+ })
100127 }
101128}
102129
0 commit comments