github.com/fafucoder/cilium@v1.6.11/pkg/endpointmanager/errors_test.go (about)

     1  // Copyright 2018 Authors of Cilium
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // +build !privileged_tests
    16  
    17  package endpointmanager
    18  
    19  import (
    20  	. "gopkg.in/check.v1"
    21  )
    22  
    23  func (s *EndpointManagerSuite) TestErrInvalidPrefix_Error(c *C) {
    24  	type args struct {
    25  		err ErrInvalidPrefix
    26  	}
    27  	type want struct {
    28  		errMsg      string
    29  		errMsgCheck Checker
    30  	}
    31  	tests := []struct {
    32  		name      string
    33  		setupArgs func() args
    34  		setupWant func() want
    35  	}{
    36  		{
    37  			name: "random Invalid Prefix",
    38  			setupArgs: func() args {
    39  				return args{
    40  					err: ErrInvalidPrefix{
    41  						InvalidPrefix: "foo",
    42  					},
    43  				}
    44  			},
    45  			setupWant: func() want {
    46  				return want{
    47  					errMsg:      "unknown endpoint prefix 'foo'",
    48  					errMsgCheck: Equals,
    49  				}
    50  			},
    51  		},
    52  	}
    53  	for _, tt := range tests {
    54  		args := tt.setupArgs()
    55  		want := tt.setupWant()
    56  		errMsg := args.err.Error()
    57  		c.Assert(errMsg, want.errMsgCheck, want.errMsg, Commentf("Test Name: %s", tt.name))
    58  	}
    59  }
    60  
    61  func (s *EndpointManagerSuite) TestIsErrUnsupportedID(c *C) {
    62  	type args struct {
    63  		err error
    64  	}
    65  	type want struct {
    66  		bool      bool
    67  		boolCheck Checker
    68  	}
    69  	tests := []struct {
    70  		name      string
    71  		setupArgs func() args
    72  		setupWant func() want
    73  	}{
    74  		{
    75  			name: "is not invalid prefix error",
    76  			setupArgs: func() args {
    77  				return args{
    78  					err: ErrUnsupportedID,
    79  				}
    80  			},
    81  			setupWant: func() want {
    82  				return want{
    83  					bool:      false,
    84  					boolCheck: Equals,
    85  				}
    86  			},
    87  		},
    88  		{
    89  			name: "is invalid prefix error",
    90  			setupArgs: func() args {
    91  				return args{
    92  					err: ErrInvalidPrefix{
    93  						InvalidPrefix: "foo",
    94  					},
    95  				}
    96  			},
    97  			setupWant: func() want {
    98  				return want{
    99  					bool:      true,
   100  					boolCheck: Equals,
   101  				}
   102  			},
   103  		},
   104  	}
   105  	for _, tt := range tests {
   106  		args := tt.setupArgs()
   107  		want := tt.setupWant()
   108  		errMsg := IsErrInvalidPrefix(args.err)
   109  		c.Assert(errMsg, want.boolCheck, want.bool, Commentf("Test Name: %s", tt.name))
   110  	}
   111  }
   112  
   113  func (s *EndpointManagerSuite) TestIsErrInvalidPrefix(c *C) {
   114  	type args struct {
   115  		err error
   116  	}
   117  	type want struct {
   118  		bool      bool
   119  		boolCheck Checker
   120  	}
   121  	tests := []struct {
   122  		name      string
   123  		setupArgs func() args
   124  		setupWant func() want
   125  	}{
   126  		{
   127  			name: "is not unsupported ID error",
   128  			setupArgs: func() args {
   129  				return args{
   130  					err: ErrInvalidPrefix{
   131  						InvalidPrefix: "foo",
   132  					},
   133  				}
   134  			},
   135  			setupWant: func() want {
   136  				return want{
   137  					bool:      false,
   138  					boolCheck: Equals,
   139  				}
   140  			},
   141  		},
   142  		{
   143  			name: "is unsupported ID error",
   144  			setupArgs: func() args {
   145  				return args{
   146  					err: ErrUnsupportedID,
   147  				}
   148  			},
   149  			setupWant: func() want {
   150  				return want{
   151  					bool:      true,
   152  					boolCheck: Equals,
   153  				}
   154  			},
   155  		},
   156  	}
   157  	for _, tt := range tests {
   158  		args := tt.setupArgs()
   159  		want := tt.setupWant()
   160  		errMsg := IsErrUnsupportedID(args.err)
   161  		c.Assert(errMsg, want.boolCheck, want.bool, Commentf("Test Name: %s", tt.name))
   162  	}
   163  }