testsupport

package
v1.52.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAPIResourceAllAbsent added in v1.50.1

func CheckAPIResourceAllAbsent[T any](resType string, getter GetAPIResourceFunc[T]) resource.TestCheckFunc

CheckAPIResourceAllAbsent checks that all the terraform resource type 'resType' are absent from the API.

func CheckAPIResourcePresent added in v1.50.1

func CheckAPIResourcePresent[T any](tfID string, getter GetAPIResourceFunc[T]) resource.TestCheckFunc

CheckAPIResourcePresent checks that the terraform resource 'tfID' is present in the API.

func CheckResourceAttrFunc

func CheckResourceAttrFunc(name, key string, valueFunc interface{}) resource.TestCheckFunc

CheckResourceAttrFunc uses valueFunc to obtain the expected attribute value.

This allows to delay determining the expected value to just before the moment it is checked.

The valueFunc may either be a func() string or a func() []string. If valueFunc is a func() []string it is enough if the resource attribute matches any value in the string slice returned by valueFunc.

func CheckResourceExists

func CheckResourceExists(name string, k KeyFunc) resource.TestCheckFunc

CheckResourceExists checks that a resource with the passed name exists.

CheckResourceExists uses k to actually retrieve the resource from the Hetzner Cloud backend.

func CheckResourcesDestroyed

func CheckResourcesDestroyed(resType string, k KeyFunc) resource.TestCheckFunc

CheckResourcesDestroyed checks if resources of resType do not exist in the Hetzner Cloud backend anymore.

func CreateClient

func CreateClient() (*hcloud.Client, error)

CreateClient creates a new *hcloud.Client which authenticates using the HCLOUD_TOKEN variable.

func LiftTCF

func LiftTCF(f func() error) resource.TestCheckFunc

LiftTCF lifts f to a resource.TestCheckFunc.

func ProjectRoot

func ProjectRoot(t *testing.T) string

ProjectRoot starts at the current working directory and looks for the projects root directory, i.e. the directory containing the .git directory.

ProjectRoot stops as soon as it found the .git directory, or upon reaching the users home directory. In the later case it fails the test.

func RandTLSCert added in v1.23.0

func RandTLSCert(orgName string) (string, string, error)

RandTLSCert generates a self-signed TLS certificate with a newly created private key, and returns both the cert and the private key PEM encoded.

Types

type GetAPIResourceFunc added in v1.50.1

type GetAPIResourceFunc[T any] func(c *hcloud.Client, attrs map[string]string) (*T, error)

GetAPIResourceFunc fetches a resource 'T' from the Hetzner Cloud API using its terraform attributes 'attrs'.

func CopyAPIResource added in v1.50.1

func CopyAPIResource[T any](target *T, getter GetAPIResourceFunc[T]) GetAPIResourceFunc[T]

CopyAPIResource is used to wrap GetAPIResourceFunc, and copy the fetched api resource 'T' into the provide 'target' pointer variable before passing down the result.

type KeyFunc

type KeyFunc func(c *hcloud.Client, id int64) bool

KeyFunc allows to retrieve a resource from the Hetzner Cloud backend using its ID.

KeyFunc must return true if the resource was found.

Jump to

Keyboard shortcuts

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