Skip to content

Commit 0c2a3a7

Browse files
committed
Enhance integration tests and improve error handling
- Added runtime checks for binary creation in `integration_test.go` to support Windows compatibility. - Improved error handling in the Makefile installation test by logging non-fatal errors during cleanup. - Updated the binary path in `testutil.go` to accommodate Windows executable naming conventions. - Removed unnecessary code in `bsl_test.go` to streamline test logic.
1 parent 4c8ff36 commit 0c2a3a7

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

cmd/non-admin/bsl/bsl_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ func TestBSLNoLongerHasRequestCommands(t *testing.T) {
8383
continue
8484
}
8585
if inAvailableCommands && strings.Contains(line, "Flags:") {
86-
inAvailableCommands = false
8786
break
8887
}
8988
if inAvailableCommands && strings.Contains(strings.TrimSpace(line), "request") {

cmd/non-admin/nonadmin.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,3 @@ func NewNonAdminCommand(f client.Factory) *cobra.Command {
4040

4141
return c
4242
}
43-

integration_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919
import (
2020
"os"
2121
"os/exec"
22+
"runtime"
2223
"strings"
2324
"testing"
2425

@@ -46,7 +47,11 @@ func TestMakefileInstallation(t *testing.T) {
4647
if err != nil {
4748
t.Fatalf("Failed to get current directory: %v", err)
4849
}
49-
defer os.Chdir(originalDir)
50+
defer func() {
51+
if err := os.Chdir(originalDir); err != nil {
52+
t.Logf("Failed to restore original directory: %v", err)
53+
}
54+
}()
5055

5156
err = os.Chdir(projectRoot)
5257
if err != nil {
@@ -76,7 +81,9 @@ func TestMakefileInstallation(t *testing.T) {
7681

7782
t.Run("make build works", func(t *testing.T) {
7883
// Clean first
79-
exec.Command("make", "clean").Run()
84+
if err := exec.Command("make", "clean").Run(); err != nil {
85+
t.Logf("Failed to clean (non-fatal): %v", err)
86+
}
8087

8188
cmd := exec.Command("make", "build")
8289
output, err := cmd.CombinedOutput()
@@ -85,12 +92,16 @@ func TestMakefileInstallation(t *testing.T) {
8592
}
8693

8794
// Check binary was created
88-
if _, err := os.Stat("kubectl-oadp"); os.IsNotExist(err) {
89-
t.Errorf("Binary kubectl-oadp was not created")
95+
binaryName := "kubectl-oadp"
96+
if runtime.GOOS == "windows" {
97+
binaryName += ".exe"
98+
}
99+
if _, err := os.Stat(binaryName); os.IsNotExist(err) {
100+
t.Errorf("Binary %s was not created", binaryName)
90101
}
91102

92103
// Cleanup
93-
os.Remove("kubectl-oadp")
104+
os.Remove(binaryName)
94105
})
95106
}
96107

internal/testutil/testutil.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ func BuildCLIBinary(t *testing.T) string {
6767

6868
// Create temp directory for the binary
6969
tempDir := t.TempDir()
70-
binaryPath := filepath.Join(tempDir, "oadp-test")
70+
binaryName := "oadp-test"
71+
if runtime.GOOS == "windows" {
72+
binaryName += ".exe"
73+
}
74+
binaryPath := filepath.Join(tempDir, binaryName)
7175

7276
t.Logf("Building CLI binary: %s", binaryPath)
7377
t.Logf("Project root: %s", projectRoot)

0 commit comments

Comments
 (0)