This repository has been archived by the owner on Aug 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile_test.go
87 lines (66 loc) · 2.02 KB
/
file_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
package magext
import (
"runtime"
"testing"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/types"
)
func TestFileExists(t *testing.T) {
type testFacts struct {
filename string
expectedExists types.GomegaMatcher
}
t.Run("should return false when file does not exist", func(t *testing.T) {
tt := NewGomegaWithT(t)
test := testFacts{
filename: "./not_existent_file.xxx",
expectedExists: BeFalse(),
}
actualExists := FileExists(test.filename)
tt.Expect(actualExists).To(test.expectedExists)
})
t.Run("should return true when file exists", func(t *testing.T) {
tt := NewGomegaWithT(t)
test := testFacts{
filename: "./file.go",
expectedExists: BeTrue(),
}
actualExists := FileExists(test.filename)
tt.Expect(actualExists).To(test.expectedExists)
})
}
func TestCommandExists(t *testing.T) {
t.Run("should return false for a command that does not exist in path", func(t *testing.T) {
tt := NewGomegaWithT(t)
actualExists := CommandExists("notexistingcmd")
tt.Expect(actualExists).To(BeFalse())
})
t.Run("should return true for a command that exist in path", func(t *testing.T) {
tt := NewGomegaWithT(t)
actualExists := false
if runtime.GOOS != "windows" {
actualExists = CommandExists("ls")
}
tt.Expect(actualExists).To(BeTrue())
})
}
func TestCommandOrFileExists(t *testing.T) {
t.Run("should return false when input does not exist as file or command", func(t *testing.T) {
tt := NewGomegaWithT(t)
actualExists := CommandOrFileExists("notexistingcmd")
tt.Expect(actualExists).To(BeFalse())
})
t.Run("should return true when input is an existing file", func(t *testing.T) {
tt := NewGomegaWithT(t)
actualExists := CommandOrFileExists("./file.go")
tt.Expect(actualExists).To(BeTrue())
})
t.Run("should return true when input is am existing command", func(t *testing.T) {
tt := NewGomegaWithT(t)
actualExists := false
if runtime.GOOS != "windows" {
actualExists = CommandOrFileExists("ls")
}
tt.Expect(actualExists).To(BeTrue())
})
}