libnetwork: refactor TestErrorInterfaces into a test
This function was added in libnetwork through50964c9948
and, based on the name of the function and its signature, I think it was meant to be a test. This patch refactors it to be one. Changing it into a test made it slightly broken: go test -v -run TestErrorInterfaces === RUN TestErrorInterfaces errors_test.go:15: Failed to detect err network not found is of type BadRequestError. Got type: libnetwork.ErrNoSuchNetwork errors_test.go:15: Failed to detect err endpoint not found is of type BadRequestError. Got type: libnetwork.ErrNoSuchEndpoint errors_test.go:42: Failed to detect err unknown driver "" is of type ForbiddenError. Got type: libnetwork.NetworkTypeError errors_test.go:42: Failed to detect err unknown network id is of type ForbiddenError. Got type: *libnetwork.UnknownNetworkError errors_test.go:42: Failed to detect err unknown endpoint id is of type ForbiddenError. Got type: *libnetwork.UnknownEndpointError --- FAIL: TestErrorInterfaces (0.00s) FAIL This was because some errors were tested twice, but for the wrong type (`NetworkTypeError`, `UnknownNetworkError`, `UnknownEndpointError`). Moving them to the right test left no test-cases for `types.ForbiddenError`, so I added `ActiveContainerError` to not make that part of the code feel lonely. Other failures were because some errors were changed from `types.BadRequestError` to a `types.NotFoundError` error in commitba012a703a
, so I moved those to the right part. Before this patch: go test -v -run TestErrorInterfaces === RUN TestErrorInterfaces --- PASS: TestErrorInterfaces (0.00s) PASS ok github.com/docker/docker/libnetwork 0.013s After this patch: go test -v -run TestErrorInterfaces === RUN TestErrorInterfaces --- PASS: TestErrorInterfaces (0.00s) PASS ok github.com/docker/docker/libnetwork 0.013s Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
454b6a7cf5
commit
be8ff186d6
1 changed files with 7 additions and 11 deletions
|
@ -7,13 +7,12 @@ import (
|
|||
)
|
||||
|
||||
func TestErrorInterfaces(t *testing.T) {
|
||||
badRequestErrorList := []error{ErrInvalidID(""), ErrInvalidName(""), ErrInvalidJoin{}, ErrInvalidNetworkDriver(""), InvalidContainerIDError(""), ErrNoSuchNetwork(""), ErrNoSuchEndpoint("")}
|
||||
badRequestErrorList := []error{ErrInvalidID(""), ErrInvalidName(""), ErrInvalidJoin{}, ErrInvalidNetworkDriver(""), InvalidContainerIDError("")}
|
||||
for _, err := range badRequestErrorList {
|
||||
switch u := err.(type) {
|
||||
case types.BadRequestError:
|
||||
return
|
||||
default:
|
||||
t.Fatalf("Failed to detect err %v is of type BadRequestError. Got type: %T", err, u)
|
||||
t.Errorf("Failed to detect err %v is of type BadRequestError. Got type: %T", err, u)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,29 +20,26 @@ func TestErrorInterfaces(t *testing.T) {
|
|||
for _, err := range maskableErrorList {
|
||||
switch u := err.(type) {
|
||||
case types.MaskableError:
|
||||
return
|
||||
default:
|
||||
t.Fatalf("Failed to detect err %v is of type MaskableError. Got type: %T", err, u)
|
||||
t.Errorf("Failed to detect err %v is of type MaskableError. Got type: %T", err, u)
|
||||
}
|
||||
}
|
||||
|
||||
notFoundErrorList := []error{NetworkTypeError(""), &UnknownNetworkError{}, &UnknownEndpointError{}}
|
||||
notFoundErrorList := []error{NetworkTypeError(""), &UnknownNetworkError{}, &UnknownEndpointError{}, ErrNoSuchNetwork(""), ErrNoSuchEndpoint("")}
|
||||
for _, err := range notFoundErrorList {
|
||||
switch u := err.(type) {
|
||||
case types.NotFoundError:
|
||||
return
|
||||
default:
|
||||
t.Fatalf("Failed to detect err %v is of type NotFoundError. Got type: %T", err, u)
|
||||
t.Errorf("Failed to detect err %v is of type NotFoundError. Got type: %T", err, u)
|
||||
}
|
||||
}
|
||||
|
||||
forbiddenErrorList := []error{NetworkTypeError(""), &UnknownNetworkError{}, &UnknownEndpointError{}}
|
||||
forbiddenErrorList := []error{&ActiveContainerError{}}
|
||||
for _, err := range forbiddenErrorList {
|
||||
switch u := err.(type) {
|
||||
case types.ForbiddenError:
|
||||
return
|
||||
default:
|
||||
t.Fatalf("Failed to detect err %v is of type ForbiddenError. Got type: %T", err, u)
|
||||
t.Errorf("Failed to detect err %v is of type ForbiddenError. Got type: %T", err, u)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue