Merge remote-tracking branch 'upstream/master' into kill-rogue-processes
Jatin Naik
7 years ago
9 | 9 |
|
10 | 10 |
Learn more about Ginkgo [here](http://onsi.github.io/ginkgo/)
|
11 | 11 |
|
|
12 |
## Community Matchers
|
|
13 |
|
|
14 |
A collection of community matchers is available on the [wiki](https://github.com/onsi/gomega/wiki).
|
|
15 |
|
12 | 16 |
## License
|
13 | 17 |
|
14 | 18 |
Gomega is MIT-Licensed
|
6 | 6 |
"fmt"
|
7 | 7 |
"reflect"
|
8 | 8 |
"strings"
|
|
9 |
"strconv"
|
9 | 10 |
)
|
10 | 11 |
|
11 | 12 |
// Use MaxDepth to set the maximum recursion depth when printing deeply nested objects
|
|
142 | 143 |
case reflect.Ptr:
|
143 | 144 |
return formatValue(value.Elem(), indentation)
|
144 | 145 |
case reflect.Slice:
|
145 | |
if value.Type().Elem().Kind() == reflect.Uint8 {
|
146 | |
return formatString(value.Bytes(), indentation)
|
147 | |
}
|
148 | 146 |
return formatSlice(value, indentation)
|
149 | 147 |
case reflect.String:
|
150 | 148 |
return formatString(value.String(), indentation)
|
|
188 | 186 |
}
|
189 | 187 |
|
190 | 188 |
func formatSlice(v reflect.Value, indentation uint) string {
|
|
189 |
if v.Kind() == reflect.Slice && v.Type().Elem().Kind() == reflect.Uint8 && isPrintableString(string(v.Bytes())){
|
|
190 |
return formatString(v.Bytes(), indentation)
|
|
191 |
}
|
|
192 |
|
191 | 193 |
l := v.Len()
|
192 | 194 |
result := make([]string, l)
|
193 | 195 |
longest := 0
|
|
261 | 263 |
return false
|
262 | 264 |
}
|
263 | 265 |
|
264 | |
func isNil(a interface{}) bool {
|
265 | |
if a == nil {
|
266 | |
return true
|
267 | |
}
|
268 | |
|
269 | |
switch reflect.TypeOf(a).Kind() {
|
270 | |
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
|
271 | |
return reflect.ValueOf(a).IsNil()
|
272 | |
}
|
273 | |
|
274 | |
return false
|
275 | |
}
|
|
266 |
/*
|
|
267 |
Returns true when the string is entirely made of printable runes, false otherwise.
|
|
268 |
*/
|
|
269 |
func isPrintableString(str string) bool {
|
|
270 |
for _, runeValue := range str {
|
|
271 |
if !strconv.IsPrint(runeValue) {
|
|
272 |
return false
|
|
273 |
}
|
|
274 |
}
|
|
275 |
return true
|
|
276 |
}
|
161 | 161 |
})
|
162 | 162 |
|
163 | 163 |
Describe("formatting []byte slices", func() {
|
164 | |
It("should present them as strings", func() {
|
165 | |
b := []byte("a\nb\nc")
|
166 | |
Ω(Object(b, 1)).Should(matchRegexp(`\[\]uint8 \| len:5, cap:\d+`, `a
|
167 | |
b
|
168 | |
c`))
|
169 | |
})
|
170 | |
})
|
|
164 |
Context("when the slice is made of printable bytes", func () {
|
|
165 |
It("should present it as string", func() {
|
|
166 |
b := []byte("a b c")
|
|
167 |
Ω(Object(b, 1)).Should(matchRegexp(`\[\]uint8 \| len:5, cap:\d+`, `a b c`))
|
|
168 |
})
|
|
169 |
})
|
|
170 |
Context("when the slice contains non-printable bytes", func () {
|
|
171 |
It("should present it as slice", func() {
|
|
172 |
b := []byte("a b c\n\x01\x02\x03\xff\x1bH")
|
|
173 |
Ω(Object(b, 1)).Should(matchRegexp(`\[\]uint8 \| len:12, cap:\d+`, `\[97, 32, 98, 32, 99, 10, 1, 2, 3, 255, 27, 72\]`))
|
|
174 |
})
|
|
175 |
})
|
|
176 |
})
|
171 | 177 |
|
172 | 178 |
Describe("formatting functions", func() {
|
173 | 179 |
It("should give the type and format values correctly", func() {
|
21 | 21 |
When Say succeeds, it fast forwards the gbytes.Buffer's read cursor to just after the succesful match.
|
22 | 22 |
Thus, subsequent calls to Say will only match against the unread portion of the buffer
|
23 | 23 |
|
24 | |
Say pairs very well with Eventually. To asser that a buffer eventually receives data matching "[123]-star" within 3 seconds you can:
|
|
24 |
Say pairs very well with Eventually. To assert that a buffer eventually receives data matching "[123]-star" within 3 seconds you can:
|
25 | 25 |
|
26 | 26 |
Eventually(buffer, 3).Should(Say("[123]-star"))
|
27 | 27 |
|
59 | 59 |
Ω(session).Should(gexec.Exit())
|
60 | 60 |
|
61 | 61 |
When the session exits it closes the stdout and stderr gbytes buffers. This will short circuit any
|
62 | |
Eventuallys waiting fo the buffers to Say something.
|
|
62 |
Eventuallys waiting for the buffers to Say something.
|
63 | 63 |
*/
|
64 | 64 |
func Start(command *exec.Cmd, outWriter io.Writer, errWriter io.Writer) (*Session, error) {
|
65 | 65 |
exited := make(chan struct{})
|
77 | 77 |
})
|
78 | 78 |
})
|
79 | 79 |
|
|
80 |
Describe("closing server mulitple times", func() {
|
|
81 |
It("should not fail", func() {
|
|
82 |
s.Close()
|
|
83 |
Ω(s.Close).ShouldNot(Panic())
|
|
84 |
})
|
|
85 |
})
|
|
86 |
|
80 | 87 |
Describe("allowing unhandled requests", func() {
|
81 | 88 |
Context("when true", func() {
|
82 | 89 |
BeforeEach(func() {
|