remove old mock validateFn

This commit is contained in:
James Bardin 2020-10-08 12:43:46 -04:00
parent ea5ee39f38
commit 177797100d
7 changed files with 21 additions and 35 deletions

View File

@ -693,8 +693,8 @@ func TestContext2Apply_providerWarning(t *testing.T) {
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
p.ValidateFn = func(c *ResourceConfig) (ws []string, es []error) {
ws = append(ws, "Just a warning")
p.ValidateResourceTypeConfigFn = func(req providers.ValidateResourceTypeConfigRequest) (resp providers.ValidateResourceTypeConfigResponse) {
resp.Diagnostics = resp.Diagnostics.Append(tfdiags.SimpleWarning("just a warning"))
return
}
ctx := testContext2(t, &ContextOpts{

View File

@ -60,9 +60,6 @@ func TestContext2Input_provider(t *testing.T) {
actual = req.Config.GetAttr("foo").AsString()
return
}
p.ValidateFn = func(c *ResourceConfig) ([]string, []error) {
return nil, c.CheckSet([]string{"foo"})
}
if diags := ctx.Input(InputModeStd); diags.HasErrors() {
t.Fatalf("input errors: %s", diags.Err())
@ -133,9 +130,6 @@ func TestContext2Input_providerMulti(t *testing.T) {
var actual []interface{}
var lock sync.Mutex
p.ValidateFn = func(c *ResourceConfig) ([]string, []error) {
return nil, c.CheckSet([]string{"foo"})
}
if diags := ctx.Input(InputModeStd); diags.HasErrors() {
t.Fatalf("input errors: %s", diags.Err())

View File

@ -150,6 +150,7 @@ func TestContext2Validate_computedVar(t *testing.T) {
ResourceTypes: map[string]*configschema.Block{
"test_instance": {
Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true},
"value": {Type: cty.String, Optional: true},
},
},
@ -165,12 +166,13 @@ func TestContext2Validate_computedVar(t *testing.T) {
},
})
p.ValidateFn = func(c *ResourceConfig) ([]string, []error) {
if !c.IsComputed("value") {
return nil, []error{fmt.Errorf("value isn't computed")}
p.PrepareProviderConfigFn = func(req providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) {
val := req.Config.GetAttr("value")
if val.IsKnown() {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("value isn't computed"))
}
return nil, c.CheckSet([]string{"value"})
return
}
diags := c.Validate()
@ -463,8 +465,11 @@ func TestContext2Validate_moduleProviderVar(t *testing.T) {
},
})
p.ValidateFn = func(c *ResourceConfig) ([]string, []error) {
return nil, c.CheckSet([]string{"foo"})
p.PrepareProviderConfigFn = func(req providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) {
if req.Config.GetAttr("foo").IsNull() {
resp.Diagnostics = resp.Diagnostics.Append(errors.New("foo is null"))
}
return
}
diags := c.Validate()
@ -498,8 +503,11 @@ func TestContext2Validate_moduleProviderInheritUnused(t *testing.T) {
},
})
p.ValidateFn = func(c *ResourceConfig) ([]string, []error) {
return nil, c.CheckSet([]string{"foo"})
p.PrepareProviderConfigFn = func(req providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) {
if req.Config.GetAttr("foo").IsNull() {
resp.Diagnostics = resp.Diagnostics.Append(errors.New("foo is null"))
}
return
}
diags := c.Validate()

View File

@ -9,7 +9,6 @@ import (
"github.com/hashicorp/terraform/configs/hcl2shim"
"github.com/hashicorp/terraform/providers"
"github.com/hashicorp/terraform/tfdiags"
)
var _ providers.Interface = (*MockProvider)(nil)
@ -88,8 +87,6 @@ type MockProvider struct {
CloseCalled bool
CloseError error
ValidateFn func(c *ResourceConfig) (ws []string, es []error)
//ValidateFn func(providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse
DiffFn func(providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse
ApplyFn func(providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse
}
@ -149,19 +146,6 @@ func (p *MockProvider) ValidateResourceTypeConfig(r providers.ValidateResourceTy
p.ValidateResourceTypeConfigCalled = true
p.ValidateResourceTypeConfigRequest = r
if p.ValidateFn != nil {
resp := p.getSchema()
schema := resp.Provider.Block
rc := NewResourceConfigShimmed(r.Config, schema)
warns, errs := p.ValidateFn(rc)
ret := providers.ValidateResourceTypeConfigResponse{}
for _, warn := range warns {
ret.Diagnostics = ret.Diagnostics.Append(tfdiags.SimpleWarning(warn))
}
for _, err := range errs {
ret.Diagnostics = ret.Diagnostics.Append(err)
}
}
if p.ValidateResourceTypeConfigFn != nil {
return p.ValidateResourceTypeConfigFn(r)
}

View File

@ -1,5 +1,5 @@
provider "aws" {
value = "${test_instance.foo.value}"
value = test_instance.foo.id
}
resource "aws_instance" "bar" {}

View File

@ -1,7 +1,7 @@
variable "value" {}
provider "aws" {
foo = "${var.value}"
foo = var.value
}
resource "aws_instance" "foo" {}

View File

@ -3,5 +3,5 @@ variable "provider_var" {}
module "child" {
source = "./child"
value = "${var.provider_var}"
value = var.provider_var
}