-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_test.go
102 lines (76 loc) · 2.11 KB
/
command_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
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
package main
import (
"bytes"
"io"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func Test_Main(t *testing.T) {
os.Args = []string{"augurken", "--help"}
exitFn = func(code int) { assert.Equal(t, 0, code) }
r, w, _ := os.Pipe()
os.Stdout = w
main()
_ = w.Close()
buf := new(bytes.Buffer)
_ = r.SetReadDeadline(time.Now().Add(time.Second))
_, _ = io.Copy(buf, r)
assert.Contains(t, buf.String(), "Usage:")
assert.Contains(t, buf.String(), "Available Commands:")
assert.Contains(t, buf.String(), "Flags:")
}
func Test_MainWithoutCommands(t *testing.T) {
os.Args = []string{"augurken"}
exitFn = func(code int) { assert.Equal(t, 0, code) }
r, w, _ := os.Pipe()
os.Stdout = w
main()
buf := new(bytes.Buffer)
_ = r.SetReadDeadline(time.Now().Add(time.Second))
_, _ = io.Copy(buf, r)
assert.Contains(t, buf.String(), "Usage:")
assert.Contains(t, buf.String(), "Available Commands:")
assert.Contains(t, buf.String(), "Flags:")
}
func Test_MainUnknownSubcommand(t *testing.T) {
os.Args = []string{"", "foobar"}
exitFn = func(code int) { assert.Equal(t, 1, code) }
r, w, _ := os.Pipe()
os.Stderr = w
main()
_ = w.Close()
buf := new(bytes.Buffer)
_ = r.SetReadDeadline(time.Now().Add(time.Second))
_, _ = io.Copy(buf, r)
assert.Contains(t, buf.String(), "unknown command")
assert.Contains(t, buf.String(), "foobar")
}
func Test_MainCheckFolderError(t *testing.T) {
content := []byte(`Feature: test
test
Scenario: scenario1
Given whatever
Then whatever
"""
hello world
"""
`)
assert.NoError(t, os.RemoveAll("tmp/"))
assert.NoError(t, os.MkdirAll("tmp/", 0o777))
assert.NoError(t, os.WriteFile("tmp/file1.feature", content, 0o600))
// Set up the command
os.Args = []string{"augurken", "check", "tmp"}
exitFn = func(code int) { assert.Equal(t, 1, code) }
r, w, _ := os.Pipe()
os.Stderr = w
main()
_ = w.Close()
buf := new(bytes.Buffer)
_ = r.SetReadDeadline(time.Now().Add(time.Second))
_, _ = io.Copy(buf, r)
assert.Contains(t, buf.String(), "Error: error occurred while formatting file/folder")
// Clean up
_ = os.RemoveAll("tmp/")
}