* Upgraded golang.org/x/crypto v0.28.0 => v0.31.0.
Signed-off-by: peng wu <2030047311@qq.com>
* Upgraded golang.org/x/net v0.30.0 => v0.33.0.
Signed-off-by: peng wu <2030047311@qq.com>
* Upgraded github.com/golang/glog v1.2.2 => v1.2.4. Fix CVE-2024-45339.
Signed-off-by: peng wu <2030047311@qq.com>
* Upgrade go stdlib from 1.22.8 to 1.22.11. Fix CVE-2024-45336.
Signed-off-by: peng wu <2030047311@qq.com>
* Upgraded github.com/go-git/go-git/v5 v5.11.0 => v5.13.0. Fix CVE-2025-21613、CVE-2025-21614.
Signed-off-by: peng wu <2030047311@qq.com>
* Upgraded telemetry v1.0.1 => v1.0.2. Fix CVE-2024-45338、CVE-2024-34156、CVE-2024-34155、CVE-2024-34158、CVE-2024-4536、CVE-2024-45341.
Signed-off-by: peng wu <2030047311@qq.com>
---------
Signed-off-by: peng wu <2030047311@qq.com>
(cherry picked from commit d38db0054c)
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 \"%s\" and \"%s\"", reflect.TypeOf(value), reflect.TypeOf(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...)
|
|
}
|