80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
/*
|
|
Copyright 2020 The Flux authors
|
|
|
|
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"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/fluxcd/pkg/runtime/testenv"
|
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
|
"k8s.io/client-go/kubernetes/scheme"
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
|
|
imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1beta1"
|
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
|
|
|
imagev1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
|
|
)
|
|
|
|
const (
|
|
contextTimeout = time.Second * 10
|
|
)
|
|
|
|
var (
|
|
testEnv *testenv.Environment
|
|
ctx = ctrl.SetupSignalHandler()
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
utilruntime.Must(imagev1_reflect.AddToScheme(scheme.Scheme))
|
|
utilruntime.Must(sourcev1.AddToScheme(scheme.Scheme))
|
|
utilruntime.Must(imagev1.AddToScheme(scheme.Scheme))
|
|
|
|
testEnv = testenv.New(testenv.WithCRDPath(
|
|
filepath.Join("..", "config", "crd", "bases"),
|
|
filepath.Join("testdata", "crds"),
|
|
))
|
|
|
|
if err := (&ImageUpdateAutomationReconciler{
|
|
Client: testEnv,
|
|
Scheme: scheme.Scheme,
|
|
}).SetupWithManager(testEnv, ImageUpdateAutomationReconcilerOptions{}); err != nil {
|
|
panic(fmt.Sprintf("Failed to start ImageUpdateAutomationReconciler: %v", err))
|
|
}
|
|
|
|
go func() {
|
|
fmt.Println("Starting the test environment")
|
|
if err := testEnv.Start(ctx); err != nil {
|
|
panic(fmt.Sprintf("Failed to start the test environment manager: %v", err))
|
|
}
|
|
}()
|
|
<-testEnv.Manager.Elected()
|
|
|
|
code := m.Run()
|
|
|
|
fmt.Println("Stopping the test environment")
|
|
if err := testEnv.Stop(); err != nil {
|
|
panic(fmt.Sprintf("Failed to stop the test environment: %v", err))
|
|
}
|
|
|
|
os.Exit(code)
|
|
}
|