MCPcopy
hub / github.com/grafana/dskit / TestParseFlagsAndArgumentsWithEnv_CLIPrecedence

Function TestParseFlagsAndArgumentsWithEnv_CLIPrecedence

flagext/parse_test.go:66–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

64}
65
66func TestParseFlagsAndArgumentsWithEnv_CLIPrecedence(t *testing.T) {
67 fs := flag.NewFlagSet("test", flag.ContinueOnError)
68 var port int
69 fs.IntVar(&port, "port", 80, "port")
70
71 origArgs := os.Args
72 t.Cleanup(func() { os.Args = origArgs })
73 os.Args = []string{"cmd", "-port", "3000"}
74
75 t.Setenv("APP_PORT", "9090")
76
77 _, err := ParseFlagsAndArgumentsWithEnv(fs, "APP")
78 require.NoError(t, err)
79 assert.Equal(t, 3000, port, "CLI flag should take precedence over env var")
80}
81
82func TestParseFlagsAndArgumentsWithEnv_EnvError(t *testing.T) {
83 fs := flag.NewFlagSet("test", flag.ContinueOnError)

Callers

nothing calls this directly

Calls 2

EqualMethod · 0.45

Tested by

no test coverage detected