-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathflags_test.go
More file actions
68 lines (53 loc) · 1.92 KB
/
flags_test.go
File metadata and controls
68 lines (53 loc) · 1.92 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
61
62
63
64
65
66
67
68
package main
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
"codeberg.org/gpanders/ijq/internal/options"
)
func TestUsageHidesLegacyFlags(t *testing.T) {
opts := options.Options{}
var out bytes.Buffer
flagSet, _, _ := newFlagSet("ijq", &opts, &out)
flagSet.Usage()
help := out.String()
assert.Contains(t, help, "-c")
assert.Contains(t, help, "-f")
assert.NotContains(t, help, "-H")
assert.NotContains(t, help, "-jqbin")
assert.NotContains(t, help, "-hide-input-pane")
}
func TestLegacyFlagsRemainSupported(t *testing.T) {
opts := options.Options{}
var out bytes.Buffer
flagSet, _, _ := newFlagSet("ijq", &opts, &out)
err := flagSet.Parse([]string{"-H", "", "-jqbin", "custom-jq", "-hide-input-pane"})
assert.NoError(t, err)
assert.Equal(t, options.HistoryFile(""), opts.HistoryFile)
assert.Equal(t, options.JQCommand("custom-jq"), opts.JQCommand)
assert.Equal(t, options.HideInputPane(true), opts.HideInputPane)
}
func TestLibraryPathsFromConfigAndFlags(t *testing.T) {
opts := options.Options{
LibraryPaths: options.LibraryPaths{"/config/modules"},
}
var out bytes.Buffer
flagSet, _, _ := newFlagSet("ijq", &opts, &out)
err := flagSet.Parse([]string{"-L", "/cli/modules"})
assert.NoError(t, err)
assert.Equal(t, options.LibraryPaths{"/config/modules", "/cli/modules"}, opts.LibraryPaths)
}
func TestLegacyFlagsOverrideConfigValues(t *testing.T) {
opts := options.Options{
HistoryFile: options.HistoryFile("/config/history"),
JQCommand: options.JQCommand("/usr/bin/jq"),
HideInputPane: options.HideInputPane(false),
}
var out bytes.Buffer
flagSet, _, _ := newFlagSet("ijq", &opts, &out)
err := flagSet.Parse([]string{"-H", "", "-jqbin", "custom-jq", "-hide-input-pane"})
assert.NoError(t, err)
assert.Equal(t, options.HistoryFile(""), opts.HistoryFile)
assert.Equal(t, options.JQCommand("custom-jq"), opts.JQCommand)
assert.Equal(t, options.HideInputPane(true), opts.HideInputPane)
}