-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
102 lines (85 loc) · 2.87 KB
/
main_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
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"errors"
"flag"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Main", func() {
var defaultInput *userInput
BeforeEach(func() {
defaultInput = &userInput{
template: "readme-template",
name: "README",
imageUrl: "./assets/default_image.png",
}
})
AfterEach(func() {
// Reset osArgs so they can be parsed again
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
})
Describe("Get user input", func() {
Context("when using default arguments", func() {
It("should return a valid default userInput object", func() {
os.Args = []string{"cmd", "--template=readme-template", "--name=README", "--imageUrl=./assets/default_image.png"}
result, err := getUserInput()
Expect(err).To(BeNil())
Expect(result.template).To(Equal(defaultInput.template))
Expect(result.name).To(Equal(defaultInput.name))
Expect(result.imageUrl).To(Equal(defaultInput.imageUrl))
})
})
Context("when no user arguments are provided", func() {
It("should also return a valid default userInput object", func() {
os.Args = []string{"cmd"}
result, err := getUserInput()
Expect(err).To(BeNil())
Expect(result.template).To(Equal(defaultInput.template))
Expect(result.name).To(Equal(defaultInput.name))
Expect(result.imageUrl).To(Equal(defaultInput.imageUrl))
})
})
// TODO: Revisit this functionality when I update the validate template code
/* Context("when template is invalid", func() {
It("should return invalid template error", func() {
expectedErr := errors.New("invalid template value. use readme-template or readme")
os.Args = []string{"cmd", "--template=f4k3"}
result, err := getUserInput()
Expect(err).To(Equal(expectedErr))
Expect(result).To(Equal(userInput{}))
})
}) */
Context("when name is invalid", func() {
It("should return invalid name error", func() {
expectedErr := errors.New("there was an error setting the document's name")
os.Args = []string{"cmd", "--name="}
result, err := getUserInput()
Expect(err).To(Equal(expectedErr))
Expect(result).To(Equal(userInput{}))
})
})
Context("when imageUrl is invalid", func() {
It("should return invalid imageUrl error", func() {
expectedErr := errors.New("there was an error setting the image's Url")
os.Args = []string{"cmd", "--imageUrl="}
result, err := getUserInput()
Expect(err).To(Equal(expectedErr))
Expect(result).To(Equal(userInput{}))
})
})
})
Describe("Generate file", func() {
Context("when the file template is readme-template", func() {
It("should create a new file with no errors", func() {
testInput := userInput{
template: "readme-template",
}
result, err := generateFile(testInput.template)
Expect(err).To(BeNil())
Expect(result).To(Not(BeNil()))
// TODO: add check for new file?
})
})
})
})