fix(testing): compare expected error messages against actual (#1857)

* fix(testing): compare expected error messages against actual

* remove nonsense

* remove nonsense

* add expected error message for bucket not found

* oops
pull/10616/head
Jade McGough 2018-12-12 10:24:33 -08:00 committed by GitHub
parent 58ff2c4eec
commit 78d0fc2b17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 5 deletions

View File

@ -516,6 +516,7 @@ func (s *BucketService) FindBucket(ctx context.Context, filter platform.BucketFi
return nil, &platform.Error{
Code: platform.ENotFound,
Op: s.OpPrefix + platform.OpFindBucket,
Msg: "bucket not found",
Err: ErrNotFound,
}
}

View File

@ -149,7 +149,7 @@ func (s *Service) FindOrganizations(ctx context.Context, filter platform.Organiz
return orgs, 0, &platform.Error{
Code: platform.ENotFound,
Op: op,
Msg: OpPrefix + platform.OpFindOrganizations,
Msg: errOrganizationNotFound,
}
}

View File

@ -945,7 +945,7 @@ func FindBucket(
err: &platform.Error{
Code: platform.ENotFound,
Op: platform.OpFindBucket,
Msg: "no results found",
Msg: "bucket not found",
},
},
},

View File

@ -295,7 +295,7 @@ func FindOrganizationByID(
err: &platform.Error{
Code: platform.ENotFound,
Op: platform.OpFindOrganizationByID,
Msg: "",
Msg: "organization not found",
},
},
},

View File

@ -21,6 +21,10 @@ func diffErrors(actual, expected error, t *testing.T) {
}
func diffPlatformErrors(name string, actual, expected error, opPrefix string, t *testing.T) {
if expected == nil && actual == nil {
return
}
if expected == nil && actual != nil {
t.Fatalf("%s failed, unexpected error %s", name, actual.Error())
}
@ -29,13 +33,17 @@ func diffPlatformErrors(name string, actual, expected error, opPrefix string, t
t.Fatalf("%s failed, expected error %s but received nil", name, expected.Error())
}
if expected != nil && actual != nil && platform.ErrorCode(expected) != platform.ErrorCode(actual) {
if 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) {
if 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))
}
if platform.ErrorMessage(expected) != platform.ErrorMessage(actual) {
t.Fatalf("%s failed, expected error %q but received error message %q", name, platform.ErrorMessage(expected), platform.ErrorMessage(actual))
}
}
// MustIDBase16 is an helper to ensure a correct ID is built during testing.