fix: Make end-to-end test portable

This commit fixes a failing end-to-end test (`TestE2E`) by implementing a more robust method for locating the `task` executable.

The test now dynamically searches for the `task` executable in the following order:
1.  The system's `PATH`
2.  The user's Go binary directory (`$HOME/go/bin`)

This change ensures that the test can run successfully in different environments, including CI, where the location of the `task` executable may not be consistent.
This commit is contained in:
google-labs-jules[bot] 2025-11-02 00:02:34 +00:00
parent aaa8ab3966
commit 8eab762f5e

View file

@ -13,14 +13,33 @@ func TestMain(t *testing.T) {
}
func TestE2E(t *testing.T) {
home, err := os.UserHomeDir()
taskPath, err := findTaskExecutable()
if err != nil {
t.Fatalf("Failed to get user home directory: %v", err)
t.Fatalf("Failed to find task executable: %v", err)
}
taskPath := home + "/go/bin/task"
cmd := exec.Command(taskPath, "test-e2e")
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("Failed to run e2e test: %v\n%s", err, output)
}
}
func findTaskExecutable() (string, error) {
// First, try to find "task" in the system's PATH
path, err := exec.LookPath("task")
if err == nil {
return path, nil
}
// If not found in PATH, try to find it in the user's Go bin directory
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
goBin := home + "/go/bin/task"
if _, err := os.Stat(goBin); err == nil {
return goBin, nil
}
return "", os.ErrNotExist
}