|
| 1 | +/* |
| 2 | +Copyright 2023 The Kubernetes 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 oci |
| 18 | + |
| 19 | +import ( |
| 20 | + "path/filepath" |
| 21 | + "testing" |
| 22 | + "time" |
| 23 | + |
| 24 | + "github.com/SovereignCloudStack/cluster-stack-operator/internal/controller" |
| 25 | + "github.com/SovereignCloudStack/cluster-stack-operator/internal/test/helpers" |
| 26 | + ociclient "github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient/oci" |
| 27 | + "github.com/SovereignCloudStack/cluster-stack-operator/pkg/kube" |
| 28 | + fakekube "github.com/SovereignCloudStack/cluster-stack-operator/pkg/kube/fake" |
| 29 | + fakeworkloadcluster "github.com/SovereignCloudStack/cluster-stack-operator/pkg/workloadcluster/fake" |
| 30 | + . "github.com/onsi/ginkgo/v2" |
| 31 | + . "github.com/onsi/gomega" |
| 32 | + ctrl "sigs.k8s.io/controller-runtime" |
| 33 | + controllerruntimecontroller "sigs.k8s.io/controller-runtime/pkg/controller" |
| 34 | +) |
| 35 | + |
| 36 | +const ( |
| 37 | + timeout = time.Second * 10 |
| 38 | + interval = 1000 * time.Millisecond |
| 39 | + releaseDir = "/tmp/downloads" |
| 40 | +) |
| 41 | + |
| 42 | +func TestControllers(t *testing.T) { |
| 43 | + RegisterFailHandler(Fail) |
| 44 | + RunSpecs(t, "Controller Suite") |
| 45 | +} |
| 46 | + |
| 47 | +var ( |
| 48 | + ctx = ctrl.SetupSignalHandler() |
| 49 | + testEnv *helpers.TestEnvironment |
| 50 | +) |
| 51 | + |
| 52 | +var _ = BeforeSuite(func() { |
| 53 | + testEnv = helpers.NewTestEnvironment() |
| 54 | + |
| 55 | + Expect((&controller.ClusterStackReconciler{ |
| 56 | + Client: testEnv.Manager.GetClient(), |
| 57 | + AssetsClientFactory: ociclient.NewFactory(), |
| 58 | + ReleaseDirectory: releaseDir, |
| 59 | + }).SetupWithManager(ctx, testEnv.Manager, controllerruntimecontroller.Options{})).To(Succeed()) |
| 60 | + |
| 61 | + Expect((&controller.ClusterStackReleaseReconciler{ |
| 62 | + Client: testEnv.Manager.GetClient(), |
| 63 | + RESTConfig: testEnv.Manager.GetConfig(), |
| 64 | + KubeClientFactory: kube.NewFactory(), |
| 65 | + AssetsClientFactory: ociclient.NewFactory(), |
| 66 | + ReleaseDirectory: releaseDir, |
| 67 | + }).SetupWithManager(ctx, testEnv.Manager, controllerruntimecontroller.Options{})).To(Succeed()) |
| 68 | + |
| 69 | + Expect((&controller.ClusterAddonCreateReconciler{ |
| 70 | + Client: testEnv.Manager.GetClient(), |
| 71 | + }).SetupWithManager(ctx, testEnv.Manager, controllerruntimecontroller.Options{})).To(Succeed()) |
| 72 | + |
| 73 | + Expect((&controller.ClusterAddonReconciler{ |
| 74 | + Client: testEnv.Manager.GetClient(), |
| 75 | + KubeClientFactory: fakekube.NewFactory(), |
| 76 | + ReleaseDirectory: filepath.Join(releaseDir, "cluster-stacks"), |
| 77 | + WorkloadClusterFactory: fakeworkloadcluster.NewFactory(), |
| 78 | + }).SetupWithManager(ctx, testEnv.Manager, controllerruntimecontroller.Options{})).To(Succeed()) |
| 79 | + |
| 80 | + go func() { |
| 81 | + defer GinkgoRecover() |
| 82 | + Expect(testEnv.StartManager(ctx)).To(Succeed()) |
| 83 | + }() |
| 84 | + |
| 85 | + <-testEnv.Manager.Elected() |
| 86 | + |
| 87 | + // wait for webhook port to be open prior to running tests |
| 88 | + testEnv.WaitForWebhooks() |
| 89 | +}) |
| 90 | + |
| 91 | +var _ = AfterSuite(func() { |
| 92 | + Expect(testEnv.Stop()).To(Succeed()) |
| 93 | +}) |
0 commit comments