-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathusage_test.go
More file actions
60 lines (50 loc) · 2.23 KB
/
usage_test.go
File metadata and controls
60 lines (50 loc) · 2.23 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
49
50
51
52
53
54
55
56
57
58
59
60
package mcli
import (
"bytes"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestQuoteUsageName(t *testing.T) {
app := NewApp()
var args struct {
Arg1 string `cli:"-a, this is escaped quoted words \\'not name\\' and this is the 'name' and more quoted words \\'actually no need to quote this\\'"`
Arg2 string "cli:\"-b, using backtick to quote name `value` some more description\""
Arg3 time.Duration "cli:\"-c, only one backtick, `some thing, using type name\""
}
app.AddRoot(func(ctx *Context) {
ctx.Parse(&args)
ctx.PrintHelp()
})
var buf bytes.Buffer
app.getFlagSet().SetOutput(&buf)
defer mockOSArgs("run")()
app.Run()
got := buf.String()
assert.Contains(t, got, `-a <name> this is escaped quoted words 'not name' and this is the name and more quoted words 'actually no need to quote this'`)
assert.Contains(t, got, "-b <value> using backtick to quote name value some more description")
assert.Contains(t, got, "-c <duration> only one backtick, `some thing, using type name")
}
func TestUsageEnvVariables(t *testing.T) {
app := NewApp()
var args struct {
CNServiceSecret string `mcli:"#E, CN service account secret blah blahblah blah blahblahblah" env:"CN_SERVICE_BEARER_SECRET"`
I18NServiceSecret string `mcli:"#E, I18N service account secret" env:"I18N_SERVICE_BEARER_SECRET"`
CNPersonalSecret string `mcli:"#E, CN personal account secret" env:"CN_PERSON_BEARER_SECRET"`
I18NPersonalSecret string `mcli:"#E, I18N personal account secret" env:"I18N_PERSON_BEARER_SECRET"`
}
app.AddRoot(func(ctx *Context) {
ctx.MustParse(&args)
ctx.PrintHelp()
})
var buf bytes.Buffer
app.getFlagSet().SetOutput(&buf)
defer mockOSArgs("run")()
app.Run()
got := buf.String()
assert.Contains(t, got, "Usage:\n run\n\nEnvironment Variables:\n")
assert.Contains(t, got, " - CN_SERVICE_BEARER_SECRET <string>\n CN service account secret blah blahblah blah blahblahblah\n")
assert.Contains(t, got, " - I18N_SERVICE_BEARER_SECRET <string>\n I18N service account secret\n")
assert.Contains(t, got, " - CN_PERSON_BEARER_SECRET <string>\n CN personal account secret\n")
assert.Contains(t, got, " - I18N_PERSON_BEARER_SECRET <string>\n I18N personal account secret\n\n")
}