dont panic when catting directories

This commit is contained in:
Jesse Duffield 2018-08-28 19:12:35 +10:00
parent 320ccdb22a
commit 7e1e97d050
9 changed files with 102 additions and 8 deletions

View file

@ -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)
}
}