forked from rhysd/dot-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_dir_test.go
53 lines (48 loc) · 1.22 KB
/
template_dir_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
package main
import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"
)
func TestTemplateDir(t *testing.T) {
dir := TemplateDir()
if _, err := os.Stat(dir); os.IsNotExist(err) {
t.Fatalf("'.github' directory for templates must be created")
}
if !filepath.IsAbs(dir) {
t.Fatalf("TemplateDir() must return absolute path")
}
if !strings.Contains(dir, ".github") {
t.Fatalf("Invalid template dir path: %v", dir)
}
}
func TestSpecifiedByEnvVar(t *testing.T) {
w, _ := os.Getwd()
os.Setenv("DOT_GITHUB_HOME", w)
defer os.Setenv("DOT_GITHUB_HOME", "")
dir := TemplateDir()
if _, err := os.Stat(dir); os.IsNotExist(err) {
t.Fatalf("'.github' directory for templates must be created")
}
if !filepath.IsAbs(dir) {
t.Fatalf("TemplateDir() must return absolute path")
}
if !strings.Contains(dir, ".github") {
t.Fatalf("Invalid template dir path: %v", dir)
}
}
func TestInvalidDir(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("because I don't know how to specify 'invalid' directory path on Windows")
}
os.Setenv("DOT_GITHUB_HOME", "/")
defer func() {
if r := recover(); r == nil {
t.Errorf("Invalid directory must cause panic")
}
defer os.Setenv("DOT_GITHUB_HOME", "")
}()
TemplateDir()
}