forked from argoproj/pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_test.go
42 lines (34 loc) · 907 Bytes
/
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
package file
import (
"fmt"
"path/filepath"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/argoproj/pkg/rand"
)
// TestIsDirectory tests if a path is a directory. Errors if directory doesn't exist
func TestIsDirectory(t *testing.T) {
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic("could not determine test directory")
}
testDir := filepath.Dir(filename)
isDir, err := IsDirectory(testDir)
require.NoError(t, err)
assert.True(t, isDir)
isDir, err = IsDirectory(filename)
require.NoError(t, err)
assert.False(t, isDir)
isDir, err = IsDirectory("doesnt-exist")
require.Error(t, err)
assert.False(t, isDir)
}
func TestExists(t *testing.T) {
assert.True(t, Exists("/"))
path, err := rand.RandString(10)
require.NoError(t, err)
randFilePath := fmt.Sprintf("/%s", path)
assert.False(t, Exists(randFilePath))
}