func TestMain(m *testing.M) {
	t := &envtest.Environment{}
	var err error
	if cfg, err = t.Start(); err != nil {
		log.Fatal(err)
	}
	code := m.Run()
	if err := t.Stop(); err != nil {
		log.Fatal(fmt.Errorf("shutting down: %w", err))
	}
	os.Exit(code)
}
TestMain runs before package tests and starts a local apiserver instance.
package rotator
import (
	"context"
	"fmt"
	"log"
	"os"
	"sync"
	"testing"
	"github.com/onsi/gomega"
	"k8s.io/client-go/rest"
	"sigs.k8s.io/controller-runtime/pkg/envtest"
	"sigs.k8s.io/controller-runtime/pkg/manager"
)
var cfg *rest.Config