|
4 | 4 | "context"
|
5 | 5 | "os"
|
6 | 6 | "path/filepath"
|
| 7 | + "runtime" |
7 | 8 | "testing"
|
8 | 9 |
|
9 | 10 | "github.com/hashicorp/go-version"
|
|
20 | 21 | _ src.LoggerSettable = &ExactVersion{}
|
21 | 22 | )
|
22 | 23 |
|
23 |
| -func TestAnyVersion_notExecutable(t *testing.T) { |
24 |
| - testutil.EndToEndTest(t) |
25 |
| - |
26 |
| - originalPath := os.Getenv("PATH") |
27 |
| - os.Setenv("PATH", "") |
28 |
| - t.Cleanup(func() { |
29 |
| - os.Setenv("PATH", originalPath) |
30 |
| - }) |
31 |
| - |
32 |
| - dirPath, fileName := createTempFile(t, "") |
33 |
| - os.Setenv("PATH", dirPath) |
34 |
| - |
35 |
| - av := &AnyVersion{ |
36 |
| - Product: product.Product{ |
37 |
| - BinaryName: fileName, |
38 |
| - }, |
39 |
| - } |
40 |
| - av.SetLogger(testutil.TestLogger()) |
41 |
| - _, err := av.Find(context.Background()) |
42 |
| - if err == nil { |
43 |
| - t.Fatalf("expected %s not to be found in %s", fileName, dirPath) |
44 |
| - } |
45 |
| -} |
46 |
| - |
47 |
| -func TestAnyVersion_executable(t *testing.T) { |
48 |
| - testutil.EndToEndTest(t) |
49 |
| - |
50 |
| - originalPath := os.Getenv("PATH") |
51 |
| - os.Setenv("PATH", "") |
52 |
| - t.Cleanup(func() { |
53 |
| - os.Setenv("PATH", originalPath) |
54 |
| - }) |
55 |
| - |
56 |
| - dirPath, fileName := createTempFile(t, "") |
57 |
| - os.Setenv("PATH", dirPath) |
58 |
| - |
59 |
| - fullPath := filepath.Join(dirPath, fileName) |
60 |
| - err := os.Chmod(fullPath, 0700) |
61 |
| - if err != nil { |
62 |
| - t.Fatal(err) |
63 |
| - } |
64 |
| - |
65 |
| - av := &AnyVersion{ |
66 |
| - Product: product.Product{ |
67 |
| - BinaryName: fileName, |
68 |
| - }, |
69 |
| - } |
70 |
| - av.SetLogger(testutil.TestLogger()) |
71 |
| - _, err = av.Find(context.Background()) |
72 |
| - if err != nil { |
73 |
| - t.Fatal(err) |
74 |
| - } |
75 |
| -} |
76 |
| - |
77 | 24 | func TestExactVersion(t *testing.T) {
|
78 | 25 | t.Skip("TODO")
|
79 | 26 | testutil.EndToEndTest(t)
|
@@ -101,6 +48,10 @@ func createTempFile(t *testing.T, content string) (string, string) {
|
101 | 48 | tmpDir := t.TempDir()
|
102 | 49 | fileName := t.Name()
|
103 | 50 |
|
| 51 | + if runtime.GOOS == "windows" { |
| 52 | + fileName += ".exe" |
| 53 | + } |
| 54 | + |
104 | 55 | filePath := filepath.Join(tmpDir, fileName)
|
105 | 56 | f, err := os.Create(filePath)
|
106 | 57 | if err != nil {
|
|
0 commit comments