go.ligato.io/vpp-agent/v3@v3.5.0/proto/ligato/vpp/stn/models_test.go (about)

     1  //  Copyright (c) 2018 Cisco and/or its affiliates.
     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  package vpp_stn_test
    16  
    17  /*func TestSTNKey(t *testing.T) {
    18  	tests := []struct {
    19  		name         string
    20  		stnInterface string
    21  		stnIP        string
    22  		expectedKey  string
    23  	}{
    24  		{
    25  			name:         "valid STN case",
    26  			stnInterface: "if1",
    27  			stnIP:        "10.0.0.1",
    28  			expectedKey:  "vpp/config/v2/stn/rule/if1/ip/10.0.0.1",
    29  		},
    30  		{
    31  			name:         "invalid STN case (undefined interface)",
    32  			stnInterface: "",
    33  			stnIP:        "10.0.0.1",
    34  			expectedKey:  "vpp/config/v2/stn/rule/<invalid>/ip/10.0.0.1",
    35  		},
    36  		{
    37  			name:         "invalid STN case (undefined address)",
    38  			stnInterface: "if1",
    39  			stnIP:        "",
    40  			expectedKey:  "vpp/config/v2/stn/rule/if1/ip/<invalid>",
    41  		},
    42  		{
    43  			name:         "invalid STN case (IP address with mask provided)",
    44  			stnInterface: "if1",
    45  			stnIP:        "10.0.0.1/24",
    46  			expectedKey:  "vpp/config/v2/stn/rule/if1/ip/<invalid>",
    47  		},
    48  	}
    49  	for _, test := range tests {
    50  		t.Run(test.name, func(t *testing.T) {
    51  			key := stn.Key(test.stnInterface, test.stnIP)
    52  			if key != test.expectedKey {
    53  				t.Errorf("failed for: stnName=%s\n"+
    54  					"expected key:\n\t%q\ngot key:\n\t%q",
    55  					test.name, test.expectedKey, key)
    56  			}
    57  		})
    58  	}
    59  }*/
    60  
    61  /*func TestParseSTNKey(t *testing.T) {
    62  	tests := []struct {
    63  		name             string
    64  		key              string
    65  		expectedIfName   string
    66  		expectedIP       string
    67  		expectedIsSTNKey bool
    68  	}{
    69  		{
    70  			name:             "valid STN key",
    71  			key:              "vpp/config/v2/stn/rule/if1/ip/10.0.0.1",
    72  			expectedIfName:   "if1",
    73  			expectedIP:       "10.0.0.1",
    74  			expectedIsSTNKey: true,
    75  		},
    76  		{
    77  			name:             "invalid if",
    78  			key:              "vpp/config/v2/stn/rule/<invalid>/ip/10.0.0.1",
    79  			expectedIfName:   "<invalid>",
    80  			expectedIP:       "10.0.0.1",
    81  			expectedIsSTNKey: true,
    82  		},
    83  		{
    84  			name:             "invalid STN",
    85  			key:              "vpp/config/v2/stn/rule/if1/ip/<invalid>",
    86  			expectedIfName:   "if1",
    87  			expectedIP:       "<invalid>",
    88  			expectedIsSTNKey: true,
    89  		},
    90  		{
    91  			name:             "invalid all",
    92  			key:              "vpp/config/v2/stn/rule/<invalid>/ip/<invalid>",
    93  			expectedIfName:   "<invalid>",
    94  			expectedIP:       "<invalid>",
    95  			expectedIsSTNKey: true,
    96  		},
    97  		{
    98  			name:             "not STN key",
    99  			key:              "vpp/config/v2/bd/bd1",
   100  			expectedIfName:   "",
   101  			expectedIP:       "",
   102  			expectedIsSTNKey: false,
   103  		},
   104  	}
   105  	for _, test := range tests {
   106  		t.Run(test.name, func(t *testing.T) {
   107  			ifName, ip, isSTNKey := stn.ParseKey(test.key)
   108  			if isSTNKey != test.expectedIsSTNKey {
   109  				t.Errorf("expected isFIBKey: %v\tgot: %v", test.expectedIsSTNKey, isSTNKey)
   110  			}
   111  			if ifName != test.expectedIfName {
   112  				t.Errorf("expected ifName: %s\tgot: %s", test.expectedIfName, ifName)
   113  			}
   114  			if ip != test.expectedIP {
   115  				t.Errorf("expected IP: %s\tgot: %s", test.expectedIP, ip)
   116  			}
   117  		})
   118  	}
   119  }*/