...

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