Documentation ¶
Index ¶
- Constants
- func Assert(actual any, expected any, customAssertions map[string]AssertionFunc) (bool, string)
- func SkipAssertion(actual any, expected ...any) string
- type AssertionFunc
- func AssertFloat64ToDecimalPlaces(decimalPlaces int) AssertionFunc
- func AssertFloat64WithTolerance(tolerance float64) AssertionFunc
- func AssertNumberWithTolerance[T ~int | ~int64 | ~float64 | ~float32 | ~int32](tolerance T) AssertionFunc
- func AssertStringWithCleanup(cleanup func(string) string) AssertionFunc
- func AssertStringWithDistance(distance int) AssertionFunc
- func AssertTimeToDuration(duration time.Duration) AssertionFunc
- func SkipAssertionIf(condition func(actual any, expected any) bool, customAssertion AssertionFunc) AssertionFunc
Constants ¶
const ( TimeType = "time.Time" FloatType = "float64" IntType = "int" Int64Type = "int64" )
Variables ¶
This section is empty.
Functions ¶
func Assert ¶
Assert compares the actual and expected values using the custom assertions defined and returns the result and message actual is the actual value to be compared expected is the expected value to be compared customAssertions is the map of custom assertions defined for the path or type Example usage:
customAssertions := map[string]AssertionFunc{ "field1": customAssertionFunc1, "field2": customAssertionFunc2, "int": customAssertionFunc3, }
match, message := Assert(actual, expected, customAssertions) returns the result and message
func SkipAssertion ¶
SkipAssertion is a custom assertion function that always returns true.
Types ¶
type AssertionFunc ¶
type AssertionFunc assertions.SoFunc
func AssertFloat64ToDecimalPlaces ¶
func AssertFloat64ToDecimalPlaces(decimalPlaces int) AssertionFunc
AssertFloat64ToDecimalPlaces is a custom assertion function that rounds float64 to the specified decimal places before comparing. this function is rounding the float64 to the specified decimal places before comparing.
func AssertFloat64WithTolerance ¶
func AssertFloat64WithTolerance(tolerance float64) AssertionFunc
AssertFloat64WithTolerance is a custom assertion function that compares float64 values with a tolerance. tolerance is in format of 0.0001 if tolerance is 0, it will compare the float64 values as is.
func AssertNumberWithTolerance ¶ added in v1.0.11
func AssertNumberWithTolerance[T ~int | ~int64 | ~float64 | ~float32 | ~int32](tolerance T) AssertionFunc
AssertNumberWithTolerance is a custom assertion function that compares number values with a tolerance. tolerance is in format of 0.0001 if tolerance is 0, it will compare the value as is.
func AssertStringWithCleanup ¶
func AssertStringWithCleanup(cleanup func(string) string) AssertionFunc
AssertStringWithCleanup is a custom assertion function that cleans up the string before comparing. cleanup function is a function that takes a string and returns a string after cleanup. if cleanup is nil, it will compare the string as is.
func AssertStringWithDistance ¶ added in v1.0.12
func AssertStringWithDistance(distance int) AssertionFunc
func AssertTimeToDuration ¶
func AssertTimeToDuration(duration time.Duration) AssertionFunc
AssertTimeToDuration is a custom assertion function that truncates time to the specified duration before comparing. this function is using time.Truncate() to truncate the time to the specified duration.
func SkipAssertionIf ¶
func SkipAssertionIf(condition func(actual any, expected any) bool, customAssertion AssertionFunc) AssertionFunc
SkipAssertionIf is a custom assertion function that skips the assertion if the condition is met. if the condition is met, it will return an empty string. if not, it will return the result of the provided customAssertion function or default assertion function shouldEqual.