forked from hyperboloide/pdfgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
88 lines (70 loc) · 1.96 KB
/
config_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main_test
import (
"io/ioutil"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spf13/viper"
. "github.com/hyperboloide/pdfgen"
)
var _ = Describe("Config", func() {
It("IsValidDir should work in the 'templates' dir", func() {
Expect(IsValidDir("./templates")).To(BeTrue())
})
It("IsValidDir should return false on a path that don't exists", func() {
Expect(IsValidDir("./do_not_exists")).To(BeFalse())
})
It("IsValidDir should return false on a path that is not a directory", func() {
Expect(IsValidDir("./main.go")).To(BeFalse())
})
It("SelectDir should return a valid path", func() {
dirs := []string{
"./do_not_exists",
"./templates",
"./main.go",
}
Expect(*SelectDir(dirs)).To(Equal("./templates"))
})
It("SelectDir should return nil if no valid path is found", func() {
dirs := []string{
"./do_not_exists",
"./main.go",
}
Expect(SelectDir(dirs)).To(BeNil())
})
Context("bad path", func() {
path := os.Getenv("PATH")
_ = BeforeEach(func() {
os.Setenv("PATH", "")
})
_ = AfterEach(func() {
os.Setenv("PATH", path)
})
It("read the config and set the error", func() {
err := ConfigRead()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("executable wkhtmltopdf could not be found in PATH"))
})
})
It("set invalid template dir", func() {
viper.Set("templates", "invalid")
err := ConfigRead()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("invalid template directory"))
})
It("set invalid template dir", func() {
viper.Set("templates", "")
err := ConfigRead()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("template directory not found"))
})
It("no template found", func() {
dir, err := ioutil.TempDir("", "")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(dir)
viper.Set("templates", dir)
err = ConfigRead()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("No template found"))
})
})