Tests in this file mutate os.Args and must NOT use t.Parallel().
(t *testing.T)
| 12 | // Tests in this file mutate os.Args and must NOT use t.Parallel(). |
| 13 | |
| 14 | func TestParseFlagsAndArgumentsWithEnv(t *testing.T) { |
| 15 | fs := flag.NewFlagSet("test", flag.ContinueOnError) |
| 16 | var host string |
| 17 | var port int |
| 18 | fs.StringVar(&host, "server.host", "localhost", "host") |
| 19 | fs.IntVar(&port, "server.port", 80, "port") |
| 20 | |
| 21 | origArgs := os.Args |
| 22 | t.Cleanup(func() { os.Args = origArgs }) |
| 23 | os.Args = []string{"cmd", "-server.host", "clihost"} |
| 24 | |
| 25 | t.Setenv("APP_SERVER_PORT", "9090") |
| 26 | |
| 27 | args, err := ParseFlagsAndArgumentsWithEnv(fs, "APP") |
| 28 | require.NoError(t, err) |
| 29 | assert.Empty(t, args) |
| 30 | assert.Equal(t, "clihost", host, "CLI flag should be used") |
| 31 | assert.Equal(t, 9090, port, "env var should set unset flag") |
| 32 | } |
| 33 | |
| 34 | func TestParseFlagsWithoutArgumentsWithEnv(t *testing.T) { |
| 35 | fs := flag.NewFlagSet("test", flag.ContinueOnError) |
nothing calls this directly
no test coverage detected