Skip to content

Commit abb8e9b

Browse files
authored
Merge pull request #5546 from thaJeztah/hints_coverage
cli/hints: add tests
2 parents 7029147 + 87acf77 commit abb8e9b

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

cli/hints/hints.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"strconv"
66
)
77

8-
// Enabled returns whether cli hints are enabled or not
8+
// Enabled returns whether cli hints are enabled or not. Hints are enabled by
9+
// default, but can be disabled through the "DOCKER_CLI_HINTS" environment
10+
// variable.
911
func Enabled() bool {
1012
if v := os.Getenv("DOCKER_CLI_HINTS"); v != "" {
1113
enabled, err := strconv.ParseBool(v)

cli/hints/hints_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package hints
2+
3+
import (
4+
"testing"
5+
6+
"gotest.tools/v3/assert"
7+
)
8+
9+
func TestEnabled(t *testing.T) {
10+
tests := []struct {
11+
doc string
12+
env string
13+
expected bool
14+
}{
15+
{
16+
doc: "default",
17+
expected: true,
18+
},
19+
{
20+
doc: "DOCKER_CLI_HINTS=1",
21+
env: "1",
22+
expected: true,
23+
},
24+
{
25+
doc: "DOCKER_CLI_HINTS=true",
26+
env: "true",
27+
expected: true,
28+
},
29+
{
30+
doc: "DOCKER_CLI_HINTS=0",
31+
env: "0",
32+
expected: false,
33+
},
34+
{
35+
doc: "DOCKER_CLI_HINTS=false",
36+
env: "false",
37+
expected: false,
38+
},
39+
{
40+
doc: "DOCKER_CLI_HINTS=not-a-bool",
41+
env: "not-a-bool",
42+
expected: true,
43+
},
44+
}
45+
46+
for _, tc := range tests {
47+
t.Run(tc.doc, func(t *testing.T) {
48+
t.Setenv("DOCKER_CLI_HINTS", tc.env)
49+
assert.Equal(t, Enabled(), tc.expected)
50+
})
51+
}
52+
}

0 commit comments

Comments
 (0)