summaryrefslogtreecommitdiffstats
path: root/pkg/commands/os_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/commands/os_test.go')
-rw-r--r--pkg/commands/os_test.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/pkg/commands/os_test.go b/pkg/commands/os_test.go
index d78391d17..a7ccef560 100644
--- a/pkg/commands/os_test.go
+++ b/pkg/commands/os_test.go
@@ -1,6 +1,7 @@
package commands
import (
+ "os"
"os/exec"
"testing"
@@ -297,3 +298,60 @@ func TestOSCommandUnquote(t *testing.T) {
assert.EqualValues(t, expected, actual)
}
+
+func TestOSCommandFileType(t *testing.T) {
+ type scenario struct {
+ path string
+ setup func()
+ test func(string)
+ }
+
+ scenarios := []scenario{
+ {
+ "testFile",
+ func() {
+ if _, err := os.Create("testFile"); err != nil {
+ panic(err)
+ }
+ },
+ func(output string) {
+ assert.EqualValues(t, "file", output)
+ },
+ },
+ {
+ "file with spaces",
+ func() {
+ if _, err := os.Create("file with spaces"); err != nil {
+ panic(err)
+ }
+ },
+ func(output string) {
+ assert.EqualValues(t, "file", output)
+ },
+ },
+ {
+ "testDirectory",
+ func() {
+ if err := os.Mkdir("testDirectory", 0644); err != nil {
+ panic(err)
+ }
+ },
+ func(output string) {
+ assert.EqualValues(t, "directory", output)
+ },
+ },
+ {
+ "nonExistant",
+ func() {},
+ func(output string) {
+ assert.EqualValues(t, "other", output)
+ },
+ },
+ }
+
+ for _, s := range scenarios {
+ s.setup()
+ s.test(newDummyOSCommand().FileType(s.path))
+ _ = os.RemoveAll(s.path)
+ }
+}