Repository navigation
Expand file tree
/
Copy pathprinter_test.go
More file actions
131 lines (110 loc) · 2.85 KB
/
Copy pathprinter_test.go
File metadata and controls
131 lines (110 loc) · 2.85 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"bytes"
"fmt"
"io"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Printer", func() {
var (
testOut *bytes.Buffer
testIn io.Reader
format string
)
JustBeforeEach(func() {
SetOutput(testOut)
SetErrorOutput(testOut)
SetInput(testIn)
})
AfterEach(func() {
SetOutput(os.Stdout)
SetErrorOutput(os.Stderr)
SetInput(os.Stdin)
})
Context("when given a single argument", func() {
BeforeEach(func() {
format = "A simple string"
testOut = &bytes.Buffer{}
testIn = bytes.NewReader([]byte("y\n"))
})
It("prompts confirmation", func() {
y := PromptConfirmation(format)
Ω(y).Should(Equal("y"))
Ω(testOut.String()).Should(Equal(format))
})
It("prints subtitles", func() {
PrintSubtitle(format)
Ω(testOut.String()).Should(ContainSubstring(format + "\n"))
})
It("prints titles", func() {
PrintTitle(format)
var rawOut = testOut.String()
Ω(rawOut).Should(ContainSubstring(format))
})
It("prints success", func() {
PrintSuccess(format)
var rawOut = testOut.String()
Ω(rawOut).Should(ContainSubstring(format))
})
It("prints errors", func() {
PrintError(format)
var rawOut = testOut.String()
Ω(rawOut).Should(ContainSubstring(format))
})
It("prints fatals", func() {
var exitCode int
osExit = func(code int) { exitCode = code }
PrintFatal(format)
var rawOut = testOut.String()
Ω(rawOut).Should(ContainSubstring(format))
Ω(exitCode).Should(Equal(1))
})
})
Context("when given a format", func() {
var (
suffix string
formatWithSuffix string
)
BeforeEach(func() {
suffix = "foo"
format = "A simple string with suffix '%s'"
formatWithSuffix = fmt.Sprintf(format, suffix)
testOut = &bytes.Buffer{}
testIn = bytes.NewReader([]byte("y\n"))
})
It("prompts confirmation", func() {
var y = PromptConfirmation(format, suffix)
Ω(y).Should(Equal("y"))
Ω(testOut.String()).Should(Equal(formatWithSuffix))
})
It("prints subtitles", func() {
PrintSubtitle(format, suffix)
Ω(testOut.String()).Should(ContainSubstring(formatWithSuffix + "\n"))
})
It("prints titles", func() {
PrintTitle(format, suffix)
var rawOut = testOut.String()
Ω(rawOut).Should(ContainSubstring(formatWithSuffix))
})
It("prints success", func() {
PrintSuccess(format, suffix)
var rawOut = testOut.String()
Ω(rawOut).Should(ContainSubstring(formatWithSuffix))
})
It("prints errors", func() {
PrintError(format, suffix)
var rawOut = testOut.String()
Ω(rawOut).Should(ContainSubstring(formatWithSuffix))
})
It("prints fatals", func() {
var exitCode int
osExit = func(code int) { exitCode = code }
PrintFatal(format, suffix)
var rawOut = testOut.String()
Ω(rawOut).Should(ContainSubstring(formatWithSuffix))
Ω(exitCode).Should(Equal(1))
})
})
})