2 * Copyright 2020 Intel Corporation, Inc
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 func TestIsValidNetworkChain(t *testing.T) {
24 t.Run("Valid Chains", func(t *testing.T) {
25 validchains := []string{
26 "app=abc,net1,app=xyz",
27 "app=abc, net1, app=xyz",
28 " app=abc , net1 , app=xyz ",
29 "app.kubernets.io/name=abc,net1,app.kubernets.io/name=xyz",
30 "app.kubernets.io/name=abc,net1,app.kubernets.io/name=xyz, net2, anotherlabel=wex",
32 for _, chain := range validchains {
33 err := validateNetworkChain(chain)
35 t.Errorf("Valid network chain failed to pass: %v %v", chain, err)
40 t.Run("Invalid Chains", func(t *testing.T) {
41 invalidchains := []string{
43 "app=abc,net1,app= xyz",
46 "app.kubernets.io/name=abc,net1,=xyz",
49 for _, chain := range invalidchains {
50 err := validateNetworkChain(chain)
52 t.Errorf("Invalid network chain passed: %v", chain)