From 1049633e253b227598b32cd6fb601a54bf221f22 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Thu, 29 May 2025 22:34:51 +0530 Subject: [PATCH] test (controllers) : Dynamically construct envtest binary assets while preparing envtest environment Currently envtest environment is loaded with hardcoded BinaryAssetsDirectory for linux/amd64 machine. This doesn't work on other machines that have other operating systems and processor architectures. Updated `BinaryAssetsDirectory` to dynamically construct paths based on `runtime.GOOS` and `runtime.GOARCH` This change adds flexibility when running EnvTest across multiple platforms. Signed-off-by: Rohan Kumar --- controllers/controller/devworkspacerouting/suite_test.go | 3 ++- controllers/workspace/suite_test.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/controllers/controller/devworkspacerouting/suite_test.go b/controllers/controller/devworkspacerouting/suite_test.go index ca18835d4..c6f091274 100644 --- a/controllers/controller/devworkspacerouting/suite_test.go +++ b/controllers/controller/devworkspacerouting/suite_test.go @@ -18,6 +18,7 @@ import ( "fmt" "os" "path/filepath" + "runtime" "testing" dwv1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha1" @@ -86,7 +87,7 @@ var _ = BeforeSuite(func() { filepath.Join(".", "testdata", "route.crd.yaml"), }, ErrorIfCRDPathMissing: true, - BinaryAssetsDirectory: filepath.Join("..", "..", "..", "bin", "k8s", "1.24.2-linux-amd64"), + BinaryAssetsDirectory: filepath.Join("..", "..", "..", "bin", "k8s", fmt.Sprintf("1.24.2-%s-%s", runtime.GOOS, runtime.GOARCH)), } cfg, err := testEnv.Start() diff --git a/controllers/workspace/suite_test.go b/controllers/workspace/suite_test.go index d76e59766..c566a1b3a 100644 --- a/controllers/workspace/suite_test.go +++ b/controllers/workspace/suite_test.go @@ -19,6 +19,7 @@ import ( "net/http" "os" "path/filepath" + "runtime" "testing" dwv1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha1" @@ -87,7 +88,7 @@ var _ = BeforeSuite(func() { testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "deploy", "templates", "crd", "bases")}, ErrorIfCRDPathMissing: true, - BinaryAssetsDirectory: filepath.Join("..", "..", "bin", "k8s", "1.24.2-linux-amd64"), + BinaryAssetsDirectory: filepath.Join("..", "..", "bin", "k8s", fmt.Sprintf("1.24.2-%s-%s", runtime.GOOS, runtime.GOARCH)), } cfg, err := testEnv.Start()