testutils

package
v3.13.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: MPL-2.0 Imports: 21 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 {
					errs := []error{}
					for _, diag := range configureResp.Diagnostics {
						errs = append(errs, fmt.Errorf("%s %s: %s", diag.Severity, diag.Summary, diag.Detail))
					}
					err = errors.Join(errs...)
				}
				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 CheckLister added in v3.5.0

func CheckLister(terraformResource string) resource.TestCheckFunc

CheckLister is a resource.TestCheckFunc that checks that the resource's lister function returns the given ID. This is meant to be used at least once in every resource's tests to ensure that the resource's lister function is working correctly.

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