MCPcopy
hub / github.com/etcd-io/etcd / TestSetFlagsFromEnv

Function TestSetFlagsFromEnv

pkg/flags/flag_test.go:27–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestSetFlagsFromEnv(t *testing.T) {
28 fs := flag.NewFlagSet("testing", flag.ExitOnError)
29 fs.String("a", "", "")
30 fs.String("b", "", "")
31 fs.String("c", "", "")
32 fs.Parse([]string{})
33
34 // flags should be settable using env vars
35 t.Setenv("ETCD_A", "foo")
36 // and command-line flags
37 require.NoError(t, fs.Set("b", "bar"))
38
39 // first verify that flags are as expected before reading the env
40 for f, want := range map[string]string{
41 "a": "",
42 "b": "bar",
43 } {
44 got := fs.Lookup(f).Value.String()
45 require.Equalf(t, want, got, "flag %q=%q, want %q", f, got, want)
46 }
47
48 // now read the env and verify flags were updated as expected
49 require.NoError(t, SetFlagsFromEnv(zaptest.NewLogger(t), "ETCD", fs))
50 for f, want := range map[string]string{
51 "a": "foo",
52 "b": "bar",
53 } {
54 got := fs.Lookup(f).Value.String()
55 assert.Equalf(t, want, got, "flag %q=%q, want %q", f, got, want)
56 }
57}
58
59func TestSetFlagsFromEnvBad(t *testing.T) {
60 // now verify that an error is propagated

Callers

nothing calls this directly

Calls 5

SetFlagsFromEnvFunction · 0.85
ParseMethod · 0.80
StringMethod · 0.65
SetMethod · 0.65
LookupMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…