-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_test.go
90 lines (72 loc) · 1.93 KB
/
cli_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
89
90
package main
import (
"html/template"
"reflect"
"testing"
)
func TestRun(t *testing.T) {
// TODO
}
func TestParseInput(t *testing.T) {
// TODO
}
func TestGetTemplate(t *testing.T) {
got, err := getTemplate("./testdata/jenga.tmpl")
if err != nil {
t.Errorf("failed to get template: %v", err)
}
want, _ := template.ParseFiles("./testdata/jenga.tmpl")
if !reflect.DeepEqual(got, want) {
t.Errorf("got %v, want %v", got, want)
}
}
func TestGetInputFilePaths(t *testing.T) {
t.Run("correctly return file paths to markdown files in input directory in reverse order", func(t *testing.T) {
got, err := getInputFilePaths("./testdata/src")
if err != nil {
t.Errorf("failed to return file paths: %v", err)
}
want := []string{
"testdata/src/test3.md",
"testdata/src/test2.md",
"testdata/src/test1.md",
}
if !reflect.DeepEqual(got, want) {
t.Errorf("got %v, want %v", got, want)
}
})
t.Run("return empty string array and err when passed path with no markdown files", func(t *testing.T) {
_, err := getInputFilePaths("./testdata/empty")
if err == nil {
t.Errorf("error is empty, want: inputDirPath is empty")
}
})
t.Run("return error when passed a broken path", func(t *testing.T) {
_, err := getInputFilePaths("./testdata/path/does/not/exist")
if err == nil {
t.Errorf("error is empty, want: failed to open")
}
})
}
func TestGetConfig(t *testing.T) {
t.Run("correctly parse passed config", func(t *testing.T) {
got, err := getConfig("./testdata/jenga.toml")
if err != nil {
t.Errorf("failed to parse config: %v", err)
}
want := &config{
InputDirPath: "./src",
OutputDirPath: "./build",
TemplatePath: "./jenga.tmpl",
}
if !reflect.DeepEqual(got, want) {
t.Errorf("got %v, want %v", got, want)
}
})
t.Run("fails when passed bad path", func(t *testing.T) {
_, err := getConfig("")
if err == nil {
t.Errorf("should return error when passed a bad path")
}
})
}