9
9
"path/filepath"
10
10
"runtime"
11
11
"testing"
12
+
13
+ "gotest.tools/v3/assert"
12
14
)
13
15
14
16
// TestDirInTestEnvironment tests that usrlocalsharelima.Dir() works correctly
@@ -18,9 +20,7 @@ import (
18
20
func TestDirInTestEnvironment (t * testing.T ) {
19
21
// Get the test executable path (will be in a temp directory)
20
22
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" )
24
24
25
25
// Determine architecture for binary name
26
26
arch := "aarch64"
@@ -31,37 +31,27 @@ func TestDirInTestEnvironment(t *testing.T) {
31
31
// Create guestagent binary in the first expected location
32
32
// (same directory as test executable)
33
33
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" )
38
36
defer os .Remove (gaBinary1 )
39
37
40
38
// Create guestagent binary in the second expected location
41
39
// (share/lima directory relative to test executable)
42
40
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" )
47
43
defer os .RemoveAll (shareDir )
48
44
49
45
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" )
54
48
defer os .Remove (gaBinary2 )
55
49
56
50
// Test that Dir() can find the binary
57
51
dir , err := Dir ()
58
- if err != nil {
59
- t .Fatalf ("Dir() failed: %v" , err )
60
- }
52
+ assert .NilError (t , err , "Dir() failed" )
61
53
62
54
// Verify that Dir() returns the correct directory
63
55
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" )
67
57
}
0 commit comments