@@ -14,14 +14,21 @@ import (
14
14
)
15
15
16
16
func TestParse (t * testing.T ) {
17
+ t .Parallel ()
18
+
19
+ // Create an in-memory provisioner to communicate with.
17
20
client , server := provisionersdk .TransportPipe ()
18
- defer client .Close ()
19
- defer server .Close ()
20
21
ctx , cancelFunc := context .WithCancel (context .Background ())
21
- defer cancelFunc ()
22
+ t .Cleanup (func () {
23
+ _ = client .Close ()
24
+ _ = server .Close ()
25
+ cancelFunc ()
26
+ })
22
27
go func () {
23
- err := Serve (ctx , & provisionersdk.ServeOptions {
24
- Transport : server ,
28
+ err := Serve (ctx , & ServeOptions {
29
+ ServeOptions : & provisionersdk.ServeOptions {
30
+ Transport : server ,
31
+ },
25
32
})
26
33
require .NoError (t , err )
27
34
}()
@@ -32,7 +39,7 @@ func TestParse(t *testing.T) {
32
39
Files map [string ]string
33
40
Response * proto.Parse_Response
34
41
}{{
35
- Name : "basic " ,
42
+ Name : "single-variable " ,
36
43
Files : map [string ]string {
37
44
"main.tf" : `variable "A" {
38
45
description = "Testing!"
@@ -45,7 +52,7 @@ func TestParse(t *testing.T) {
45
52
}},
46
53
},
47
54
}, {
48
- Name : "default-value" ,
55
+ Name : "default-variable- value" ,
49
56
Files : map [string ]string {
50
57
"main.tf" : `variable "A" {
51
58
default = "wow"
@@ -58,7 +65,7 @@ func TestParse(t *testing.T) {
58
65
}},
59
66
},
60
67
}, {
61
- Name : "validation" ,
68
+ Name : "variable- validation" ,
62
69
Files : map [string ]string {
63
70
"main.tf" : `variable "A" {
64
71
validation {
@@ -73,7 +80,11 @@ func TestParse(t *testing.T) {
73
80
}},
74
81
},
75
82
}} {
83
+ tc := tc
76
84
t .Run (tc .Name , func (t * testing.T ) {
85
+ t .Parallel ()
86
+
87
+ // Write all files to the temporary test directory.
77
88
directory := t .TempDir ()
78
89
for path , content := range tc .Files {
79
90
err := os .WriteFile (filepath .Join (directory , path ), []byte (content ), 0644 )
@@ -85,9 +96,9 @@ func TestParse(t *testing.T) {
85
96
})
86
97
require .NoError (t , err )
87
98
99
+ // Ensure the want and got are equivalent!
88
100
want , err := json .Marshal (tc .Response )
89
101
require .NoError (t , err )
90
-
91
102
got , err := json .Marshal (response )
92
103
require .NoError (t , err )
93
104
0 commit comments