influxdb/testing/util.go

43 lines
1.2 KiB
Go
Raw Normal View History

package testing
import (
2018-11-07 18:55:52 +00:00
"testing"
"github.com/influxdata/platform"
)
2018-11-07 18:55:52 +00:00
func diffPlatformErrors(name string, actual, expected error, opPrefix string, t *testing.T) {
if expected == nil && actual == nil {
return
}
2018-11-07 18:55:52 +00:00
if expected == nil && actual != nil {
t.Fatalf("%s failed, unexpected error %s", name, actual.Error())
}
if expected != nil && actual == nil {
t.Errorf("%s failed, expected error %s but received nil", name, expected.Error())
2018-11-07 18:55:52 +00:00
}
if platform.ErrorCode(expected) != platform.ErrorCode(actual) {
t.Errorf("%s failed, expected error code %q but received %q", name, platform.ErrorCode(expected), platform.ErrorCode(actual))
2018-11-07 18:55:52 +00:00
}
if opPrefix+platform.ErrorOp(expected) != platform.ErrorOp(actual) {
t.Errorf("%s failed, expected error op %q but received %q", name, opPrefix+platform.ErrorOp(expected), platform.ErrorOp(actual))
2018-11-07 18:55:52 +00:00
}
if platform.ErrorMessage(expected) != platform.ErrorMessage(actual) {
t.Errorf("%s failed, expected error message %q but received %q", name, platform.ErrorMessage(expected), platform.ErrorMessage(actual))
}
2018-11-07 18:55:52 +00:00
}
// MustIDBase16 is an helper to ensure a correct ID is built during testing.
func MustIDBase16(s string) platform.ID {
id, err := platform.IDFromString(s)
if err != nil {
panic(err)
}
return *id
}