testutils

package
v2.19.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2024 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ProtoV5ProviderFactories is a static map containing the grafana provider instance
	// It is used to configure the provider in acceptance tests
	ProtoV5ProviderFactories = map[string]func() (tfprotov5.ProviderServer, error){
		"grafana": func() (tfprotov5.ProviderServer, error) {

			ctx := context.Background()
			server, err := provider.MakeProviderServer(ctx, "testacc")
			if err != nil {
				return nil, err
			}

			schemaResp, err := server.GetProviderSchema(ctx, nil)
			if err != nil {
				return nil, fmt.Errorf("failed to get provider schema: %v", err)
			}
			fields := map[string]tftypes.Value{}
			for _, v := range schemaResp.Provider.Block.Attributes {
				fields[v.Name] = tftypes.NewValue(v.Type, nil)
			}
			testValue := tftypes.NewValue(schemaResp.Provider.ValueType(), fields)
			testDynamicValue, err := tfprotov5.NewDynamicValue(schemaResp.Provider.ValueType(), testValue)
			if err != nil {
				return nil, err
			}

			configureResp, err := server.ConfigureProvider(context.Background(), &tfprotov5.ConfigureProviderRequest{Config: &testDynamicValue})
			if err != nil || len(configureResp.Diagnostics) > 0 {
				if err == nil {
					err = fmt.Errorf("provider configuration failed: %v", configureResp.Diagnostics)
				}
				return nil, fmt.Errorf("failed to configure provider: %v", err)
			}
			return server, nil
		},
	}

	// Provider is the "main" provider instance
	//
	// This Provider can be used in testing code for API calls without requiring
	// the use of saving and referencing specific ProviderFactories instances.
	//
	// It is configured from the main provider package when the test suite is initialized
	// but it is used in tests of every package
	Provider *schema.Provider
)

Functions

func AccTestsEnabled

func AccTestsEnabled(envVarName string) bool

func CheckCloudAPITestsEnabled

func CheckCloudAPITestsEnabled(t *testing.T)

CheckCloudTestsEnabled checks if the cloud tests are enabled. This should be the first line of any test that tests Cloud API features

func CheckCloudInstanceTestsEnabled

func CheckCloudInstanceTestsEnabled(t *testing.T)

CheckCloudInstanceTestsEnabled checks if tests that run on cloud instances are enabled. This should be the first line of any test that tests Grafana Cloud Pro features

func CheckEnterpriseTestsEnabled

func CheckEnterpriseTestsEnabled(t *testing.T, semverConstraintOptional ...string)

CheckEnterpriseTestsEnabled checks if the enterprise tests are enabled. This should be the first line of any test that tests Grafana Enterprise features

func CheckEnvVarsSet

func CheckEnvVarsSet(t *testing.T, envVars ...string)

func CheckOSSTestsEnabled

func CheckOSSTestsEnabled(t *testing.T, semverConstraintOptional ...string)

CheckOSSTestsEnabled checks if the OSS acceptance tests are enabled. This should be the first line of any test that uses Grafana OSS features only

func IsUnitTest

func IsUnitTest(t *testing.T)

func TestAccExample

func TestAccExample(t *testing.T, path string) string

TestAccExample returns an example config from the examples directory. Examples are used for both documentation and acceptance tests.

func TestAccExampleWithReplace

func TestAccExampleWithReplace(t *testing.T, path string, replaceMap map[string]string) string

TestAccExampleWithReplace works like testAccExample, but replaces strings in the example.

func WithoutResource

func WithoutResource(t *testing.T, tfCode string, resourceNames ...string) string

WithoutResource removes a resource from a Terraform configuration.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL