...
1
2
3
4
5
6
7
8
9
10
11
12
13
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