-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathmain_test.go
More file actions
48 lines (36 loc) · 1.18 KB
/
main_test.go
File metadata and controls
48 lines (36 loc) · 1.18 KB
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
package main
import (
"bytes"
"regexp"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAppHasAllCommands(t *testing.T) {
app := newApp(&bytes.Buffer{}, &bytes.Buffer{})
require.NotNil(t, app)
assert.Equal(t, "step", app.Name)
assert.Equal(t, "step", app.HelpName)
var names = make([]string, 0, len(app.Commands))
for _, c := range app.Commands {
names = append(names, c.Name)
}
assert.ElementsMatch(t, []string{
"help", "api", "path", "base64", "fileserver",
"certificate", "completion", "context", "crl",
"crypto", "oauth", "version", "ca", "beta", "ssh",
}, names)
}
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
var ansiRegex = regexp.MustCompile(ansi)
func TestAppRuns(t *testing.T) {
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
app := newApp(stdout, stderr)
require.NotNil(t, app)
err := app.Run([]string{"step"})
require.NoError(t, err)
require.Empty(t, stderr.Bytes())
output := ansiRegex.ReplaceAllString(stdout.String(), "")
assert.Contains(t, output, "step -- plumbing for distributed systems")
}