...

Source file src/k8s.io/kubernetes/test/e2e/framework/providers/gce/firewall_test.go

Documentation: k8s.io/kubernetes/test/e2e/framework/providers/gce

     1  //go:build !providerless
     2  // +build !providerless
     3  
     4  /*
     5  Copyright 2018 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  package gce
    21  
    22  import "testing"
    23  
    24  func TestIsPortsSubset(t *testing.T) {
    25  	tc := map[string]struct {
    26  		required  []string
    27  		coverage  []string
    28  		expectErr bool
    29  	}{
    30  		"Single port coverage": {
    31  			required: []string{"tcp/50"},
    32  			coverage: []string{"tcp/50", "tcp/60", "tcp/70"},
    33  		},
    34  		"Port range coverage": {
    35  			required: []string{"tcp/50"},
    36  			coverage: []string{"tcp/20-30", "tcp/45-60"},
    37  		},
    38  		"Multiple Port range coverage": {
    39  			required: []string{"tcp/50", "tcp/29", "tcp/46"},
    40  			coverage: []string{"tcp/20-30", "tcp/45-60"},
    41  		},
    42  		"Not covered": {
    43  			required:  []string{"tcp/50"},
    44  			coverage:  []string{"udp/50", "tcp/49", "tcp/51-60"},
    45  			expectErr: true,
    46  		},
    47  	}
    48  
    49  	for name, c := range tc {
    50  		t.Run(name, func(t *testing.T) {
    51  			gotErr := isPortsSubset(c.required, c.coverage)
    52  			if c.expectErr != (gotErr != nil) {
    53  				t.Errorf("isPortsSubset(%v, %v) = %v, wanted err? %v", c.required, c.coverage, gotErr, c.expectErr)
    54  			}
    55  		})
    56  	}
    57  }
    58  

View as plain text