-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_suite_test.go
45 lines (36 loc) · 998 Bytes
/
main_suite_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
package main_test
import (
"io"
"testing"
"github.com/kkrull/gohttp/main/cmd"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestMain(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "main")
}
type CliCommandMock struct {
RunReturnsCode int
RunReturnsError error
runStderr io.Writer
}
func (mock *CliCommandMock) Run(stderr io.Writer) (code int, err error) {
mock.runStderr = stderr
return mock.RunReturnsCode, mock.RunReturnsError
}
func (mock *CliCommandMock) RunShouldHaveReceived(stderr io.Writer) {
ExpectWithOffset(1, mock.runStderr).To(BeIdenticalTo(stderr))
}
type CommandParserMock struct {
ParseReturns cmd.CliCommand
parseArgs []string
}
func (mock *CommandParserMock) Parse(args []string) cmd.CliCommand {
mock.parseArgs = make([]string, len(args))
copy(mock.parseArgs, args)
return mock.ParseReturns
}
func (mock *CommandParserMock) ParseShouldHaveReceived(args []string) {
ExpectWithOffset(1, mock.parseArgs).To(Equal(args))
}