Skip to content

Commit f0883e9

Browse files
author
Konikz
committed
fix: update test file to comply with linting rules
- Replace t.Fatalf with assert.NilError and assert.Equal - Update octal literals to use new style (0o755) - Fix formatting issues Signed-off-by: Konikz <[email protected]>
1 parent d6a6411 commit f0883e9

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

Diff for: pkg/usrlocalsharelima/standalone_test.go

+11-21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"path/filepath"
1010
"runtime"
1111
"testing"
12+
13+
"gotest.tools/v3/assert"
1214
)
1315

1416
// TestDirInTestEnvironment tests that usrlocalsharelima.Dir() works correctly
@@ -18,9 +20,7 @@ import (
1820
func TestDirInTestEnvironment(t *testing.T) {
1921
// Get the test executable path (will be in a temp directory)
2022
testExe, err := os.Executable()
21-
if err != nil {
22-
t.Fatalf("Failed to get test executable path: %v", err)
23-
}
23+
assert.NilError(t, err, "Failed to get test executable path")
2424

2525
// Determine architecture for binary name
2626
arch := "aarch64"
@@ -31,37 +31,27 @@ func TestDirInTestEnvironment(t *testing.T) {
3131
// Create guestagent binary in the first expected location
3232
// (same directory as test executable)
3333
gaBinary1 := filepath.Join(filepath.Dir(testExe), fmt.Sprintf("lima-guestagent.Linux-%s", arch))
34-
err = os.WriteFile(gaBinary1, []byte("dummy"), 0755)
35-
if err != nil {
36-
t.Fatalf("Failed to create guestagent binary: %v", err)
37-
}
34+
err = os.WriteFile(gaBinary1, []byte("dummy"), 0o755)
35+
assert.NilError(t, err, "Failed to create guestagent binary")
3836
defer os.Remove(gaBinary1)
3937

4038
// Create guestagent binary in the second expected location
4139
// (share/lima directory relative to test executable)
4240
shareDir := filepath.Join(filepath.Dir(filepath.Dir(testExe)), "share", "lima")
43-
err = os.MkdirAll(shareDir, 0755)
44-
if err != nil {
45-
t.Fatalf("Failed to create share directory: %v", err)
46-
}
41+
err = os.MkdirAll(shareDir, 0o755)
42+
assert.NilError(t, err, "Failed to create share directory")
4743
defer os.RemoveAll(shareDir)
4844

4945
gaBinary2 := filepath.Join(shareDir, fmt.Sprintf("lima-guestagent.Linux-%s", arch))
50-
err = os.WriteFile(gaBinary2, []byte("dummy"), 0755)
51-
if err != nil {
52-
t.Fatalf("Failed to create guestagent binary: %v", err)
53-
}
46+
err = os.WriteFile(gaBinary2, []byte("dummy"), 0o755)
47+
assert.NilError(t, err, "Failed to create guestagent binary")
5448
defer os.Remove(gaBinary2)
5549

5650
// Test that Dir() can find the binary
5751
dir, err := Dir()
58-
if err != nil {
59-
t.Fatalf("Dir() failed: %v", err)
60-
}
52+
assert.NilError(t, err, "Dir() failed")
6153

6254
// Verify that Dir() returns the correct directory
6355
expectedDir := filepath.Dir(gaBinary1)
64-
if dir != expectedDir {
65-
t.Errorf("Expected directory %q, got %q", expectedDir, dir)
66-
}
56+
assert.Equal(t, dir, expectedDir, "Directory mismatch")
6757
}

0 commit comments

Comments
 (0)