-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gotooltest: run probe commands in temporary directory
This ensures we don't make any assumptions about the caller's working directory, which might contain an invalid go.mod, for example.
- Loading branch information
Showing
2 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package gotooltest | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestInitGoEnv(t *testing.T) { | ||
// Set up a temp directory containing a bad go.mod file to | ||
// ensure the working directory does not influence the probe | ||
// commands run during initGoEnv | ||
td := t.TempDir() | ||
|
||
// If these commands fail we are in bigger trouble | ||
wd, _ := os.Getwd() | ||
os.Chdir(td) | ||
|
||
t.Cleanup(func() { | ||
os.Chdir(wd) | ||
os.Remove(td) | ||
}) | ||
|
||
if err := os.WriteFile("go.mod", []byte("this is rubbish"), 0600); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if err := initGoEnv(); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |