github.com/oam-dev/kubevela@v1.9.11/test/e2e-test/config_workflow_test.go (about)

     1  /*
     2  Copyright 2022 The KubeVela Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package controllers_test
    18  
    19  import (
    20  	"context"
    21  	"time"
    22  
    23  	. "github.com/onsi/ginkgo/v2"
    24  	. "github.com/onsi/gomega"
    25  	corev1 "k8s.io/api/core/v1"
    26  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    27  	"k8s.io/klog/v2"
    28  	"sigs.k8s.io/controller-runtime/pkg/client"
    29  	"sigs.k8s.io/yaml"
    30  
    31  	"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
    32  	"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
    33  	"github.com/oam-dev/kubevela/pkg/oam/util"
    34  )
    35  
    36  var _ = Describe("Test application of the specified definition version", func() {
    37  	ctx := context.Background()
    38  
    39  	var namespace string
    40  	var ns corev1.Namespace
    41  
    42  	BeforeEach(func() {
    43  		namespace = randomNamespaceName("config-e2e-test")
    44  		ns = corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
    45  
    46  		Eventually(func() error {
    47  			return k8sClient.Create(ctx, &ns)
    48  		}, time.Second*3, time.Microsecond*300).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
    49  	})
    50  
    51  	It("Test the workflow", func() {
    52  		var app v1beta1.Application
    53  		Expect(yaml.Unmarshal([]byte(manageConfigApplication), &app)).Should(BeNil())
    54  		app.Namespace = namespace
    55  		Expect(k8sClient.Create(context.TODO(), &app)).Should(BeNil())
    56  		Eventually(
    57  			func() common.ApplicationPhase {
    58  				var getAPP v1beta1.Application
    59  				if err := k8sClient.Get(ctx, client.ObjectKey{Namespace: namespace, Name: app.Name}, &getAPP); err != nil {
    60  					klog.Errorf("fail to query the app %s", err.Error())
    61  				}
    62  				klog.Infof("the application status is %s (%+v)", getAPP.Status.Phase, getAPP.Status.Workflow)
    63  				return getAPP.Status.Phase
    64  			},
    65  			time.Second*30, time.Second*2).Should(Equal(common.ApplicationRunning))
    66  	})
    67  
    68  	AfterEach(func() {
    69  		By("Clean up resources after a test")
    70  		k8sClient.DeleteAllOf(ctx, &v1beta1.Application{}, client.InNamespace(namespace))
    71  	})
    72  })
    73  
    74  var manageConfigApplication = `
    75  kind: Application
    76  apiVersion: core.oam.dev/v1beta1
    77  metadata:
    78    name: test-config
    79    namespace: "config-e2e-test"
    80  spec:
    81    components: []
    82    workflow:
    83      steps:
    84      - name: write-config
    85        type: create-config
    86        properties:
    87          name: test
    88          config: 
    89            key1: value1
    90            key2: 2
    91            key3: true
    92            key4: 
    93              key5: value5
    94      - name: read-config
    95        type: read-config
    96        properties:
    97          name: test
    98        outputs:
    99        - fromKey: config
   100          name: read-config
   101      - name: delete-config
   102        type: delete-config
   103        properties:
   104          name: test
   105  `