-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathfs_unix_test.go
101 lines (84 loc) · 2.08 KB
/
fs_unix_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//go:build !windows
// +build !windows
package fs
import (
"context"
"os"
"path/filepath"
"testing"
"github.com/hashicorp/hc-install/errors"
"github.com/hashicorp/hc-install/internal/testutil"
"github.com/hashicorp/hc-install/product"
)
func TestAnyVersion_notExecutable(t *testing.T) {
testutil.EndToEndTest(t)
dirPath, fileName := testutil.CreateTempFile(t, "")
t.Setenv("PATH", dirPath)
av := &AnyVersion{
Product: &product.Product{
BinaryName: func() string { return fileName },
},
}
av.SetLogger(testutil.TestLogger())
_, err := av.Find(context.Background())
if err == nil {
t.Fatalf("expected %s not to be found in %s", fileName, dirPath)
}
}
func TestAnyVersion_executable(t *testing.T) {
testutil.EndToEndTest(t)
dirPath, fileName := testutil.CreateTempFile(t, "")
t.Setenv("PATH", dirPath)
fullPath := filepath.Join(dirPath, fileName)
err := os.Chmod(fullPath, 0700)
if err != nil {
t.Fatal(err)
}
av := &AnyVersion{
Product: &product.Product{
BinaryName: func() string { return fileName },
},
}
av.SetLogger(testutil.TestLogger())
_, err = av.Find(context.Background())
if err != nil {
t.Fatal(err)
}
}
func TestAnyVersion_exactBinPath(t *testing.T) {
testutil.EndToEndTest(t)
dirPath, fileName := testutil.CreateTempFile(t, "")
fullPath := filepath.Join(dirPath, fileName)
err := os.Chmod(fullPath, 0700)
if err != nil {
t.Fatal(err)
}
av := &AnyVersion{
ExactBinPath: fullPath,
}
av.SetLogger(testutil.TestLogger())
_, err = av.Find(context.Background())
if err != nil {
t.Fatal(err)
}
}
func TestAnyVersion_exactBinPath_notExecutable(t *testing.T) {
testutil.EndToEndTest(t)
dirPath, fileName := testutil.CreateTempFile(t, "")
fullPath := filepath.Join(dirPath, fileName)
err := os.Chmod(fullPath, 0600)
if err != nil {
t.Fatal(err)
}
av := &AnyVersion{
ExactBinPath: fullPath,
}
av.SetLogger(testutil.TestLogger())
_, err = av.Find(context.Background())
if err == nil {
t.Fatal("expected error for non-executable file")
}
if !errors.IsErrorSkippable(err) {
t.Fatalf("expected a skippable error, got: %#v", err)
}
}