github.com/kubevela/workflow@v0.6.0/e2e/e2e_suite_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 e2e
    18  
    19  import (
    20  	"context"
    21  	"os"
    22  	"path/filepath"
    23  	"strings"
    24  	"testing"
    25  
    26  	. "github.com/onsi/ginkgo"
    27  	. "github.com/onsi/gomega"
    28  	"k8s.io/apimachinery/pkg/runtime"
    29  	utilruntime "k8s.io/apimachinery/pkg/util/runtime"
    30  	clientgoscheme "k8s.io/client-go/kubernetes/scheme"
    31  	"sigs.k8s.io/controller-runtime/pkg/client"
    32  	"sigs.k8s.io/controller-runtime/pkg/client/config"
    33  
    34  	"github.com/kubevela/pkg/util/test/definition"
    35  
    36  	"github.com/kubevela/workflow/api/v1alpha1"
    37  	"github.com/kubevela/workflow/pkg/utils"
    38  )
    39  
    40  var (
    41  	scheme = runtime.NewScheme()
    42  )
    43  
    44  func init() {
    45  	utilruntime.Must(clientgoscheme.AddToScheme(scheme))
    46  
    47  	utilruntime.Must(v1alpha1.AddToScheme(scheme))
    48  	//+kubebuilder:scaffold:scheme
    49  }
    50  
    51  func TestE2e(t *testing.T) {
    52  	RegisterFailHandler(Fail)
    53  	RunSpecs(t, "E2e Suite")
    54  }
    55  
    56  var k8sClient client.Client
    57  
    58  var _ = BeforeSuite(func() {
    59  	conf, err := config.GetConfig()
    60  	Expect(err).Should(BeNil())
    61  
    62  	k8sClient, err = client.New(conf, client.Options{Scheme: scheme})
    63  	Expect(err).Should(BeNil())
    64  
    65  	prepareWorkflowDefinitions()
    66  })
    67  
    68  func prepareWorkflowDefinitions() {
    69  	var files []string
    70  	err := filepath.Walk("./test-data/definitions/", func(path string, info os.FileInfo, err error) error {
    71  		if strings.HasSuffix(path, "yaml") {
    72  			files = append(files, path)
    73  		}
    74  		return nil
    75  	})
    76  	Expect(err).Should(BeNil())
    77  	for _, f := range files {
    78  		Expect(definition.InstallDefinitionFromYAML(context.TODO(), k8sClient, f, nil)).Should(SatisfyAny(BeNil(), &utils.AlreadyExistMatcher{}))
    79  	}
    80  }