Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijeet-dhumal committed Jan 25, 2024
1 parent 9429154 commit 3d8c2bb
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions functional-tests/appwrapper_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,11 @@ import (
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
log "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

var (
cfg *rest.Config
k8sClient client.Client // You'll be using this client in your tests.
testEnv *envtest.Environment
err error
)

func logger() {
// Get log file path from environment variable or use a default path
logFilePath := os.Getenv("LOG_FILE_PATH")
Expand All @@ -55,45 +47,37 @@ func logger() {
log.SetLogger(logger)
}

func startEnvTest(t *testing.T) {
func startEnvTest(t *testing.T) (*envtest.Environment, *rest.Config) {
// to redirect all functional test related logs to separate logfile ~ default (in functional-tests directory), can be changed using environment variable LOG_FILE_PATH=/path_to_logfile
logger()

//specify testEnv configuration
testEnv = &envtest.Environment{
testEnv := &envtest.Environment{
CRDDirectoryPaths: []string{
filepath.Join(build.Default.GOPATH, "pkg", "mod", "github.com", "project-codeflare", "[email protected]", "config", "crd", "bases"),
filepath.Join(build.Default.GOPATH, "pkg", "mod", "github.com", "openshift", "[email protected]", "machine", "v1beta1"),
},
ErrorIfCRDPathMissing: true,
}
test := WithConfig(t, testEnv.Config)
cfg, err = testEnv.Start()
cfg, err := testEnv.Start()
test.Expect(err).NotTo(HaveOccurred())

t.Cleanup(func() {
teardownTestEnv(t, testEnv)
})

establishClient(t, testEnv) // setup client required for test to interact with kubernetes machine API
return testEnv, cfg
}

func establishClient(t *testing.T, testEnv *envtest.Environment) {
// Create a test instance with the provided configuration.
test := WithConfig(t, cfg)

func startInstascaleController(test Test, testEnv *envtest.Environment, cfg *rest.Config) {
// Add custom resource schemes to the global scheme.
err = mcadv1beta1.AddToScheme(scheme.Scheme)
err := mcadv1beta1.AddToScheme(scheme.Scheme)
test.Expect(err).NotTo(HaveOccurred())

err = machinev1beta1.AddToScheme(scheme.Scheme)
test.Expect(err).NotTo(HaveOccurred())

// Create a Kubernetes client using the provided configuration.
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
test.Expect(err).NotTo(HaveOccurred())
test.Expect(k8sClient).NotTo(BeNil())

// Create a controller manager for managing controllers.
k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme.Scheme,
Expand Down Expand Up @@ -177,9 +161,10 @@ func MachineSetReplicas(machineSet *machinev1beta1.MachineSet) *int32 {

func TestReconciler(t *testing.T) {
// initiate setting up the EnvTest environment
startEnvTest(t)
testEnv, cfg := startEnvTest(t)

test := WithConfig(t, cfg)
startInstascaleController(test, testEnv, cfg) // setup client required for test to interact with kubernetes machine API

// initialize a variable with test client
client := test.Client()
Expand Down

0 comments on commit 3d8c2bb

Please sign in to comment.