mirror of
https://github.com/hanzoai/metrics.git
synced 2026-10-30 20:03:39 +00:00
Updates: - unpin AWS dependencies and run `make vendor-update` - add config options to enable checksums only if required by storage in order to preserve backwards compatibility Related issues: - https://github.com/VictoriaMetrics/VictoriaMetrics/issues/9748 - https://github.com/VictoriaMetrics/VictoriaMetrics/issues/8622 Tested with: AWS S3, self-hosted MinIO, Linode object storage as it was failing previously with multi-part uploads (reported here - https://github.com/VictoriaMetrics/VictoriaMetrics/pull/8630#issuecomment-2772185033). An updated library allows (PR with the fix - https://github.com/aws/aws-sdk-go-v2/pull/3151) overriding multi-part upload configurations so that compatibility can be preserved. Signed-off-by: Zakhar Bessarab <[email protected]>
82 lines
2.7 KiB
Go
82 lines
2.7 KiB
Go
package assert
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
)
|
|
|
|
// isOrdered checks that collection contains orderable elements.
|
|
func isOrdered(t TestingT, object interface{}, allowedComparesResults []compareResult, failMessage string, msgAndArgs ...interface{}) bool {
|
|
objKind := reflect.TypeOf(object).Kind()
|
|
if objKind != reflect.Slice && objKind != reflect.Array {
|
|
return false
|
|
}
|
|
|
|
objValue := reflect.ValueOf(object)
|
|
objLen := objValue.Len()
|
|
|
|
if objLen <= 1 {
|
|
return true
|
|
}
|
|
|
|
value := objValue.Index(0)
|
|
valueInterface := value.Interface()
|
|
firstValueKind := value.Kind()
|
|
|
|
for i := 1; i < objLen; i++ {
|
|
prevValue := value
|
|
prevValueInterface := valueInterface
|
|
|
|
value = objValue.Index(i)
|
|
valueInterface = value.Interface()
|
|
|
|
compareResult, isComparable := compare(prevValueInterface, valueInterface, firstValueKind)
|
|
|
|
if !isComparable {
|
|
return Fail(t, fmt.Sprintf(`Can not compare type "%T" and "%T"`, value, prevValue), msgAndArgs...)
|
|
}
|
|
|
|
if !containsValue(allowedComparesResults, compareResult) {
|
|
return Fail(t, fmt.Sprintf(failMessage, prevValue, value), msgAndArgs...)
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// IsIncreasing asserts that the collection is increasing
|
|
//
|
|
// assert.IsIncreasing(t, []int{1, 2, 3})
|
|
// assert.IsIncreasing(t, []float{1, 2})
|
|
// assert.IsIncreasing(t, []string{"a", "b"})
|
|
func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
|
return isOrdered(t, object, []compareResult{compareLess}, "\"%v\" is not less than \"%v\"", msgAndArgs...)
|
|
}
|
|
|
|
// IsNonIncreasing asserts that the collection is not increasing
|
|
//
|
|
// assert.IsNonIncreasing(t, []int{2, 1, 1})
|
|
// assert.IsNonIncreasing(t, []float{2, 1})
|
|
// assert.IsNonIncreasing(t, []string{"b", "a"})
|
|
func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
|
return isOrdered(t, object, []compareResult{compareEqual, compareGreater}, "\"%v\" is not greater than or equal to \"%v\"", msgAndArgs...)
|
|
}
|
|
|
|
// IsDecreasing asserts that the collection is decreasing
|
|
//
|
|
// assert.IsDecreasing(t, []int{2, 1, 0})
|
|
// assert.IsDecreasing(t, []float{2, 1})
|
|
// assert.IsDecreasing(t, []string{"b", "a"})
|
|
func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
|
return isOrdered(t, object, []compareResult{compareGreater}, "\"%v\" is not greater than \"%v\"", msgAndArgs...)
|
|
}
|
|
|
|
// IsNonDecreasing asserts that the collection is not decreasing
|
|
//
|
|
// assert.IsNonDecreasing(t, []int{1, 1, 2})
|
|
// assert.IsNonDecreasing(t, []float{1, 2})
|
|
// assert.IsNonDecreasing(t, []string{"a", "b"})
|
|
func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
|
return isOrdered(t, object, []compareResult{compareLess, compareEqual}, "\"%v\" is not less than or equal to \"%v\"", msgAndArgs...)
|
|
}
|