...

Source file src/github.com/chaos-mesh/chaos-mesh/controllers/config/types_test.go

Documentation: github.com/chaos-mesh/chaos-mesh/controllers/config

     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 config
    17  
    18  import (
    19  	"testing"
    20  
    21  	. "github.com/onsi/ginkgo/v2"
    22  	. "github.com/onsi/gomega"
    23  
    24  	"github.com/chaos-mesh/chaos-mesh/pkg/config"
    25  )
    26  
    27  func TestValidations(t *testing.T) {
    28  	RegisterFailHandler(Fail)
    29  
    30  	RunSpecs(t, "Namespace scoped")
    31  }
    32  
    33  var _ = Describe("Namespace-scoped Chaos", func() {
    34  	Context("Namespace-scoped Chaos Configuration Validation", func() {
    35  		It("Validation", func() {
    36  			type TestCase struct {
    37  				name        string
    38  				config      config.ChaosControllerConfig
    39  				expectValid bool
    40  			}
    41  
    42  			testCases := []TestCase{
    43  				{
    44  					name: "target namespace should not be empty with namespaced scope",
    45  					config: config.ChaosControllerConfig{
    46  						ClusterScoped:   false,
    47  						TargetNamespace: "",
    48  					},
    49  					expectValid: false,
    50  				},
    51  			}
    52  
    53  			for _, testCase := range testCases {
    54  				By(testCase.name)
    55  				err := validate(&testCase.config)
    56  				if testCase.expectValid {
    57  					Expect(err).NotTo(HaveOccurred())
    58  				} else {
    59  					Expect(err).To(HaveOccurred())
    60  				}
    61  			}
    62  		})
    63  	})
    64  })
    65