(t *testing.T)
| 519 | } |
| 520 | |
| 521 | func TestContext2Validate_orphans(t *testing.T) { |
| 522 | p := testProvider("aws") |
| 523 | p.GetProviderSchemaResponse = &providers.GetProviderSchemaResponse{ |
| 524 | ResourceTypes: map[string]providers.Schema{ |
| 525 | "aws_instance": { |
| 526 | Block: &configschema.Block{ |
| 527 | Attributes: map[string]*configschema.Attribute{ |
| 528 | "foo": {Type: cty.String, Optional: true}, |
| 529 | "num": {Type: cty.String, Optional: true}, |
| 530 | }, |
| 531 | }, |
| 532 | }, |
| 533 | }, |
| 534 | } |
| 535 | |
| 536 | m := testModule(t, "validate-good") |
| 537 | |
| 538 | c := testContext2(t, &ContextOpts{ |
| 539 | Plugins: plugins.NewLibrary(map[addrs.Provider]providers.Factory{ |
| 540 | addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p), |
| 541 | }, nil), |
| 542 | }) |
| 543 | |
| 544 | p.ValidateResourceConfigFn = func(req providers.ValidateResourceConfigRequest) providers.ValidateResourceConfigResponse { |
| 545 | var diags tfdiags.Diagnostics |
| 546 | if req.Config.GetAttr("foo").IsNull() { |
| 547 | diags = diags.Append(errors.New("foo is not set")) |
| 548 | } |
| 549 | return providers.ValidateResourceConfigResponse{ |
| 550 | Diagnostics: diags, |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | diags := c.Validate(context.Background(), m) |
| 555 | if diags.HasErrors() { |
| 556 | t.Fatalf("unexpected error: %s", diags.Err()) |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | func TestContext2Validate_providerConfig_bad(t *testing.T) { |
| 561 | m := testModule(t, "validate-bad-pc") |
nothing calls this directly
no test coverage detected