|
| 1 | +package scope |
| 2 | + |
| 3 | +import ( |
| 4 | + // "os" |
| 5 | + "path/filepath" |
| 6 | + "testing" |
| 7 | + |
| 8 | + . "github.com/onsi/ginkgo/v2" |
| 9 | + . "github.com/onsi/gomega" |
| 10 | + |
| 11 | + "k8s.io/client-go/kubernetes/scheme" |
| 12 | + "k8s.io/client-go/rest" |
| 13 | + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" |
| 14 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 15 | + "sigs.k8s.io/controller-runtime/pkg/envtest" |
| 16 | + logf "sigs.k8s.io/controller-runtime/pkg/log" |
| 17 | + "sigs.k8s.io/controller-runtime/pkg/log/zap" |
| 18 | + |
| 19 | + infrav1 "github.com/sp-yduck/cluster-api-provider-proxmox/api/v1beta1" |
| 20 | +) |
| 21 | + |
| 22 | +var ( |
| 23 | + cfg *rest.Config |
| 24 | + k8sClient client.Client |
| 25 | + testEnv *envtest.Environment |
| 26 | + proxmoxUser string |
| 27 | + proxmoxPassword string |
| 28 | +) |
| 29 | + |
| 30 | +func TestScopes(t *testing.T) { |
| 31 | + RegisterFailHandler(Fail) |
| 32 | + RunSpecs(t, "Scope Suite") |
| 33 | +} |
| 34 | + |
| 35 | +var _ = BeforeSuite(func() { |
| 36 | + logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) |
| 37 | + |
| 38 | + By("bootstrapping test environment") |
| 39 | + testEnv = &envtest.Environment{ |
| 40 | + CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, |
| 41 | + ErrorIfCRDPathMissing: true, |
| 42 | + } |
| 43 | + |
| 44 | + var err error |
| 45 | + // cfg is defined in this file globally. |
| 46 | + cfg, err = testEnv.Start() |
| 47 | + Expect(err).NotTo(HaveOccurred()) |
| 48 | + Expect(cfg).NotTo(BeNil()) |
| 49 | + |
| 50 | + Expect(clusterv1.AddToScheme(scheme.Scheme)).To(Succeed()) |
| 51 | + Expect(infrav1.AddToScheme(scheme.Scheme)).To(Succeed()) |
| 52 | + |
| 53 | + //+kubebuilder:scaffold:scheme |
| 54 | + |
| 55 | + k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) |
| 56 | + Expect(err).NotTo(HaveOccurred()) |
| 57 | + Expect(k8sClient).NotTo(BeNil()) |
| 58 | +}) |
| 59 | + |
| 60 | +var _ = AfterSuite(func() { |
| 61 | + By("tearing down the test environment") |
| 62 | + err := testEnv.Stop() |
| 63 | + Expect(err).NotTo(HaveOccurred()) |
| 64 | +}) |
0 commit comments