Refactor/internal testing (#194)
* added NoError check * corrected NoError * has error checks * replace more checks * Used checks test helper * Used checks test helper * remove duplicate import * fixed lint issues regarding length of messages --------- Co-authored-by: Rex Posadas <rposadas@redwoodlogistics.com>
This commit is contained in:
48
internal/test/checks/checks.go
Normal file
48
internal/test/checks/checks.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package checks
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func NoError(t *testing.T, err error, message ...string) {
|
||||
t.Helper()
|
||||
if err != nil {
|
||||
t.Error(err, message)
|
||||
}
|
||||
}
|
||||
|
||||
func HasError(t *testing.T, err error, message ...string) {
|
||||
t.Helper()
|
||||
if err == nil {
|
||||
t.Error(err, message)
|
||||
}
|
||||
}
|
||||
|
||||
func ErrorIs(t *testing.T, err, target error, msg ...string) {
|
||||
t.Helper()
|
||||
if !errors.Is(err, target) {
|
||||
t.Fatal(msg)
|
||||
}
|
||||
}
|
||||
|
||||
func ErrorIsF(t *testing.T, err, target error, format string, msg ...string) {
|
||||
t.Helper()
|
||||
if !errors.Is(err, target) {
|
||||
t.Fatalf(format, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func ErrorIsNot(t *testing.T, err, target error, msg ...string) {
|
||||
t.Helper()
|
||||
if errors.Is(err, target) {
|
||||
t.Fatal(msg)
|
||||
}
|
||||
}
|
||||
|
||||
func ErrorIsNotf(t *testing.T, err, target error, format string, msg ...string) {
|
||||
t.Helper()
|
||||
if errors.Is(err, target) {
|
||||
t.Fatalf(format, msg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user