MCPcopy
hub / github.com/opentofu/opentofu / TestContext2Validate_orphans

Function TestContext2Validate_orphans

internal/tofu/context_validate_test.go:521–558  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

519}
520
521func 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
560func TestContext2Validate_providerConfig_bad(t *testing.T) {
561 m := testModule(t, "validate-bad-pc")

Callers

nothing calls this directly

Calls 12

AppendMethod · 0.95
HasErrorsMethod · 0.95
ErrMethod · 0.95
NewLibraryFunction · 0.92
NewDefaultProviderFunction · 0.92
testModuleFunction · 0.85
testContext2Function · 0.85
testProviderFuncFixedFunction · 0.85
GetAttrMethod · 0.80
NewMethod · 0.80
testProviderFunction · 0.70
ValidateMethod · 0.65

Tested by

no test coverage detected