add assert tests
Some checks failed
continuous-integration/drone/push Build was killed
continuous-integration/drone/tag Build was killed

This commit is contained in:
2024-01-25 22:30:15 +03:00
parent b7736b7d4c
commit 66c1eef44a
3 changed files with 49 additions and 4 deletions

30
test/assert/equal.go Normal file
View File

@@ -0,0 +1,30 @@
package assert
import (
"reflect"
"testing"
)
func Equal(t *testing.T, expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
t.Helper()
if reflect.DeepEqual(expected, actual) {
return true
}
t.Error(msgAndArgs...)
return false
}
func Equalf(t *testing.T, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
t.Helper()
if reflect.DeepEqual(expected, actual) {
return true
}
t.Errorf(msg, args...)
return false
}

15
test/assert/nil.go Normal file
View File

@@ -0,0 +1,15 @@
package assert
import "testing"
func Nil(t *testing.T, data any, msgAndArgs ...interface{}) bool {
t.Helper()
if data != nil {
t.Error(msgAndArgs...)
return false
}
return true
}

View File

@@ -1,25 +1,25 @@
package require
import (
"reflect"
"testing"
"gitoa.ru/go-4devs/config/test/assert"
)
func Equal(t *testing.T, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
t.Helper()
if reflect.DeepEqual(expected, actual) {
if assert.Equal(t, expected, actual, msgAndArgs...) {
return
}
t.Error(msgAndArgs...)
t.FailNow()
}
func Equalf(t *testing.T, expected interface{}, actual interface{}, msg string, args ...interface{}) {
t.Helper()
if reflect.DeepEqual(expected, actual) {
if assert.Equalf(t, expected, actual, msg, args...) {
return
}