...

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