2020-07-13 18:19:52 +03:00
|
|
|
package assert
|
|
|
|
|
|
|
|
import (
|
2024-02-14 21:46:47 -08:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/testing/assertions"
|
2020-08-13 19:22:25 +03:00
|
|
|
"github.com/sirupsen/logrus/hooks/test"
|
2020-07-13 18:19:52 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Equal compares values using comparison operator.
|
2020-07-20 04:36:28 +03:00
|
|
|
func Equal(tb assertions.AssertionTestingTB, expected, actual interface{}, msg ...interface{}) {
|
2020-07-18 21:45:04 -07:00
|
|
|
assertions.Equal(tb.Errorf, expected, actual, msg...)
|
2020-07-13 18:19:52 +03:00
|
|
|
}
|
|
|
|
|
2020-07-26 00:53:41 +08:00
|
|
|
// NotEqual compares values using comparison operator.
|
|
|
|
func NotEqual(tb assertions.AssertionTestingTB, expected, actual interface{}, msg ...interface{}) {
|
|
|
|
assertions.NotEqual(tb.Errorf, expected, actual, msg...)
|
|
|
|
}
|
|
|
|
|
2020-07-13 18:19:52 +03:00
|
|
|
// DeepEqual compares values using DeepEqual.
|
2021-05-17 14:32:04 -04:00
|
|
|
// NOTE: this function does not work for checking arrays/slices or maps of protobuf messages.
|
|
|
|
// For arrays/slices, please use DeepSSZEqual.
|
|
|
|
// For maps, please iterate through and compare the individual keys and values.
|
2020-07-20 04:36:28 +03:00
|
|
|
func DeepEqual(tb assertions.AssertionTestingTB, expected, actual interface{}, msg ...interface{}) {
|
2020-07-18 21:45:04 -07:00
|
|
|
assertions.DeepEqual(tb.Errorf, expected, actual, msg...)
|
2020-07-13 18:19:52 +03:00
|
|
|
}
|
|
|
|
|
2020-08-24 13:14:13 +03:00
|
|
|
// DeepNotEqual compares values using DeepEqual.
|
2021-05-17 14:32:04 -04:00
|
|
|
// NOTE: this function does not work for checking arrays/slices or maps of protobuf messages.
|
|
|
|
// For arrays/slices, please use DeepNotSSZEqual.
|
|
|
|
// For maps, please iterate through and compare the individual keys and values.
|
2020-08-24 13:14:13 +03:00
|
|
|
func DeepNotEqual(tb assertions.AssertionTestingTB, expected, actual interface{}, msg ...interface{}) {
|
|
|
|
assertions.DeepNotEqual(tb.Errorf, expected, actual, msg...)
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:02:48 -05:00
|
|
|
// DeepSSZEqual compares values using ssz.DeepEqual.
|
2021-02-09 15:57:22 -05:00
|
|
|
func DeepSSZEqual(tb assertions.AssertionTestingTB, expected, actual interface{}, msg ...interface{}) {
|
|
|
|
assertions.DeepSSZEqual(tb.Errorf, expected, actual, msg...)
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:02:48 -05:00
|
|
|
// DeepNotSSZEqual compares values using ssz.DeepEqual.
|
2021-02-09 15:57:22 -05:00
|
|
|
func DeepNotSSZEqual(tb assertions.AssertionTestingTB, expected, actual interface{}, msg ...interface{}) {
|
|
|
|
assertions.DeepNotSSZEqual(tb.Errorf, expected, actual, msg...)
|
|
|
|
}
|
|
|
|
|
2022-12-20 18:41:47 +08:00
|
|
|
// StringContains asserts a string contains specified substring.
|
|
|
|
func StringContains(tb assertions.AssertionTestingTB, expected, actual string, msg ...interface{}) {
|
|
|
|
assertions.StringContains(tb.Errorf, expected, actual, true, msg...)
|
|
|
|
}
|
|
|
|
|
2023-10-20 09:45:33 -07:00
|
|
|
// StringNotContains asserts a string does not contain specified substring.
|
2022-12-20 18:41:47 +08:00
|
|
|
func StringNotContains(tb assertions.AssertionTestingTB, expected, actual string, msg ...interface{}) {
|
|
|
|
assertions.StringContains(tb.Errorf, expected, actual, false, msg...)
|
|
|
|
}
|
|
|
|
|
2020-07-13 18:19:52 +03:00
|
|
|
// NoError asserts that error is nil.
|
2020-07-20 04:36:28 +03:00
|
|
|
func NoError(tb assertions.AssertionTestingTB, err error, msg ...interface{}) {
|
2020-07-15 23:10:54 +03:00
|
|
|
assertions.NoError(tb.Errorf, err, msg...)
|
2020-07-13 18:19:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// ErrorContains asserts that actual error contains wanted message.
|
2020-07-20 04:36:28 +03:00
|
|
|
func ErrorContains(tb assertions.AssertionTestingTB, want string, err error, msg ...interface{}) {
|
2020-07-15 23:10:54 +03:00
|
|
|
assertions.ErrorContains(tb.Errorf, want, err, msg...)
|
2020-07-13 18:19:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// NotNil asserts that passed value is not nil.
|
2020-07-20 04:36:28 +03:00
|
|
|
func NotNil(tb assertions.AssertionTestingTB, obj interface{}, msg ...interface{}) {
|
2020-07-15 23:10:54 +03:00
|
|
|
assertions.NotNil(tb.Errorf, obj, msg...)
|
2020-07-13 18:19:52 +03:00
|
|
|
}
|
2020-08-13 19:22:25 +03:00
|
|
|
|
|
|
|
// LogsContain checks that the desired string is a subset of the current log output.
|
|
|
|
func LogsContain(tb assertions.AssertionTestingTB, hook *test.Hook, want string, msg ...interface{}) {
|
|
|
|
assertions.LogsContain(tb.Errorf, hook, want, true, msg...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// LogsDoNotContain is the inverse check of LogsContain.
|
|
|
|
func LogsDoNotContain(tb assertions.AssertionTestingTB, hook *test.Hook, want string, msg ...interface{}) {
|
|
|
|
assertions.LogsContain(tb.Errorf, hook, want, false, msg...)
|
|
|
|
}
|
2021-07-15 17:32:10 -05:00
|
|
|
|
|
|
|
// NotEmpty checks that the object fields are not empty. This method also checks all of the
|
|
|
|
// pointer fields to ensure none of those fields are empty.
|
|
|
|
func NotEmpty(tb assertions.AssertionTestingTB, obj interface{}, msg ...interface{}) {
|
|
|
|
assertions.NotEmpty(tb.Errorf, obj, msg...)
|
|
|
|
}
|