Skip to content

Commit 74a430a

Browse files
authored
test (controllers) : Dynamically construct envtest binary assets while preparing envtest environment (#1441)
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 <[email protected]>
1 parent d0cd6e4 commit 74a430a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

controllers/controller/devworkspacerouting/suite_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"os"
2020
"path/filepath"
21+
"runtime"
2122
"testing"
2223

2324
dwv1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha1"
@@ -86,7 +87,7 @@ var _ = BeforeSuite(func() {
8687
filepath.Join(".", "testdata", "route.crd.yaml"),
8788
},
8889
ErrorIfCRDPathMissing: true,
89-
BinaryAssetsDirectory: filepath.Join("..", "..", "..", "bin", "k8s", "1.24.2-linux-amd64"),
90+
BinaryAssetsDirectory: filepath.Join("..", "..", "..", "bin", "k8s", fmt.Sprintf("1.24.2-%s-%s", runtime.GOOS, runtime.GOARCH)),
9091
}
9192

9293
cfg, err := testEnv.Start()

controllers/workspace/suite_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"net/http"
2020
"os"
2121
"path/filepath"
22+
"runtime"
2223
"testing"
2324

2425
dwv1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha1"
@@ -87,7 +88,7 @@ var _ = BeforeSuite(func() {
8788
testEnv = &envtest.Environment{
8889
CRDDirectoryPaths: []string{filepath.Join("..", "..", "deploy", "templates", "crd", "bases")},
8990
ErrorIfCRDPathMissing: true,
90-
BinaryAssetsDirectory: filepath.Join("..", "..", "bin", "k8s", "1.24.2-linux-amd64"),
91+
BinaryAssetsDirectory: filepath.Join("..", "..", "bin", "k8s", fmt.Sprintf("1.24.2-%s-%s", runtime.GOOS, runtime.GOARCH)),
9192
}
9293

9394
cfg, err := testEnv.Start()

0 commit comments

Comments
 (0)