-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,97 @@ | ||
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package infrastructure_test | ||
package infrastructure | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
"time" | ||
|
||
gardenerextensionv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1" | ||
machinescheme "github.com/gardener/machine-controller-manager/pkg/client/clientset/versioned/scheme" | ||
"github.com/ironcore-dev/controller-utils/modutils" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"go.uber.org/zap/zapcore" | ||
apiextensionsscheme "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/scheme" | ||
"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/komega" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
|
||
apiv1alpha1 "github.com/ironcore-dev/gardener-extension-provider-ironcore-metal/pkg/apis/metal/v1alpha1" | ||
) | ||
|
||
const ( | ||
pollingInterval = 50 * time.Millisecond | ||
eventuallyTimeout = 10 * time.Second | ||
consistentlyDuration = 1 * time.Second | ||
) | ||
|
||
func TestInfrastructure(t *testing.T) { | ||
SetDefaultConsistentlyPollingInterval(pollingInterval) | ||
SetDefaultEventuallyPollingInterval(pollingInterval) | ||
SetDefaultEventuallyTimeout(eventuallyTimeout) | ||
SetDefaultConsistentlyDuration(consistentlyDuration) | ||
|
||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Infrastructure Suite") | ||
} | ||
|
||
var ( | ||
testEnv *envtest.Environment | ||
cfg *rest.Config | ||
k8sClient client.Client | ||
) | ||
|
||
var _ = BeforeSuite(func() { | ||
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true), zap.Level(zapcore.InfoLevel))) | ||
|
||
By("bootstrapping test environment") | ||
testEnv = &envtest.Environment{ | ||
CRDDirectoryPaths: []string{ | ||
modutils.Dir("github.com/gardener/machine-controller-manager", "kubernetes", "crds", "machine.sapcloud.io_machineclasses.yaml"), | ||
modutils.Dir("github.com/gardener/machine-controller-manager", "kubernetes", "crds", "machine.sapcloud.io_machinedeployments.yaml"), | ||
modutils.Dir("github.com/gardener/machine-controller-manager", "kubernetes", "crds", "machine.sapcloud.io_machines.yaml"), | ||
modutils.Dir("github.com/gardener/machine-controller-manager", "kubernetes", "crds", "machine.sapcloud.io_machinesets.yaml"), | ||
filepath.Join("..", "..", "..", "example", "20-crd-extensions.gardener.cloud_infrastructures.yaml"), | ||
}, | ||
ErrorIfCRDPathMissing: true, | ||
|
||
// The BinaryAssetsDirectory is only required if you want to run the tests directly | ||
// without call the makefile target test. If not informed it will look for the | ||
// default path defined in controller-apiruntime which is /usr/local/kubebuilder/. | ||
// Note that you must have the required binaries setup under the bin directory to perform | ||
// the tests directly. When we run make test it will be setup and used automatically. | ||
BinaryAssetsDirectory: filepath.Join("..", "..", "..", "bin", "k8s", | ||
fmt.Sprintf("1.31.0-%s-%s", runtime.GOOS, runtime.GOARCH)), | ||
} | ||
|
||
var err error | ||
// cfg is defined in this file globally. | ||
cfg, err = testEnv.Start() | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(cfg).NotTo(BeNil()) | ||
|
||
Expect(apiextensionsscheme.AddToScheme(scheme.Scheme)).To(Succeed()) | ||
Expect(machinescheme.AddToScheme(scheme.Scheme)).To(Succeed()) | ||
Expect(gardenerextensionv1alpha1.AddToScheme(scheme.Scheme)).To(Succeed()) | ||
Expect(apiv1alpha1.AddToScheme(scheme.Scheme)).To(Succeed()) | ||
|
||
// Init package-level k8sClient | ||
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(k8sClient).NotTo(BeNil()) | ||
|
||
komega.SetClient(k8sClient) | ||
}) | ||
|
||
var _ = AfterSuite(func() { | ||
Expect(testEnv.Stop()).To(Succeed()) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters