utils

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExpectResourceNotFound = "expectNotFoundResource"
)

Variables

This section is empty.

Functions

func Added

func Added(oldValues, newValues []string) []string

func DiagError

func DiagError(summary string, err error, diags diag.Diagnostics) diag.Diagnostics

DiagError collects errors and appends diagnostics with diagnostic of err

func Filter

func Filter[T any](slice []T, filterFunc func(T) bool) []T

Filter takes 2 arguments: 1. A slice of generic type T 2. A function that excepts an argument of generic type T and returns a boolean The Filter function than applies the filterFunc to each element of the slice and returns a sub-slice which contains all element x where filterFunc(x) == true

func GetChangeWithParse

func GetChangeWithParse[T any](d *schema.ResourceData, key string, parseFunc func(any) T) (T, T, bool)

GetChangeWithParse checks if there has been any changes made to the value saved under the given key in the resourceData object if so, the functon applies the given parse function to the old and new values and returns the parsing results the function also returns a boolean which indicates weather a change has been made or not

func Map

func Map[T, U any](slice []T, mapFunc func(T) U) []U

Map takes 2 arguments: 1. A slice of generic type T 2. A function that excepts an argument of generic type T and returns a value of generic type U The Map function than applies the mapFunc to each element of the slice and returns a slice of the retruned values from the mapFunc

func MustGetChange

func MustGetChange[T any](d *schema.ResourceData, key string) (T, T, bool)

GetChangeWithParse checks if there has been any changes made to the value saved under the given key in the resourceData object if so, the functon converts the the old and new values to the desired type note that if the conversion fails the function will panic!

func MustResourceDataCollectionToSlice

func MustResourceDataCollectionToSlice[T any](d *schema.ResourceData, fieldName string) []T

MustResourceDataCollectionToSlice takes a ResourceData object and a fieldName the function tries to retrieve the field's value and expects it to be of type schema.TypeSet or schema.TypeList (otherwise it will panic!) this function then converts the set/list to a slice of the desired type

func MustSchemaCollectionToSlice

func MustSchemaCollectionToSlice[T any](listOrSet any) []T

MustSchemaCollectionToSlice converts the argument to a slice of the desired type The argument must be of type schema.TypeSet or schema.TypeList otherwise, the function will panic

func MustSliceAs

func MustSliceAs[T any](slice []any) []T

MustSliceAs takes a slice as an argument and converts all it's members to the desired type T

func MustUnmarshalAs

func MustUnmarshalAs[T, U any](toConvert U) T

MustUnmarshalAs marshals the argument and than unmarshals it to the desired type ignores error if marshal/unmarshal fails (prints the error and returns the empty value of the desired type)

func MustValueAs

func MustValueAs[T any](val any) T

MustValueAs converts a the given argument to the desired type note that this conversion is not safe and may panic

func Removed

func Removed(oldValues, newValues []string) []string

func SliceToStringIndicatorsMap

func SliceToStringIndicatorsMap[T any](slice []T) map[string]T

SliceToStringIndicatorsMap excepts a slice of generice type T The function returns a map from a string representation of each value in the slice to the value itself for example: [1, 2, 3] ==> {"1": 1, "2": 2, "3": 3}

func SlicesDiff

func SlicesDiff[T any](oldValues, newValues []T) ([]T, []T)

SlicesDiff excepts to slices which represents old and new values THe function returns: 1. a slice of all values that exist in the new and not in the old slice (a.k.a "added") 2. a slice of all values that exist in the old and not in the new slice (a.k.a "removed")

func SupressDiffIfExists

func SupressDiffIfExists(k, old, new string, d *schema.ResourceData) bool

SupressDiffIfExists shows diff only if resource is new

func UnmarshalAs

func UnmarshalAs[T, U any](toConvert U) (T, error)

UnmarshalAs marshals the argument and than unmarshals it to the desired type returns error upon failure

Types

This section is empty.

Jump to

Keyboard shortcuts

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