-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathx_glean_test.go
More file actions
92 lines (76 loc) · 2.41 KB
/
Copy pathx_glean_test.go
File metadata and controls
92 lines (76 loc) · 2.41 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package apiclientgo
import (
"os"
"testing"
"github.com/gleanwork/api-client-go/internal/hooks"
)
func TestWithExcludeDeprecatedAfter(t *testing.T) {
sdk := New(
WithExcludeDeprecatedAfter("2026-10-15"),
)
config := hooks.GetXGleanConfig(sdk)
if config.ExcludeDeprecatedAfter != "2026-10-15" {
t.Errorf("expected ExcludeDeprecatedAfter to be '2026-10-15', got '%s'", config.ExcludeDeprecatedAfter)
}
}
func TestWithIncludeExperimental(t *testing.T) {
sdk := New(
WithIncludeExperimental(true),
)
config := hooks.GetXGleanConfig(sdk)
if !config.IncludeExperimental {
t.Error("expected IncludeExperimental to be true")
}
}
func TestWithBothOptions(t *testing.T) {
sdk := New(
WithExcludeDeprecatedAfter("2026-10-15"),
WithIncludeExperimental(true),
)
config := hooks.GetXGleanConfig(sdk)
if config.ExcludeDeprecatedAfter != "2026-10-15" {
t.Errorf("expected ExcludeDeprecatedAfter to be '2026-10-15', got '%s'", config.ExcludeDeprecatedAfter)
}
if !config.IncludeExperimental {
t.Error("expected IncludeExperimental to be true")
}
}
func TestWithIncludeExperimentalFalse(t *testing.T) {
sdk := New(
WithIncludeExperimental(false),
)
config := hooks.GetXGleanConfig(sdk)
if config.IncludeExperimental {
t.Error("expected IncludeExperimental to be false")
}
}
func TestMultipleSDKInstances(t *testing.T) {
sdk1 := New(
WithExcludeDeprecatedAfter("2026-01-01"),
)
sdk2 := New(
WithExcludeDeprecatedAfter("2027-12-31"),
)
config1 := hooks.GetXGleanConfig(sdk1)
config2 := hooks.GetXGleanConfig(sdk2)
if config1.ExcludeDeprecatedAfter != "2026-01-01" {
t.Errorf("sdk1: expected ExcludeDeprecatedAfter to be '2026-01-01', got '%s'", config1.ExcludeDeprecatedAfter)
}
if config2.ExcludeDeprecatedAfter != "2027-12-31" {
t.Errorf("sdk2: expected ExcludeDeprecatedAfter to be '2027-12-31', got '%s'", config2.ExcludeDeprecatedAfter)
}
}
func TestEnvironmentVariablesAreRead(t *testing.T) {
// This test verifies that the hook reads environment variables
// The actual precedence is tested in the hooks package
// Set environment variables
os.Setenv("X_GLEAN_EXCLUDE_DEPRECATED_AFTER", "2028-06-01")
os.Setenv("X_GLEAN_INCLUDE_EXPERIMENTAL", "true")
defer os.Unsetenv("X_GLEAN_EXCLUDE_DEPRECATED_AFTER")
defer os.Unsetenv("X_GLEAN_INCLUDE_EXPERIMENTAL")
// SDK can be created without error when env vars are set
sdk := New()
if sdk == nil {
t.Error("expected SDK to be created")
}
}