-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
47 lines (39 loc) · 1.16 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
package main_test
import (
"bytes"
"fmt"
. "github.com/kkrull/gohttp"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("GoHTTP", func() {
Describe("#Run", func() {
var (
gohttp *GoHTTP
parser *CommandParserMock
command *CliCommandMock
stderr *bytes.Buffer
)
BeforeEach(func() {
command = &CliCommandMock{}
parser = &CommandParserMock{ParseReturns: command}
gohttp = &GoHTTP{CommandParser: parser, Stderr: stderr}
})
It("parses a command from the given arguments", func() {
gohttp.Run([]string{"save", "world"})
parser.ParseShouldHaveReceived([]string{"save", "world"})
})
It("runs the command", func() {
gohttp.Run(nil)
command.RunShouldHaveReceived(stderr)
})
It("returns the exit code and any error from running the command", func() {
command := &CliCommandMock{RunReturnsCode: 42, RunReturnsError: fmt.Errorf("bang")}
parser = &CommandParserMock{ParseReturns: command}
gohttp = &GoHTTP{CommandParser: parser, Stderr: stderr}
exitCode, returnedRunErr := gohttp.Run(nil)
Expect(exitCode).To(Equal(42))
Expect(returnedRunErr).To(BeIdenticalTo(command.RunReturnsError))
})
})
})