sweeper

package
v1.20.1-0...-f9123b0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0

Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTestSweepers

func AddTestSweepers(name string, sweeper func(region string) error)

func ExecuteSweepers

func ExecuteSweepers(t *testing.T)

ExecuteSweepers

Sweepers enable infrastructure cleanup functions to be included with resource definitions, typically so developers can remove all resources of that resource type from testing infrastructure in case of failures that prevented the normal resource destruction behavior of acceptance tests. Use the AddTestSweepers() function to configure available sweepers.

Sweeper flags added to the "go test" command:

-sweep: Comma-separated list of locations/regions to run available sweepers.
-sweep-allow-failues: Enable to allow other sweepers to run after failures.
-sweep-run: Comma-separated list of resource type sweepers to run. Defaults
        to all sweepers.

Refer to the Env prefixed constants for environment variables that further control testing functionality.

func IsSweepableTestResource

func IsSweepableTestResource(resourceName string) bool

func ListParentResourcesInLocation

func ListParentResourcesInLocation(d *tpgresource.ResourceDataMock, config *transport_tpg.Config, listTemplate, responseField string) ([]string, error)

ListParentResourcesInLocation calls a provided list endpoint and returns the names of any resources found in the response. This function is intended to be used in sweepers where the resources being swept can only be found with knowledge about existing parental resources.

func SharedConfigForRegion

func SharedConfigForRegion(region string) (*transport_tpg.Config, error)

SharedConfigForRegion returns a common config setup needed for the sweeper functions for a given region

Types

type Sweeper

type Sweeper struct {
	// Name for sweeper. Must be unique to be ran by the Sweeper Runner
	Name string

	// Dependencies list the const names of other Sweeper functions that must be ran
	// prior to running this Sweeper. This is an ordered list that will be invoked
	// recursively at the helper/resource level
	Dependencies []string

	// Sweeper function that when invoked sweeps the Provider of specific
	// resources
	F SweeperFunc
}

type SweeperFunc

type SweeperFunc func(r string) error

SweeperFunc is a signature for a function that acts as a sweeper. It accepts a string for the region that the sweeper is to be ran in. This function must be able to construct a valid client for that region.

Jump to

Keyboard shortcuts

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