@@ -10,14 +10,15 @@ import (
10
10
11
11
"github.com/hashicorp/hcl/v2"
12
12
"github.com/hashicorp/hcl/v2/hcltest"
13
+ "github.com/zclconf/go-cty/cty"
14
+
13
15
"github.com/hashicorp/terraform/internal/addrs"
14
16
"github.com/hashicorp/terraform/internal/configs"
15
17
"github.com/hashicorp/terraform/internal/configs/configschema"
16
18
"github.com/hashicorp/terraform/internal/lang/marks"
17
19
"github.com/hashicorp/terraform/internal/providers"
18
20
"github.com/hashicorp/terraform/internal/provisioners"
19
21
"github.com/hashicorp/terraform/internal/tfdiags"
20
- "github.com/zclconf/go-cty/cty"
21
22
)
22
23
23
24
func TestNodeValidatableResource_ValidateProvisioner_valid (t * testing.T ) {
@@ -54,7 +55,7 @@ func TestNodeValidatableResource_ValidateProvisioner_valid(t *testing.T) {
54
55
},
55
56
}
56
57
57
- diags := node .validateProvisioner (ctx , pc )
58
+ diags := node .validateProvisioner (ctx , pc , nil )
58
59
if diags .HasErrors () {
59
60
t .Fatalf ("node.Eval failed: %s" , diags .Err ())
60
61
}
@@ -99,7 +100,7 @@ func TestNodeValidatableResource_ValidateProvisioner__warning(t *testing.T) {
99
100
}
100
101
}
101
102
102
- diags := node .validateProvisioner (ctx , pc )
103
+ diags := node .validateProvisioner (ctx , pc , nil )
103
104
if len (diags ) != 1 {
104
105
t .Fatalf ("wrong number of diagnostics in %s; want one warning" , diags .ErrWithWarnings ())
105
106
}
@@ -144,7 +145,57 @@ func TestNodeValidatableResource_ValidateProvisioner__connectionInvalid(t *testi
144
145
},
145
146
}
146
147
147
- diags := node .validateProvisioner (ctx , pc )
148
+ diags := node .validateProvisioner (ctx , pc , nil )
149
+ if ! diags .HasErrors () {
150
+ t .Fatalf ("node.Eval succeeded; want error" )
151
+ }
152
+ if len (diags ) != 3 {
153
+ t .Fatalf ("wrong number of diagnostics; want two errors\n \n %s" , diags .Err ())
154
+ }
155
+
156
+ errStr := diags .Err ().Error ()
157
+ if ! (strings .Contains (errStr , "bananananananana" ) && strings .Contains (errStr , "bazaz" )) {
158
+ t .Fatalf ("wrong errors %q; want something about each of our invalid connInfo keys" , errStr )
159
+ }
160
+ }
161
+
162
+ func TestNodeValidatableResource_ValidateProvisioner_baseConnInvalid (t * testing.T ) {
163
+ ctx := & MockEvalContext {}
164
+ ctx .installSimpleEval ()
165
+ mp := & MockProvisioner {}
166
+ ps := & configschema.Block {}
167
+ ctx .ProvisionerSchemaSchema = ps
168
+ ctx .ProvisionerProvisioner = mp
169
+
170
+ pc := & configs.Provisioner {
171
+ Type : "baz" ,
172
+ Config : hcl .EmptyBody (),
173
+ }
174
+
175
+ baseConn := & configs.Connection {
176
+ Config : configs .SynthBody ("" , map [string ]cty.Value {
177
+ "type" : cty .StringVal ("ssh" ),
178
+ "bananananananana" : cty .StringVal ("foo" ),
179
+ "bazaz" : cty .StringVal ("bar" ),
180
+ }),
181
+ }
182
+
183
+ rc := & configs.Resource {
184
+ Mode : addrs .ManagedResourceMode ,
185
+ Type : "test_foo" ,
186
+ Name : "bar" ,
187
+ Config : configs .SynthBody ("" , map [string ]cty.Value {}),
188
+ Managed : & configs.ManagedResource {},
189
+ }
190
+
191
+ node := NodeValidatableResource {
192
+ NodeAbstractResource : & NodeAbstractResource {
193
+ Addr : mustConfigResourceAddr ("test_foo.bar" ),
194
+ Config : rc ,
195
+ },
196
+ }
197
+
198
+ diags := node .validateProvisioner (ctx , pc , baseConn )
148
199
if ! diags .HasErrors () {
149
200
t .Fatalf ("node.Eval succeeded; want error" )
150
201
}
0 commit comments