2022-06-27 04:58:09 -04:00
|
|
|
|
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
"k8s.io/client-go/kubernetes/scheme"
|
|
|
|
"k8s.io/client-go/rest"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/envtest"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
|
|
|
|
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
|
|
|
|
|
|
|
updatev1alpha1 "github.com/edgelesssys/constellation/operators/constellation-node-operator/api/v1alpha1"
|
|
|
|
//+kubebuilder:scaffold:imports
|
|
|
|
)
|
|
|
|
|
|
|
|
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
|
|
|
|
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
|
|
|
|
|
2022-06-27 06:05:42 -04:00
|
|
|
var (
|
|
|
|
cfg *rest.Config
|
|
|
|
k8sClient client.Client
|
|
|
|
testEnv *envtest.Environment
|
|
|
|
)
|
2022-06-27 04:58:09 -04:00
|
|
|
|
|
|
|
func TestAPIs(t *testing.T) {
|
|
|
|
RegisterFailHandler(Fail)
|
|
|
|
|
|
|
|
RunSpecsWithDefaultAndCustomReporters(t,
|
|
|
|
"Controller Suite",
|
|
|
|
[]Reporter{printer.NewlineReporter{}})
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ = BeforeSuite(func() {
|
|
|
|
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
|
|
|
|
|
|
|
|
By("bootstrapping test environment")
|
|
|
|
testEnv = &envtest.Environment{
|
|
|
|
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
|
|
|
|
ErrorIfCRDPathMissing: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
// cfg is defined in this file globally.
|
|
|
|
cfg, err = testEnv.Start()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(cfg).NotTo(BeNil())
|
|
|
|
|
|
|
|
err = updatev1alpha1.AddToScheme(scheme.Scheme)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
//+kubebuilder:scaffold:scheme
|
|
|
|
|
|
|
|
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(k8sClient).NotTo(BeNil())
|
|
|
|
}, 60)
|
|
|
|
|
|
|
|
var _ = AfterSuite(func() {
|
|
|
|
By("tearing down the test environment")
|
|
|
|
err := testEnv.Stop()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
})
|