mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-05-25 10:32:59 +00:00
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package integration
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/onsi/ginkgo"
|
|
"github.com/onsi/gomega"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
"k8s.io/client-go/rest"
|
|
"sigs.k8s.io/controller-runtime/pkg/envtest"
|
|
|
|
clusterv1client "github.com/open-cluster-management/api/client/cluster/clientset/versioned"
|
|
)
|
|
|
|
const (
|
|
eventuallyTimeout = 30 // seconds
|
|
eventuallyInterval = 1 // seconds
|
|
)
|
|
|
|
var testEnv *envtest.Environment
|
|
var restConfig *rest.Config
|
|
var kubeClient kubernetes.Interface
|
|
var clusterClient clusterv1client.Interface
|
|
|
|
func TestIntegration(t *testing.T) {
|
|
gomega.RegisterFailHandler(ginkgo.Fail)
|
|
ginkgo.RunSpecs(t, "Integration Suite")
|
|
}
|
|
|
|
var _ = ginkgo.BeforeSuite(func(done ginkgo.Done) {
|
|
ginkgo.By("bootstrapping test environment")
|
|
|
|
// start a kube-apiserver
|
|
testEnv = &envtest.Environment{
|
|
ErrorIfCRDPathMissing: true,
|
|
CRDDirectoryPaths: []string{
|
|
filepath.Join(".", "vendor", "github.com", "open-cluster-management", "api", "cluster", "v1"),
|
|
filepath.Join(".", "vendor", "github.com", "open-cluster-management", "api", "cluster", "v1alpha1"),
|
|
},
|
|
}
|
|
|
|
cfg, err := testEnv.Start()
|
|
gomega.Expect(err).ToNot(gomega.HaveOccurred())
|
|
gomega.Expect(cfg).ToNot(gomega.BeNil())
|
|
|
|
kubeClient, err = kubernetes.NewForConfig(cfg)
|
|
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
|
clusterClient, err = clusterv1client.NewForConfig(cfg)
|
|
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
|
|
|
restConfig = cfg
|
|
close(done)
|
|
}, 60)
|
|
|
|
var _ = ginkgo.AfterSuite(func() {
|
|
ginkgo.By("tearing down the test environment")
|
|
|
|
err := testEnv.Stop()
|
|
gomega.Expect(err).ToNot(gomega.HaveOccurred())
|
|
})
|