remove old mock validateFn
This commit is contained in:
parent
ea5ee39f38
commit
177797100d
|
@ -693,8 +693,8 @@ func TestContext2Apply_providerWarning(t *testing.T) {
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
p.ApplyFn = testApplyFn
|
p.ApplyFn = testApplyFn
|
||||||
p.DiffFn = testDiffFn
|
p.DiffFn = testDiffFn
|
||||||
p.ValidateFn = func(c *ResourceConfig) (ws []string, es []error) {
|
p.ValidateResourceTypeConfigFn = func(req providers.ValidateResourceTypeConfigRequest) (resp providers.ValidateResourceTypeConfigResponse) {
|
||||||
ws = append(ws, "Just a warning")
|
resp.Diagnostics = resp.Diagnostics.Append(tfdiags.SimpleWarning("just a warning"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := testContext2(t, &ContextOpts{
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
|
|
@ -60,9 +60,6 @@ func TestContext2Input_provider(t *testing.T) {
|
||||||
actual = req.Config.GetAttr("foo").AsString()
|
actual = req.Config.GetAttr("foo").AsString()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.ValidateFn = func(c *ResourceConfig) ([]string, []error) {
|
|
||||||
return nil, c.CheckSet([]string{"foo"})
|
|
||||||
}
|
|
||||||
|
|
||||||
if diags := ctx.Input(InputModeStd); diags.HasErrors() {
|
if diags := ctx.Input(InputModeStd); diags.HasErrors() {
|
||||||
t.Fatalf("input errors: %s", diags.Err())
|
t.Fatalf("input errors: %s", diags.Err())
|
||||||
|
@ -133,9 +130,6 @@ func TestContext2Input_providerMulti(t *testing.T) {
|
||||||
|
|
||||||
var actual []interface{}
|
var actual []interface{}
|
||||||
var lock sync.Mutex
|
var lock sync.Mutex
|
||||||
p.ValidateFn = func(c *ResourceConfig) ([]string, []error) {
|
|
||||||
return nil, c.CheckSet([]string{"foo"})
|
|
||||||
}
|
|
||||||
|
|
||||||
if diags := ctx.Input(InputModeStd); diags.HasErrors() {
|
if diags := ctx.Input(InputModeStd); diags.HasErrors() {
|
||||||
t.Fatalf("input errors: %s", diags.Err())
|
t.Fatalf("input errors: %s", diags.Err())
|
||||||
|
|
|
@ -150,6 +150,7 @@ func TestContext2Validate_computedVar(t *testing.T) {
|
||||||
ResourceTypes: map[string]*configschema.Block{
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
"test_instance": {
|
"test_instance": {
|
||||||
Attributes: map[string]*configschema.Attribute{
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {Type: cty.String, Computed: true},
|
||||||
"value": {Type: cty.String, Optional: true},
|
"value": {Type: cty.String, Optional: true},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -165,12 +166,13 @@ func TestContext2Validate_computedVar(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
p.ValidateFn = func(c *ResourceConfig) ([]string, []error) {
|
p.PrepareProviderConfigFn = func(req providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) {
|
||||||
if !c.IsComputed("value") {
|
val := req.Config.GetAttr("value")
|
||||||
return nil, []error{fmt.Errorf("value isn't computed")}
|
if val.IsKnown() {
|
||||||
|
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("value isn't computed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, c.CheckSet([]string{"value"})
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
diags := c.Validate()
|
diags := c.Validate()
|
||||||
|
@ -463,8 +465,11 @@ func TestContext2Validate_moduleProviderVar(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
p.ValidateFn = func(c *ResourceConfig) ([]string, []error) {
|
p.PrepareProviderConfigFn = func(req providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) {
|
||||||
return nil, c.CheckSet([]string{"foo"})
|
if req.Config.GetAttr("foo").IsNull() {
|
||||||
|
resp.Diagnostics = resp.Diagnostics.Append(errors.New("foo is null"))
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
diags := c.Validate()
|
diags := c.Validate()
|
||||||
|
@ -498,8 +503,11 @@ func TestContext2Validate_moduleProviderInheritUnused(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
p.ValidateFn = func(c *ResourceConfig) ([]string, []error) {
|
p.PrepareProviderConfigFn = func(req providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) {
|
||||||
return nil, c.CheckSet([]string{"foo"})
|
if req.Config.GetAttr("foo").IsNull() {
|
||||||
|
resp.Diagnostics = resp.Diagnostics.Append(errors.New("foo is null"))
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
diags := c.Validate()
|
diags := c.Validate()
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/configs/hcl2shim"
|
"github.com/hashicorp/terraform/configs/hcl2shim"
|
||||||
"github.com/hashicorp/terraform/providers"
|
"github.com/hashicorp/terraform/providers"
|
||||||
"github.com/hashicorp/terraform/tfdiags"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ providers.Interface = (*MockProvider)(nil)
|
var _ providers.Interface = (*MockProvider)(nil)
|
||||||
|
@ -88,8 +87,6 @@ type MockProvider struct {
|
||||||
CloseCalled bool
|
CloseCalled bool
|
||||||
CloseError error
|
CloseError error
|
||||||
|
|
||||||
ValidateFn func(c *ResourceConfig) (ws []string, es []error)
|
|
||||||
//ValidateFn func(providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse
|
|
||||||
DiffFn func(providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse
|
DiffFn func(providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse
|
||||||
ApplyFn func(providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse
|
ApplyFn func(providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse
|
||||||
}
|
}
|
||||||
|
@ -149,19 +146,6 @@ func (p *MockProvider) ValidateResourceTypeConfig(r providers.ValidateResourceTy
|
||||||
p.ValidateResourceTypeConfigCalled = true
|
p.ValidateResourceTypeConfigCalled = true
|
||||||
p.ValidateResourceTypeConfigRequest = r
|
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 {
|
if p.ValidateResourceTypeConfigFn != nil {
|
||||||
return p.ValidateResourceTypeConfigFn(r)
|
return p.ValidateResourceTypeConfigFn(r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
value = "${test_instance.foo.value}"
|
value = test_instance.foo.id
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_instance" "bar" {}
|
resource "aws_instance" "bar" {}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
variable "value" {}
|
variable "value" {}
|
||||||
|
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
foo = "${var.value}"
|
foo = var.value
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_instance" "foo" {}
|
resource "aws_instance" "foo" {}
|
||||||
|
|
|
@ -3,5 +3,5 @@ variable "provider_var" {}
|
||||||
module "child" {
|
module "child" {
|
||||||
source = "./child"
|
source = "./child"
|
||||||
|
|
||||||
value = "${var.provider_var}"
|
value = var.provider_var
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue