Skip to content

Commit

Permalink
fix(tests): remove need for REPO_ROOT env var
Browse files Browse the repository at this point in the history
  • Loading branch information
hrak committed Aug 30, 2024
1 parent 00692df commit f472057
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
23 changes: 8 additions & 15 deletions controllers/controllers_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
"fmt"
"go/build"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
goruntime "runtime"
"strings"
"testing"
"time"
Expand All @@ -37,7 +38,6 @@ import (
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -131,16 +131,6 @@ var (
)

var _ = BeforeSuite(func() {
repoRoot := os.Getenv("REPO_ROOT")

// Add ginkgo recover statements to controllers.
cmd := exec.Command(repoRoot+"/hack/testing_ginkgo_recover_statements.sh", "--contains")
cmd.Stdout = os.Stdout
if err := cmd.Run(); err != nil {
fmt.Println(errors.Wrapf(err, "refusing to run test suite without ginkgo recover statements present"))
os.Exit(1)
}

By("bootstrapping test environment")

Ω(infrav1.AddToScheme(scheme.Scheme)).Should(Succeed())
Expand Down Expand Up @@ -177,11 +167,14 @@ func (m *MockCtrlrCloudClientImplementation) RegisterExtension(r *csCtrlrUtils.R
}

func SetupTestEnvironment() {
repoRoot := os.Getenv("REPO_ROOT")
crdPaths := []string{filepath.Join(repoRoot, "config", "crd", "bases"), filepath.Join(repoRoot, "test", "fakes")}
// Get the root of the current file to use in CRD paths.
_, filename, _, _ := goruntime.Caller(0) //nolint:dogsled // Ignore "declaration has 3 blank identifiers" check.
root := path.Join(path.Dir(filename), "..")

crdPaths := []string{filepath.Join(root, "config", "crd", "bases"), filepath.Join(root, "test", "fakes")}

// Append CAPI CRDs path
if capiPath := getFilePathToCAPICRDs(repoRoot); capiPath != "" {
if capiPath := getFilePathToCAPICRDs(root); capiPath != "" {
crdPaths = append(crdPaths, capiPath)
}
testEnv = &envtest.Environment{
Expand Down
8 changes: 6 additions & 2 deletions test/dummies/v1beta3/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package dummies

import (
"os"
"path"
goruntime "runtime"

csapi "github.com/apache/cloudstack-go/v2/cloudstack"
"github.com/onsi/gomega"
Expand Down Expand Up @@ -94,8 +96,10 @@ var ( // Declare exported dummy vars.

// SetDummyVars sets/resets all dummy vars.
func SetDummyVars() {
projDir := os.Getenv("REPO_ROOT")
source, err := os.ReadFile(projDir + "/test/e2e/config/cloudstack.yaml")
// Get the root of the current file to use in CRD paths.
_, filename, _, _ := goruntime.Caller(0) //nolint:dogsled // Ignore "declaration has 3 blank identifiers" check.
root := path.Join(path.Dir(filename), "..", "..")
source, err := os.ReadFile(root + "/e2e/config/cloudstack.yaml")
if err != nil {
panic(err)
}
Expand Down

0 comments on commit f472057

Please sign in to comment.