-
Notifications
You must be signed in to change notification settings - Fork 11
/
command_test.go
54 lines (42 loc) · 953 Bytes
/
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
package gounit
import (
"bytes"
"flag"
"io"
"strings"
"testing"
)
type testCmd string
func (t testCmd) Description() string {
return string(t)
}
func (t testCmd) Usage() string {
return string(t)
}
func (t testCmd) Run(args []string, out, err io.Writer) error {
return nil
}
func (t testCmd) FlagSet() *flag.FlagSet {
return flag.NewFlagSet("testcmd", flag.ContinueOnError)
}
func TestRegisterCommand(t *testing.T) {
RegisterCommand("gen", testCmd("gen"))
_, ok := commands["gen"]
if !ok {
t.Fatalf("\"gen\" key is not present in the commands map")
}
}
func TestGetCommand(t *testing.T) {
commands["gen"] = testCmd("gen")
if GetCommand("gen") == nil {
t.Fatalf("expected non-nil value")
}
}
func TestUsage(t *testing.T) {
commands["_generate_"] = testCmd("gen")
b := bytes.NewBuffer([]byte{})
Usage(b)
if !strings.Contains(b.String(), "_generate_") {
t.Fatalf("no _generate_ command name found in the output")
}
}