77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
/*
|
|
Copyright 2022 SUSE.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package controllers
|
|
|
|
import (
|
|
"fmt"
|
|
"path"
|
|
"testing"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
|
|
// +kubebuilder:scaffold:imports
|
|
bootstrapv1 "github.com/rancher/cluster-api-provider-rke2/bootstrap/api/v1beta1"
|
|
controlplanev1 "github.com/rancher/cluster-api-provider-rke2/controlplane/api/v1beta1"
|
|
"github.com/rancher/cluster-api-provider-rke2/test/helpers"
|
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
|
"k8s.io/client-go/kubernetes/scheme"
|
|
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
)
|
|
|
|
var (
|
|
testEnv *helpers.TestEnvironment
|
|
ctx = ctrl.SetupSignalHandler()
|
|
)
|
|
|
|
func TestAPIs(t *testing.T) {
|
|
RegisterFailHandler(Fail)
|
|
setup()
|
|
defer teardown()
|
|
RunSpecs(t, "Controller Suite")
|
|
}
|
|
|
|
func setup() {
|
|
utilruntime.Must(clusterv1.AddToScheme(scheme.Scheme))
|
|
utilruntime.Must(bootstrapv1.AddToScheme(scheme.Scheme))
|
|
utilruntime.Must(controlplanev1.AddToScheme(scheme.Scheme))
|
|
|
|
testEnvConfig := helpers.NewTestEnvironmentConfiguration([]string{
|
|
path.Join("bootstrap", "config", "crd", "bases"),
|
|
path.Join("controlplane", "config", "crd", "bases"),
|
|
},
|
|
)
|
|
var err error
|
|
testEnv, err = testEnvConfig.Build()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
go func() {
|
|
fmt.Println("Starting the manager")
|
|
if err := testEnv.StartManager(ctx); err != nil {
|
|
panic(fmt.Sprintf("Failed to start the envtest manager: %v", err))
|
|
}
|
|
}()
|
|
}
|
|
|
|
func teardown() {
|
|
if err := testEnv.Stop(); err != nil {
|
|
panic(fmt.Sprintf("Failed to stop envtest: %v", err))
|
|
}
|
|
}
|