istio.io/istio@v0.0.0-20240520182934-d79c90f27776/tools/istio-iptables/pkg/dependencies/implementation_test.go (about)

     1  // Copyright Istio Authors
     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 dependencies
    16  
    17  import (
    18  	"testing"
    19  
    20  	utilversion "k8s.io/apimachinery/pkg/util/version"
    21  
    22  	"istio.io/istio/pkg/test/util/assert"
    23  )
    24  
    25  func TestOverrideVersionIsCorrectlyParsed(t *testing.T) {
    26  	cases := []struct {
    27  		name string
    28  		ver  string
    29  		want *utilversion.Version
    30  	}{
    31  		{
    32  			name: "jammy nft",
    33  			ver:  "iptables v1.8.7 (nf_tables)",
    34  			want: utilversion.MustParseGeneric("1.8.7"),
    35  		},
    36  		{
    37  			name: "jammy legacy",
    38  			ver:  "iptables v1.8.7 (legacy)",
    39  
    40  			want: utilversion.MustParseGeneric("1.8.7"),
    41  		},
    42  		{
    43  			name: "xenial",
    44  			ver:  "iptables v1.6.0",
    45  
    46  			want: utilversion.MustParseGeneric("1.6.0"),
    47  		},
    48  		{
    49  			name: "bionic",
    50  			ver:  "iptables v1.6.1",
    51  
    52  			want: utilversion.MustParseGeneric("1.6.1"),
    53  		},
    54  		{
    55  			name: "centos 7",
    56  			ver:  "iptables v1.4.21",
    57  
    58  			want: utilversion.MustParseGeneric("1.4.21"),
    59  		},
    60  		{
    61  			name: "centos 8",
    62  			ver:  "iptables v1.8.4 (nf_tables)",
    63  
    64  			want: utilversion.MustParseGeneric("1.8.4"),
    65  		},
    66  		{
    67  			name: "alpine 3.18",
    68  			ver:  "iptables v1.8.9 (legacy)",
    69  
    70  			want: utilversion.MustParseGeneric("1.8.9"),
    71  		},
    72  	}
    73  	for _, tt := range cases {
    74  		t.Run(tt.name, func(t *testing.T) {
    75  			got, err := parseIptablesVer(tt.ver)
    76  			if err != nil {
    77  				t.Fatal(err)
    78  			}
    79  			assert.Equal(t, got.String(), tt.want.String())
    80  		})
    81  	}
    82  }