Repository navigation
Expand file tree
/
Copy pathfeature_flags_failed_telemetry_test.go
More file actions
63 lines (58 loc) · 2.56 KB
/
Copy pathfeature_flags_failed_telemetry_test.go
File metadata and controls
63 lines (58 loc) · 2.56 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
package posthog
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestPollerFailedFlagTelemetryRetainsResponseErrors(t *testing.T) {
for _, globalError := range []string{"true", "false", "absent"} {
for _, inconclusive := range []bool{false, true} {
for _, variant := range []string{"null", `"placeholder"`} {
name := globalError + "/missing-local/" + variant
definitions := localDefinitions()
if inconclusive {
name = globalError + "/inconclusive-local/" + variant
definitions = localDefinitions(continuityCheckoutDefinition)
}
t.Run(name, func(t *testing.T) {
globalField := ""
if globalError != "absent" {
globalField = `"errorsWhileComputingFlags":` + globalError + `,`
}
remote := `{` + globalField + `"flags":{"checkout":{"key":"checkout","enabled":false,"variant":` + variant + `,"failed":true,"metadata":{"payload":"\"remote\""}},"healthy":{"key":"healthy","enabled":false,"failed":false}}}`
client, capture, _ := newUnresolvedFlagsClient(t, definitions, remote)
config := FeatureFlagPayload{Key: "checkout", DistinctId: "person"}
for i := 0; i < 2; i++ {
result, err := client.GetFeatureFlagResult(config)
require.Nil(t, result)
require.ErrorIs(t, err, ErrFlagNotFound)
}
expected := FeatureFlagErrorEvaluationFailed
if globalError == "true" {
expected = FeatureFlagErrorErrorsWhileComputing + "," + expected
}
require.Equal(t, expected, flagCalledError(t, client, capture, "checkout"))
events := snapshotCapturedEvents(capture)
require.Equal(t, 1, countFlagCalledEvents(events, "checkout"))
require.Nil(t, findEvent(events, "$feature_flag_called", "checkout").Properties["$feature_flag_response"])
config.DistinctId = "suppressed"
config.SendFeatureFlagEvents = Ptr(false)
result, err := client.GetFeatureFlagResult(config)
require.Nil(t, result)
require.ErrorIs(t, err, ErrFlagNotFound)
flushEvaluationEvents(t, client)
require.Equal(t, 1, countFlagCalledEvents(snapshotCapturedEvents(capture), "checkout"))
healthy, err := client.GetFeatureFlagResult(FeatureFlagPayload{Key: "healthy", DistinctId: "person"})
require.NoError(t, err)
require.False(t, healthy.Enabled)
healthyError := flagCalledError(t, client, capture, "healthy")
require.NotContains(t, healthyError, FeatureFlagErrorEvaluationFailed)
if globalError == "true" {
require.Equal(t, FeatureFlagErrorErrorsWhileComputing, healthyError)
} else {
require.Empty(t, healthyError)
}
})
}
}
}
}