-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain_background_env_test.go
More file actions
42 lines (36 loc) · 1.17 KB
/
Copy pathmain_background_env_test.go
File metadata and controls
42 lines (36 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import "testing"
func TestEnabledEnv(t *testing.T) {
t.Run("unset returns default", func(t *testing.T) {
t.Setenv("ELASTICKV_TEST_BOOL_ENV", "")
if !enabledEnv("ELASTICKV_TEST_BOOL_ENV") {
t.Fatal("enabledEnv() = false, want true")
}
})
t.Run("false disables default true", func(t *testing.T) {
t.Setenv("ELASTICKV_TEST_BOOL_ENV", "false")
if enabledEnv("ELASTICKV_TEST_BOOL_ENV") {
t.Fatal("enabledEnv() = true, want false")
}
})
t.Run("invalid returns default", func(t *testing.T) {
t.Setenv("ELASTICKV_TEST_BOOL_ENV", "maybe")
if !enabledEnv("ELASTICKV_TEST_BOOL_ENV") {
t.Fatal("enabledEnv() = false, want true")
}
})
}
func TestRedisDeltaCompactorEnv(t *testing.T) {
t.Run("default enabled", func(t *testing.T) {
t.Setenv(redisDeltaCompactorEnabledEnvVar, "")
if newRedisDeltaCompactorIfEnabled(nil, nil) == nil {
t.Fatal("newRedisDeltaCompactorIfEnabled() = nil, want compactor")
}
})
t.Run("false disables", func(t *testing.T) {
t.Setenv(redisDeltaCompactorEnabledEnvVar, "false")
if newRedisDeltaCompactorIfEnabled(nil, nil) != nil {
t.Fatal("newRedisDeltaCompactorIfEnabled() returned compactor, want nil")
}
})
}