MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestFlagParsing

Function TestFlagParsing

cmd/cortex/main_test.go:16–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestFlagParsing(t *testing.T) {
17 for name, tc := range map[string]struct {
18 arguments []string
19 yaml string
20 stdoutMessage string // string that must be included in stdout
21 stderrMessage string // string that must be included in stderr
22 stdoutExcluded string // string that must NOT be included in stdout
23 stderrExcluded string // string that must NOT be included in stderr
24 }{
25 "help": {
26 arguments: []string{"-h"},
27 stdoutMessage: "Usage of", // Usage must be on stdout, not stderr.
28 stderrExcluded: "Usage of",
29 },
30
31 "unknown flag": {
32 arguments: []string{"-unknown.flag"},
33 stderrMessage: "Run with -help to get list of available parameters",
34 stdoutExcluded: "Usage of", // No usage description on unknown flag.
35 stderrExcluded: "Usage of",
36 },
37
38 "new flag, with config": {
39 arguments: []string{"-mem-ballast-size-bytes=100000"},
40 yaml: "target: ingester",
41 stdoutMessage: "target: ingester",
42 },
43
44 "default values": {
45 stderrMessage: "please set configuration file. For example: -config.file=./docs/configuration/single-process-config-blocks-local.yaml\n",
46 },
47
48 "config": {
49 yaml: "target: ingester",
50 stdoutMessage: "target: ingester\n",
51 },
52
53 "config with expand-env": {
54 arguments: []string{"-config.expand-env"},
55 yaml: "target: $TARGET",
56 stdoutMessage: "target: ingester\n",
57 },
58
59 "config with arguments override": {
60 yaml: "target: ingester",
61 arguments: []string{"-target=distributor"},
62 stdoutMessage: "target: distributor\n",
63 },
64
65 "user visible module listing": {
66 arguments: []string{"-modules"},
67 stdoutMessage: "ingester *\n",
68 stderrExcluded: "ingester\n",
69 },
70
71 "user visible module listing flag take precedence over target flag": {
72 arguments: []string{"-modules", "-target=blah"},
73 stdoutMessage: "ingester *\n",

Callers

nothing calls this directly

Calls 2

testSingleFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected