-
Notifications
You must be signed in to change notification settings - Fork 9
/
hoi_test.go
58 lines (49 loc) · 1.14 KB
/
hoi_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
package hoi
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
func TestTestFile(t *testing.T) {
var err error
hoi := Hoi{}
_, err = hoi.TestFile("hoi.go")
if err != nil {
t.Errorf("It should have no error in case file exists")
}
_, err = hoi.TestFile("foobar")
if err == nil {
t.Errorf("It should have error in case file does not exist ")
}
}
func TestMakePublic(t *testing.T) {
publicDir := "public_test"
os.MkdirAll(publicDir, 0755)
defer os.RemoveAll(publicDir)
hoi := Hoi{publicDir: publicDir}
linked := hoi.makePublic("hoi.go")
file, err := os.Lstat(filepath.Join(publicDir, linked))
if err != nil {
t.Errorf("It should be made symlink %s, %s", file, err)
}
}
func TestClear(t *testing.T) {
publicDir := "public_test"
os.MkdirAll(publicDir, 0755)
defer os.RemoveAll(publicDir)
hoi := Hoi{publicDir: publicDir}
hoi.makePublic("hoi.go")
hoi.Clear()
contents, _ := ioutil.ReadDir(publicDir)
if len(contents) > 0 {
t.Errorf("It should be clear %s", publicDir)
}
}
func TestRandomString(t *testing.T) {
expect := 10
random := randomString(expect)
if len(random) != 10 {
t.Errorf("It should equal %d", expect)
}
}