...

Source file src/github.com/chaos-mesh/chaos-mesh/controllers/podnetworkchaos/ipset/ipset_test.go

Documentation: github.com/chaos-mesh/chaos-mesh/controllers/podnetworkchaos/ipset

     1  // Copyright 2021 Chaos Mesh 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  
    16  package ipset
    17  
    18  import (
    19  	"testing"
    20  
    21  	. "github.com/onsi/gomega"
    22  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    23  
    24  	"github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
    25  )
    26  
    27  func Test_generateIPSetName(t *testing.T) {
    28  	g := NewWithT(t)
    29  	postfix := "alongpostfix"
    30  
    31  	t.Run("name with postfix", func(t *testing.T) {
    32  		chaosName := "test"
    33  
    34  		networkChaos := &v1alpha1.NetworkChaos{
    35  			ObjectMeta: metav1.ObjectMeta{
    36  				Name: chaosName,
    37  			},
    38  		}
    39  
    40  		name := GenerateIPSetName(networkChaos, postfix)
    41  
    42  		g.Expect(name).Should(Equal(chaosName + "_" + postfix))
    43  	})
    44  
    45  	t.Run("length equal 27", func(t *testing.T) {
    46  		networkChaos := &v1alpha1.NetworkChaos{
    47  			ObjectMeta: metav1.ObjectMeta{
    48  				Name: "test-metav1object",
    49  			},
    50  		}
    51  
    52  		name := GenerateIPSetName(networkChaos, postfix)
    53  
    54  		g.Expect(len(name)).Should(Equal(27))
    55  	})
    56  }
    57