github.com/toplink-cn/moby@v0.0.0-20240305205811-460b4aebdf81/libnetwork/errors_test.go (about)

     1  package libnetwork
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/docker/docker/libnetwork/types"
     7  )
     8  
     9  func TestErrorInterfaces(t *testing.T) {
    10  	badRequestErrorList := []error{ErrInvalidID(""), ErrInvalidName("")}
    11  	for _, err := range badRequestErrorList {
    12  		switch u := err.(type) {
    13  		case types.InvalidParameterError:
    14  		default:
    15  			t.Errorf("Failed to detect err %v is of type InvalidParameterError. Got type: %T", err, u)
    16  		}
    17  	}
    18  
    19  	maskableErrorList := []error{ManagerRedirectError("")}
    20  	for _, err := range maskableErrorList {
    21  		switch u := err.(type) {
    22  		case types.MaskableError:
    23  		default:
    24  			t.Errorf("Failed to detect err %v is of type MaskableError. Got type: %T", err, u)
    25  		}
    26  	}
    27  
    28  	notFoundErrorList := []error{&UnknownNetworkError{}, ErrNoSuchNetwork(""), ErrNoSuchEndpoint("")}
    29  	for _, err := range notFoundErrorList {
    30  		switch u := err.(type) {
    31  		case types.NotFoundError:
    32  		default:
    33  			t.Errorf("Failed to detect err %v is of type NotFoundError. Got type: %T", err, u)
    34  		}
    35  	}
    36  
    37  	forbiddenErrorList := []error{&ActiveContainerError{}}
    38  	for _, err := range forbiddenErrorList {
    39  		switch u := err.(type) {
    40  		case types.ForbiddenError:
    41  		default:
    42  			t.Errorf("Failed to detect err %v is of type ForbiddenError. Got type: %T", err, u)
    43  		}
    44  	}
    45  }