-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilesystem_test.go
40 lines (30 loc) · 1.08 KB
/
filesystem_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
package goutils
import "testing"
func TestValidateFile(t *testing.T) {
// test empty filename
_, _, err := ValidateFile("")
Equals(t, err.Error(), "{file} required")
// test file does not exist
_, _, err = ValidateFile("noexist.txt")
Equals(t, err.Error(), "invalid, no such file [noexist.txt]")
// test valid file that exists
_, _, err = ValidateFile("test/readonly.txt")
Ok(t, err)
// test error file is directory
_, _, err = ValidateFile("test")
Equals(t, err.Error(), "invalid, file is a directory [test]")
}
func TestValidateDir(t *testing.T) {
// test empty filename
_, _, err := ValidateDir("")
Equals(t, err.Error(), "{directory} required")
// test file does not exist
_, _, err = ValidateDir("noexist.txt")
Equals(t, err.Error(), "invalid, no such directory [noexist.txt]")
// test error is not a directory
_, _, err = ValidateDir("/test/test")
Equals(t, err.Error(), "invalid, no such directory [/test/test]")
// test valid file that exists
_, _, err = ValidateDir("test/readonly.txt")
Equals(t, err.Error(), "invalid, is not a directory [test/readonly.txt]")
}