-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflag_format_test.go
88 lines (73 loc) · 2.06 KB
/
flag_format_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
package cli_test
import (
"github.com/phogolabs/cli"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Format", func() {
var (
flag *cli.StringFlag
)
BeforeEach(func() {
flag = &cli.StringFlag{
Name: "log-level, l",
Path: "logger.conf",
Usage: "Application log level",
EnvVar: "LOG_LEVEL, LOG_LVL",
Value: "info",
}
})
It("formats a flag successfully", func() {
help := cli.FlagFormat(flag)
Expect(help).To(Equal("--log-level value, -l value\tApplication log level (default: info) [$LOG_LEVEL, $LOG_LVL] [logger.conf]"))
})
Context("when the Path is not set", func() {
BeforeEach(func() {
flag.Path = ""
})
It("formats a flag successfully", func() {
help := cli.FlagFormat(flag)
Expect(help).To(Equal("--log-level value, -l value\tApplication log level (default: info) [$LOG_LEVEL, $LOG_LVL]"))
})
})
Context("when the EnvVar is not set", func() {
BeforeEach(func() {
flag.EnvVar = ""
})
It("formats a flag successfully", func() {
help := cli.FlagFormat(flag)
Expect(help).To(Equal("--log-level value, -l value\tApplication log level (default: info) [logger.conf]"))
})
})
Context("when the value is boolean", func() {
var flag *cli.BoolFlag
BeforeEach(func() {
flag = &cli.BoolFlag{
Name: "log-level, l",
Path: "logger.conf",
Usage: "Application log level",
EnvVar: "LOG_LEVEL, LOG_LVL",
Value: true,
}
})
It("formats a flag successfully", func() {
help := cli.FlagFormat(flag)
Expect(help).To(Equal("--log-level, -l\tApplication log level [$LOG_LEVEL, $LOG_LVL] [logger.conf]"))
})
})
Context("when the value is nil", func() {
var flag *cli.YAMLFlag
BeforeEach(func() {
flag = &cli.YAMLFlag{
Name: "log-level, l",
Path: "logger.conf",
Usage: "Application log level",
EnvVar: "LOG_LEVEL, LOG_LVL",
}
})
It("formats a flag successfully", func() {
help := cli.FlagFormat(flag)
Expect(help).To(Equal("--log-level value, -l value\tApplication log level [$LOG_LEVEL, $LOG_LVL] [logger.conf]"))
})
})
})