MCPcopy Create free account
hub / github.com/cli/cli / TestConfigFromEnv

Function TestConfigFromEnv

internal/debug/config_test.go:13–72  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestConfigFromEnv(t *testing.T) {
14 tests := []struct {
15 name string
16 env map[string]string
17 want DebugConfig
18 }{
19 {
20 name: "unset environment",
21 },
22 {
23 name: "configured overrides",
24 env: map[string]string{
25 "GH_INTERNAL_AT_EXPIRES_IN": "90",
26 "GH_INTERNAL_RT_EXPIRES_IN": "15552000",
27 "GH_INTERNAL_DEBUG_REFRESH_TOKEN": "1",
28 },
29 want: DebugConfig{
30 AccessTokenExpiresIn: o.Some(90 * time.Second),
31 RefreshTokenExpiresIn: o.Some(180 * 24 * time.Hour),
32 VerboseTokenRefresh: o.Some(true),
33 },
34 },
35 {
36 name: "zero and negative lifetimes are explicit overrides",
37 env: map[string]string{
38 "GH_INTERNAL_AT_EXPIRES_IN": "0",
39 "GH_INTERNAL_RT_EXPIRES_IN": "-1",
40 },
41 want: DebugConfig{
42 AccessTokenExpiresIn: o.Some(time.Duration(0)),
43 RefreshTokenExpiresIn: o.Some(-time.Second),
44 },
45 },
46 {
47 name: "zero explicitly disables verbose logging",
48 env: map[string]string{"GH_INTERNAL_DEBUG_REFRESH_TOKEN": "0"},
49 want: DebugConfig{VerboseTokenRefresh: o.Some(false)},
50 },
51 {
52 name: "false explicitly disables verbose logging",
53 env: map[string]string{"GH_INTERNAL_DEBUG_REFRESH_TOKEN": "false"},
54 want: DebugConfig{VerboseTokenRefresh: o.Some(false)},
55 },
56 {
57 name: "true explicitly enables verbose logging",
58 env: map[string]string{"GH_INTERNAL_DEBUG_REFRESH_TOKEN": "true"},
59 want: DebugConfig{VerboseTokenRefresh: o.Some(true)},
60 },
61 }
62 for _, tt := range tests {
63 t.Run(tt.name, func(t *testing.T) {
64 clearConfigEnv(t)
65 for key, value := range tt.env {
66 t.Setenv(key, value)
67 }
68
69 assert.Equal(t, tt.want, configFromEnv())
70 })

Callers

nothing calls this directly

Calls 5

clearConfigEnvFunction · 0.85
configFromEnvFunction · 0.85
DurationMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected