test for RPC warnings with no errors
This commit is contained in:
parent
f987b69777
commit
b8bed97ef4
|
@ -12230,3 +12230,52 @@ resource "test_resource" "foo" {
|
|||
t.Fatal("missing 'test_resource.foo' in state:", state)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_rpcDiagnostics(t *testing.T) {
|
||||
m := testModuleInline(t, map[string]string{
|
||||
"main.tf": `
|
||||
resource "test_instance" "a" {
|
||||
}
|
||||
`,
|
||||
})
|
||||
|
||||
p := testProvider("test")
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"id": {Type: cty.String, Computed: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
p.ValidateResourceTypeConfigResponse = providers.ValidateResourceTypeConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics(nil).Append(tfdiags.SimpleWarning("don't frobble")),
|
||||
}
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
_, diags := ctx.Plan()
|
||||
if diags.HasErrors() {
|
||||
t.Fatal(diags.Err())
|
||||
}
|
||||
|
||||
_, diags = ctx.Apply()
|
||||
if diags.HasErrors() {
|
||||
t.Fatal(diags.Err())
|
||||
}
|
||||
|
||||
for _, d := range diags {
|
||||
des := d.Description().Summary
|
||||
if !strings.Contains(des, "frobble") {
|
||||
t.Fatalf(`expected frobble, got %q`, des)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6421,3 +6421,46 @@ data "test_data_source" "b" {
|
|||
t.Fatal("data source b was not read during plan")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Plan_rpcDiagnostics(t *testing.T) {
|
||||
m := testModuleInline(t, map[string]string{
|
||||
"main.tf": `
|
||||
resource "test_instance" "a" {
|
||||
}
|
||||
`,
|
||||
})
|
||||
|
||||
p := testProvider("test")
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"id": {Type: cty.String, Computed: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
p.ValidateResourceTypeConfigResponse = providers.ValidateResourceTypeConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics(nil).Append(tfdiags.SimpleWarning("don't herd cats")),
|
||||
}
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
_, diags := ctx.Plan()
|
||||
if diags.HasErrors() {
|
||||
t.Fatal(diags.Err())
|
||||
}
|
||||
|
||||
for _, d := range diags {
|
||||
des := d.Description().Summary
|
||||
if !strings.Contains(des, "cats") {
|
||||
t.Fatalf(`expected cats, got %q`, des)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1795,3 +1795,46 @@ resource "test_instance" "a" {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Validate_rpcDiagnostics(t *testing.T) {
|
||||
// validate module and output depends_on
|
||||
m := testModuleInline(t, map[string]string{
|
||||
"main.tf": `
|
||||
resource "test_instance" "a" {
|
||||
}
|
||||
`,
|
||||
})
|
||||
|
||||
p := testProvider("test")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"id": {Type: cty.String, Computed: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
p.ValidateResourceTypeConfigResponse = providers.ValidateResourceTypeConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics(nil).Append(tfdiags.SimpleWarning("don't frobble")),
|
||||
}
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
diags := ctx.Validate()
|
||||
if diags.HasErrors() {
|
||||
t.Fatal(diags.Err())
|
||||
}
|
||||
|
||||
for _, d := range diags {
|
||||
des := d.Description().Summary
|
||||
if !strings.Contains(des, "frobble") {
|
||||
t.Fatalf(`expected frobble, got %q`, des)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue