-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
53 lines (41 loc) · 1.11 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
package main
import (
"fmt"
"os"
"os/exec"
"testing"
"github.com/stretchr/testify/assert"
)
func buildTestExecutable() ([]byte, error) {
command := exec.Command("go", "build", "-o", "test-trello-cli")
output, err := command.CombinedOutput()
return output, err
}
func removeExecutable() {
os.Remove("gosdnc")
}
func checkCmdErr(test *testing.T, err error, output []byte) {
if err != nil {
fmt.Printf("Error: %s \n Output: %s", err, string(output))
test.FailNow()
}
}
func TestMain(t *testing.T) {
defer removeExecutable()
output, err := buildTestExecutable()
checkCmdErr(t, err, output)
runCommand := exec.Command("./test-trello-cli", "help")
expectedOutput := `
trello-cli [command] [options]
commands:
context - Set context for other commands.
list - Print board and card ids.
recurring - Print or add recurring todo's.
shopping-list - Interact with your shopping-list.
todo - Print current todo's.
version - Print current version.
`
output, err = runCommand.CombinedOutput()
checkCmdErr(t, err, output)
assert.Equal(t, expectedOutput, string(output), "they should be equal")
}