...

Source file src/github.com/chaos-mesh/chaos-mesh/api/v1alpha1/awschaos_types_test.go

Documentation: github.com/chaos-mesh/chaos-mesh/api/v1alpha1

     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 v1alpha1
    17  
    18  import (
    19  	"context"
    20  
    21  	. "github.com/onsi/ginkgo/v2"
    22  	. "github.com/onsi/gomega"
    23  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    24  	"k8s.io/apimachinery/pkg/types"
    25  )
    26  
    27  // These tests are written in BDD-style using Ginkgo framework. Refer to
    28  // http://onsi.github.io/ginkgo to learn more.
    29  
    30  var _ = Describe("AWSChaos", func() {
    31  	var (
    32  		key              types.NamespacedName
    33  		created, fetched *AWSChaos
    34  	)
    35  
    36  	BeforeEach(func() {
    37  		// Add any setup steps that needs to be executed before each test
    38  	})
    39  
    40  	AfterEach(func() {
    41  		// Add any teardown steps that needs to be executed after each test
    42  	})
    43  
    44  	Context("Create API", func() {
    45  		It("should create an object successfully", func() {
    46  			testInstance := "testInstance"
    47  			testSecretName := "testSecretName"
    48  			key = types.NamespacedName{
    49  				Name:      "foo",
    50  				Namespace: "default",
    51  			}
    52  
    53  			created = &AWSChaos{
    54  				ObjectMeta: metav1.ObjectMeta{
    55  					Name:      "foo",
    56  					Namespace: "default",
    57  				},
    58  				Spec: AWSChaosSpec{
    59  					Action: Ec2Stop,
    60  					AWSSelector: AWSSelector{
    61  						Ec2Instance: testInstance,
    62  					},
    63  					SecretName: &testSecretName,
    64  				},
    65  			}
    66  
    67  			By("creating an API obj")
    68  			Expect(k8sClient.Create(context.TODO(), created)).To(Succeed())
    69  
    70  			fetched = &AWSChaos{}
    71  			Expect(k8sClient.Get(context.TODO(), key, fetched)).To(Succeed())
    72  			Expect(fetched).To(Equal(created))
    73  
    74  			By("deleting the created object")
    75  			Expect(k8sClient.Delete(context.TODO(), created)).To(Succeed())
    76  			Expect(k8sClient.Get(context.TODO(), key, created)).ToNot(Succeed())
    77  		})
    78  	})
    79  })
    80