-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
32 lines (27 loc) · 726 Bytes
/
main_test.go
File metadata and controls
32 lines (27 loc) · 726 Bytes
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
package main
import (
"io"
"os"
"testing"
"github.com/stretchr/testify/assert"
"go.octolab.org/safe"
)
func TestExecution(t *testing.T) {
t.Run("success", func(t *testing.T) {
exit = func(code int) { assert.Equal(t, 0, code) }
stderr, stdout = io.Discard, io.Discard
os.Args = []string{"root", "version"}
main()
})
t.Run("failure", func(t *testing.T) {
exit = func(code int) { assert.Equal(t, 1, code) }
stderr, stdout = io.Discard, io.Discard
os.Args = []string{"root", "unknown"}
main()
})
t.Run("shutdown with panic", func(t *testing.T) {
exit = func(code int) { assert.Equal(t, 1, code) }
stderr, stdout = io.Discard, io.Discard
safe.Do(func() error { panic("test") }, shutdown)
})
}