@@ -4,8 +4,6 @@ package util
44
55import (
66 "context"
7- "errors"
8- "io/fs"
97 "os"
108 "os/exec"
119 "path/filepath"
@@ -22,16 +20,10 @@ const (
2220)
2321
2422func TestExecutable (t * testing.T ) {
25- helperBinary := os .Getenv ("TEST_HELPER" )
26- if helperBinary == "" {
27- helperBinary = "./test-helper"
28- }
23+ helperBinary := filepath .Join (os .Getenv ("TEST_HELPERS" ), "test-args" )
2924 helperBinary , err := filepath .Abs (helperBinary )
30- require .NoError (t , err , "Failed to get absolute path of helper binary" )
31-
32- if _ , err := os .Stat (helperBinary ); errors .Is (err , fs .ErrNotExist ) {
33- t .Fatalf ("Helper binary does not exist at expected path: %q\n " , helperBinary )
34- }
25+ require .NoError (t , err , "Failed to get absolute path of helper binary" , helperBinary )
26+ require .FileExists (t , helperBinary , "Helper binary is not available at expected path" )
3527
3628 tempDir := t .TempDir ()
3729 symlinkBinary := filepath .Join (tempDir , "executable_test_symlink" )
@@ -44,11 +36,10 @@ func TestExecutable(t *testing.T) {
4436
4537 cmd := exec .CommandContext (ctx , helperBinary , helperExecutableCommand )
4638 output , err := cmd .Output ()
47- if err != nil {
48- t .Fatalf ("Error executing helper binary: %s\n " , err )
49- }
39+ require .NoError (t , err )
40+
5041 t .Log (string (output ))
51- assert .Equal (t , string ( output ), "\" " + helperBinary + "\" \n " , "Output should match the helper binary path" )
42+ assert .Equal (t , "\" " + helperBinary + "\" \n " , string ( output ) , "Output should match the helper binary path" )
5243 })
5344
5445 t .Run ("absolute symlink" , func (t * testing.T ) {
@@ -57,11 +48,10 @@ func TestExecutable(t *testing.T) {
5748
5849 cmd := exec .CommandContext (ctx , symlinkBinary , helperExecutableCommand )
5950 output , err := cmd .Output ()
60- if err != nil {
61- t .Fatalf ("Error executing helper binary: %s\n " , err )
62- }
51+ require .NoError (t , err )
52+
6353 t .Log (string (output ))
64- assert .Equal (t , string ( output ), "\" " + symlinkBinary + "\" \n " , "Output should match the helper binary path" )
54+ assert .Equal (t , "\" " + symlinkBinary + "\" \n " , string ( output ) , "Output should match the helper binary path" )
6555 })
6656
6757 t .Run ("relative" , func (t * testing.T ) {
@@ -71,11 +61,10 @@ func TestExecutable(t *testing.T) {
7161 cmd := exec .CommandContext (ctx , "./" + filepath .Base (helperBinary ), helperExecutableCommand )
7262 cmd .Dir = filepath .Dir (helperBinary ) // Set the working directory to the helper binary's directory
7363 output , err := cmd .Output ()
74- if err != nil {
75- t .Fatalf ("Error executing helper binary: %s\n " , err )
76- }
64+ require .NoError (t , err )
65+
7766 t .Log (string (output ))
78- assert .Equal (t , string ( output ), "\" " + helperBinary + "\" \n " , "Output should match the helper binary path" )
67+ assert .Equal (t , "\" " + helperBinary + "\" \n " , string ( output ) , "Output should match the helper binary path" )
7968 })
8069
8170 t .Run ("relative symlink" , func (t * testing.T ) {
@@ -85,11 +74,10 @@ func TestExecutable(t *testing.T) {
8574 cmd := exec .CommandContext (ctx , "./" + filepath .Base (symlinkBinary ), helperExecutableCommand )
8675 cmd .Dir = tempDir // Set the working directory to the temp directory
8776 output , err := cmd .Output ()
88- if err != nil {
89- t .Fatalf ("Error executing helper binary: %s\n " , err )
90- }
77+ require .NoError (t , err )
78+
9179 t .Log (string (output ))
92- assert .Equal (t , string ( output ), "\" " + symlinkBinary + "\" \n " , "Output should match the helper binary path" )
80+ assert .Equal (t , "\" " + symlinkBinary + "\" \n " , string ( output ) , "Output should match the helper binary path" )
9381 })
9482
9583 t .Run ("from PATH" , func (t * testing.T ) {
@@ -102,11 +90,10 @@ func TestExecutable(t *testing.T) {
10290
10391 cmd := exec .CommandContext (ctx , filepath .Base (helperBinary ), helperExecutableCommand )
10492 output , err := cmd .Output ()
105- if err != nil {
106- t .Fatalf ("Error executing helper binary: %s\n " , err )
107- }
93+ require .NoError (t , err )
94+
10895 t .Log (string (output ))
109- assert .Equal (t , string ( output ), "\" " + helperBinary + "\" \n " , "Output should match the helper binary path" )
96+ assert .Equal (t , "\" " + helperBinary + "\" \n " , string ( output ) , "Output should match the helper binary path" )
11097 })
11198
11299 t .Run ("symlink from PATH" , func (t * testing.T ) {
@@ -119,10 +106,9 @@ func TestExecutable(t *testing.T) {
119106
120107 cmd := exec .CommandContext (ctx , filepath .Base (symlinkBinary ), helperExecutableCommand )
121108 output , err := cmd .Output ()
122- if err != nil {
123- t .Fatalf ("Error executing helper binary: %s\n " , err )
124- }
109+ require .NoError (t , err )
110+
125111 t .Log (string (output ))
126- assert .Equal (t , string ( output ), "\" " + symlinkBinary + "\" \n " , "Output should match the helper binary path" )
112+ assert .Equal (t , "\" " + symlinkBinary + "\" \n " , string ( output ) , "Output should match the helper binary path" )
127113 })
128114}
0 commit comments