| // Copyright (c) HashiCorp, Inc. |
| // SPDX-License-Identifier: BUSL-1.1 |
| |
| package terraform |
| |
| import ( |
| "github.com/hashicorp/terraform/internal/addrs" |
| "github.com/hashicorp/terraform/internal/configs/configschema" |
| "github.com/hashicorp/terraform/internal/providers" |
| "github.com/hashicorp/terraform/internal/providers/testing" |
| "github.com/hashicorp/terraform/internal/schemarepo" |
| "github.com/hashicorp/terraform/internal/schemarepo/loadschemas" |
| ) |
| |
| func simpleTestSchemas() *schemarepo.Schemas { |
| provider := simpleMockProvider() |
| provisioner := simpleMockProvisioner() |
| |
| return &Schemas{ |
| Providers: map[addrs.Provider]providers.ProviderSchema{ |
| addrs.NewDefaultProvider("test"): provider.GetProviderSchema(), |
| }, |
| Provisioners: map[string]*configschema.Block{ |
| "test": provisioner.GetSchemaResponse.Provisioner, |
| }, |
| } |
| } |
| |
| // schemaOnlyProvidersForTesting is a testing helper that constructs a |
| // plugin library that contains a set of providers that only know how to |
| // return schema, and will exhibit undefined behavior if used for any other |
| // purpose. |
| // |
| // The intended use for this is in testing components that use schemas to |
| // drive other behavior, such as reference analysis during graph construction, |
| // but that don't actually need to interact with providers otherwise. |
| func schemaOnlyProvidersForTesting(schemas map[addrs.Provider]providers.ProviderSchema) *loadschemas.Plugins { |
| factories := make(map[addrs.Provider]providers.Factory, len(schemas)) |
| |
| for providerAddr, schema := range schemas { |
| schema := schema |
| |
| provider := &testing.MockProvider{ |
| GetProviderSchemaResponse: &schema, |
| } |
| |
| factories[providerAddr] = func() (providers.Interface, error) { |
| return provider, nil |
| } |
| } |
| |
| return newContextPlugins(factories, nil, nil) |
| } |