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