Add integration test in context_validate

This commit is contained in:
Pam Selle 2020-11-20 10:58:40 -05:00
parent b1e229ef6c
commit d626a7787d
1 changed files with 65 additions and 0 deletions

View File

@ -1131,6 +1131,71 @@ func TestContext2Validate_interpolateMap(t *testing.T) {
} }
} }
func TestContext2Validate_varSensitive(t *testing.T) {
// Smoke test through validate where a variable has sensitive applied
m := testModuleInline(t, map[string]string{
"main.tf": `
variable "foo" {
default = "xyz"
sensitive = true
}
variable "bar" {
sensitive = true
}
data "aws_data_source" "bar" {
foo = var.bar
}
resource "aws_instance" "foo" {
foo = var.foo
}
`,
})
p := testProvider("aws")
p.ValidateResourceTypeConfigFn = func(req providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse {
// Providers receive unmarked values
if got, want := req.Config.GetAttr("foo"), cty.UnknownVal(cty.String); !got.RawEquals(want) {
t.Fatalf("wrong value for foo\ngot: %#v\nwant: %#v", got, want)
}
return providers.ValidateResourceTypeConfigResponse{}
}
p.ValidateDataSourceConfigFn = func(req providers.ValidateDataSourceConfigRequest) (resp providers.ValidateDataSourceConfigResponse) {
if got, want := req.Config.GetAttr("foo"), cty.UnknownVal(cty.String); !got.RawEquals(want) {
t.Fatalf("wrong value for foo\ngot: %#v\nwant: %#v", got, want)
}
return providers.ValidateDataSourceConfigResponse{}
}
ctx := testContext2(t, &ContextOpts{
Config: m,
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
},
Variables: InputValues{
"bar": &InputValue{
Value: cty.StringVal("boop"),
SourceType: ValueFromCaller,
},
},
})
diags := ctx.Validate()
if diags.HasErrors() {
t.Fatal(diags.Err())
}
if !p.ValidateResourceTypeConfigCalled {
t.Fatal("expected ValidateResourceTypeConfigFn to be called")
}
if !p.ValidateDataSourceConfigCalled {
t.Fatal("expected ValidateDataSourceConfigFn to be called")
}
}
// Manually validate using the new PlanGraphBuilder // Manually validate using the new PlanGraphBuilder
func TestContext2Validate_PlanGraphBuilder(t *testing.T) { func TestContext2Validate_PlanGraphBuilder(t *testing.T) {
fixture := contextFixtureApplyVars(t) fixture := contextFixtureApplyVars(t)