2024-03-25 11:01:09 +00:00
|
|
|
package dynassert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/databricks/cli/libs/dyn"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func Equal(t assert.TestingT, expected any, actual any, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
ev, eok := expected.(dyn.Value)
|
|
|
|
av, aok := actual.(dyn.Value)
|
|
|
|
if eok && aok && ev.IsValid() && av.IsValid() {
|
|
|
|
if !assert.Equal(t, ev.AsAny(), av.AsAny(), msgAndArgs...) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// The values are equal on contents. Now compare the locations.
|
|
|
|
if !assert.Equal(t, ev.Location(), av.Location(), msgAndArgs...) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Walk ev and av and compare the locations of each element.
|
|
|
|
_, err := dyn.Walk(ev, func(p dyn.Path, evv dyn.Value) (dyn.Value, error) {
|
|
|
|
avv, err := dyn.GetByPath(av, p)
|
|
|
|
if assert.NoError(t, err, "unable to get value from actual value at path %v", p.String()) {
|
|
|
|
assert.Equal(t, evv.Location(), avv.Location())
|
|
|
|
}
|
|
|
|
return evv, nil
|
|
|
|
})
|
|
|
|
return assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return assert.Equal(t, expected, actual, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func EqualValues(t assert.TestingT, expected, actual any, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.EqualValues(t, expected, actual, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func NotEqual(t assert.TestingT, expected any, actual any, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.NotEqual(t, expected, actual, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func Len(t assert.TestingT, object any, length int, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.Len(t, object, length, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func Empty(t assert.TestingT, object any, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.Empty(t, object, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func Nil(t assert.TestingT, object any, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.Nil(t, object, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func NotNil(t assert.TestingT, object any, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.NotNil(t, object, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func NoError(t assert.TestingT, err error, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.NoError(t, err, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func Error(t assert.TestingT, err error, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.Error(t, err, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func EqualError(t assert.TestingT, theError error, errString string, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.EqualError(t, theError, errString, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func ErrorContains(t assert.TestingT, theError error, contains string, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.ErrorContains(t, theError, contains, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func ErrorIs(t assert.TestingT, theError, target error, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.ErrorIs(t, theError, target, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func True(t assert.TestingT, value bool, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.True(t, value, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func False(t assert.TestingT, value bool, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.False(t, value, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func Contains(t assert.TestingT, list any, element any, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.Contains(t, list, element, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func NotContains(t assert.TestingT, list any, element any, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.NotContains(t, list, element, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func ElementsMatch(t assert.TestingT, listA, listB any, msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.ElementsMatch(t, listA, listB, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func Panics(t assert.TestingT, f func(), msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.Panics(t, f, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func PanicsWithValue(t assert.TestingT, expected any, f func(), msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.PanicsWithValue(t, expected, f, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func PanicsWithError(t assert.TestingT, errString string, f func(), msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.PanicsWithError(t, errString, f, msgAndArgs...)
|
|
|
|
}
|
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func NotPanics(t assert.TestingT, f func(), msgAndArgs ...any) bool {
|
2024-03-25 11:01:09 +00:00
|
|
|
return assert.NotPanics(t, f, msgAndArgs...)
|
|
|
|
}
|
2024-10-29 15:32:33 +00:00
|
|
|
|
2024-12-05 15:37:24 +00:00
|
|
|
func JSONEq(t assert.TestingT, expected string, actual string, msgAndArgs ...any) bool {
|
2024-10-29 15:32:33 +00:00
|
|
|
return assert.JSONEq(t, expected, actual, msgAndArgs...)
|
|
|
|
}
|