github.com/oam-dev/kubevela@v1.9.11/references/cli/defapply_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 cli
    18  
    19  import (
    20  	"bytes"
    21  	"context"
    22  	"os"
    23  
    24  	. "github.com/onsi/ginkgo/v2"
    25  	. "github.com/onsi/gomega"
    26  	"sigs.k8s.io/controller-runtime/pkg/client"
    27  
    28  	"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
    29  	"github.com/oam-dev/kubevela/apis/types"
    30  	"github.com/oam-dev/kubevela/pkg/utils/common"
    31  	"github.com/oam-dev/kubevela/pkg/utils/util"
    32  )
    33  
    34  var _ = Describe("Test def apply cli", func() {
    35  
    36  	When("test vela def apply", func() {
    37  
    38  		It("should not have err and applied all def files", func() {
    39  
    40  			buffer := bytes.NewBuffer(nil)
    41  			ioStreams := util.IOStreams{In: os.Stdin, Out: buffer, ErrOut: buffer}
    42  
    43  			ctx := context.Background()
    44  			c := common.Args{}
    45  			c.SetConfig(cfg)
    46  			c.SetClient(k8sClient)
    47  			err := defApplyAll(ctx, c, ioStreams, types.DefaultKubeVelaNS, "./test-data/defapply", false)
    48  			Expect(err).Should(BeNil())
    49  
    50  			By("check component definition in YAML exist")
    51  			cml := v1beta1.ComponentDefinition{}
    52  			Expect(k8sClient.Get(ctx, client.ObjectKey{Name: "testdefyaml", Namespace: types.DefaultKubeVelaNS}, &cml)).Should(BeNil())
    53  
    54  			By("check trait definition in CUE exist")
    55  			traitd := v1beta1.TraitDefinition{}
    56  			Expect(k8sClient.Get(ctx, client.ObjectKey{Name: "testdefcue", Namespace: types.DefaultKubeVelaNS}, &traitd)).Should(BeNil())
    57  
    58  		})
    59  	})
    60  })