返回 DeepSeek-Reasonix
policy_test.go
根目录 / internal / telemetry / policy_test.go
1 package telemetry
2
3 import "testing"
4
5 func clearPolicyEnv(t *testing.T) {
6 t.Helper()
7 for _, key := range []string{
8 "DO_NOT_TRACK", "REASONIX_TELEMETRY", "CI", "CONTINUOUS_INTEGRATION",
9 "GITHUB_ACTIONS", "GITLAB_CI", "BUILDKITE", "CIRCLECI", "JENKINS_URL",
10 "TEAMCITY_VERSION", "TF_BUILD",
11 } {
12 t.Setenv(key, "")
13 }
14 }
15
16 func TestEnabledPolicy(t *testing.T) {
17 clearPolicyEnv(t)
18 if !Enabled("auto", "v1.20.0", true) {
19 t.Fatal("auto should enable a release build on an interactive terminal")
20 }
21 if Enabled("auto", "v1.20.0", false) {
22 t.Fatal("auto should disable headless execution")
23 }
24 if !Enabled("on", "v1.20.0", false) {
25 t.Fatal("on should permit a local headless release run")
26 }
27 for _, tc := range []struct {
28 name string
29 mode string
30 version string
31 }{
32 {name: "off", mode: "off", version: "v1.20.0"},
33 {name: "development", mode: "on", version: "dev"},
34 {name: "test version", mode: "on", version: "test-version"},
35 } {
36 t.Run(tc.name, func(t *testing.T) {
37 if Enabled(tc.mode, tc.version, true) {
38 t.Fatal("policy unexpectedly enabled telemetry")
39 }
40 })
41 }
42 }
43
44 func TestEnabledHonorsEnvironmentOptOuts(t *testing.T) {
45 clearPolicyEnv(t)
46 for _, tc := range []struct{ key, value string }{
47 {key: "DO_NOT_TRACK", value: "1"},
48 {key: "REASONIX_TELEMETRY", value: "0"},
49 {key: "CI", value: "true"},
50 {key: "GITHUB_ACTIONS", value: "1"},
51 } {
52 t.Run(tc.key, func(t *testing.T) {
53 clearPolicyEnv(t)
54 t.Setenv(tc.key, tc.value)
55 if Enabled("on", "v1.20.0", true) {
56 t.Fatal("environment opt-out was ignored")
57 }
58 })
59 }
60 }
61
61 lines GO