registry/api/errorcode: TestErrorCodes: use sub-tests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-04-30 15:23:44 +02:00
parent 57f9f31af9
commit f884a079df
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -34,11 +34,14 @@ var ErrorCodeTest3 = Register("test.errors", ErrorDescriptor{
// TestErrorCodes ensures that error code format, mappings and
// marshaling/unmarshaling. round trips are stable.
func TestErrorCodes(t *testing.T) {
t.Parallel()
if len(errorCodeToDescriptors) == 0 {
t.Fatal("errors aren't loaded!")
}
for ec, desc := range errorCodeToDescriptors {
t.Run(ec.String(), func(t *testing.T) {
t.Parallel()
if ec != desc.Code {
t.Fatalf("error code in descriptor isn't correct, %q != %q", ec, desc.Code)
}
@ -48,7 +51,7 @@ func TestErrorCodes(t *testing.T) {
}
if ec.Message() != desc.Message {
t.Fatalf("ec.Message doesn't mtach desc.Message: %q != %q", ec.Message(), desc.Message)
t.Fatalf("ec.Message doesn't match desc.Message: %q != %q", ec.Message(), desc.Message)
}
// Test (de)serializing the ErrorCode
@ -85,6 +88,7 @@ func TestErrorCodes(t *testing.T) {
if ec.Error() != expectedErrorString {
t.Fatalf("unexpected return from %v.Error(): %q != %q", ec, ec.Error(), expectedErrorString)
}
})
}
}