...

Source file src/github.com/chaos-mesh/chaos-mesh/pkg/webhook/config/config_test.go

Documentation: github.com/chaos-mesh/chaos-mesh/pkg/webhook/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  	"github.com/ghodss/yaml"
    20  	. "github.com/onsi/ginkgo"
    21  	. "github.com/onsi/gomega"
    22  )
    23  
    24  var _ = Describe("webhook config", func() {
    25  	Context("Test webhook config", func() {
    26  		It("unmarshal TemplateArgs", func() {
    27  			template := `
    28  name: chaosfs-etcd
    29  selector:
    30    labelSelectors:
    31      app: etcd
    32  template: chaosfs-sidecar
    33  arguments:
    34    ContainerName: "etcd"
    35    DataPath: "/var/run/etcd/default.etcd"
    36    MountPath: "/var/run/etcd"
    37    VolumeName: "datadir"`
    38  
    39  			var cfg TemplateArgs
    40  			err := yaml.Unmarshal([]byte(template), &cfg)
    41  			Expect(err).To(BeNil())
    42  		})
    43  
    44  		It("unmarshal Injection Config", func() {
    45  			template := `
    46  initContainers:
    47  - name: inject-scripts
    48    image: pingcap/chaos-scripts:latest
    49    imagePullpolicy: Always
    50    command: ["sh", "-c", "/scripts/init.sh -d /var/lib/pd/data -f /var/lib/pd/fuse-data"]
    51  containers:
    52  - name: chaosfs
    53    image: pingcap/chaos-fs:latest
    54    imagePullpolicy: Always
    55    ports:
    56    - containerPort: 65534
    57    securityContext:
    58      privileged: true
    59    command:
    60      - /usr/local/bin/chaosfs
    61      - -addr=:65534
    62      - -pidfile=/tmp/fuse/pid
    63      - -original=/var/lib/pd/fuse-data
    64      - -mountpoint=/var/lib/pd/data
    65    volumeMounts:
    66    - name: pd
    67      mountPath: /var/lib/pd
    68      mountPropagation: Bidirectional
    69  volumeMounts:
    70  - name: pd
    71    mountPath: /var/lib/pd
    72    mountPropagation: HostToContainer
    73  - name: scripts
    74    mountPath: /tmp/scripts
    75  - name: fuse
    76    mountPath: /tmp/fuse
    77  volumes:
    78  - name: scripts
    79    emptyDir: {}
    80  - name: fuse
    81    emptyDir: {}
    82  postStart:
    83    pd:
    84      command:
    85        - /tmp/scripts/wait-fuse.sh
    86  `
    87  			var cfg InjectionConfig
    88  			err := yaml.Unmarshal([]byte(template), &cfg)
    89  			Expect(err).To(BeNil())
    90  		})
    91  
    92  		It("should return request on RequestAnnotationKey", func() {
    93  			var cfg Config
    94  			res := cfg.RequestAnnotationKey()
    95  			Expect(res).To(Equal("/request"))
    96  		})
    97  
    98  		It("should return status on StatusAnnotationKey", func() {
    99  			var cfg Config
   100  			res := cfg.StatusAnnotationKey()
   101  			Expect(res).To(Equal("/status"))
   102  		})
   103  
   104  		It("should return init-request on RequestInitAnnotationKey", func() {
   105  			var cfg Config
   106  			res := cfg.RequestInitAnnotationKey()
   107  			Expect(res).To(Equal("/init-request"))
   108  		})
   109  
   110  	})
   111  })
   112