Skip to content

Commit

Permalink
update decide fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
jvitoroc committed Aug 11, 2024
1 parent 245c094 commit 6fe151b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 53 deletions.
38 changes: 19 additions & 19 deletions feature_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func TestFlagPersonProperty(t *testing.T) {

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-simple-flag-person-prop.json")))
}
Expand Down Expand Up @@ -329,7 +329,7 @@ func TestFlagGroup(t *testing.T) {
if !groupPropertiesEquality {
t.Errorf("Expected groupProperties to be map[company:map[name:Project Name 1]], got %s", reqBody.GroupProperties)
}
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-flag-group-properties.json")))
} else if strings.HasPrefix(r.URL.Path, "/batch/") {
Expand Down Expand Up @@ -415,7 +415,7 @@ func TestFlagGroupProperty(t *testing.T) {
func TestComplexDefinition(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-complex-definition.json"))) // Don't return anything for local eval
}
Expand Down Expand Up @@ -457,7 +457,7 @@ func TestComplexDefinition(t *testing.T) {
func TestFallbackToDecide(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte("{}")) // Don't return anything for local eval
}
Expand Down Expand Up @@ -563,7 +563,7 @@ func TestFeatureFlagsDontFallbackToDecideWhenOnlyLocalEvaluationIsTrue(t *testin
func TestFeatureFlagDefaultsDontHinderEvaluation(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-false.json")))
}
Expand Down Expand Up @@ -712,7 +712,7 @@ func TestExperienceContinuityOverride(t *testing.T) {
func TestGetAllFlags(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-multiple-flags.json")))
}
Expand All @@ -738,7 +738,7 @@ func TestGetAllFlags(t *testing.T) {
func TestGetAllFlagsEmptyLocal(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte("{}"))
}
Expand All @@ -764,7 +764,7 @@ func TestGetAllFlagsEmptyLocal(t *testing.T) {
func TestGetAllFlagsNoDecide(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-multiple-flags-valid.json")))
}
Expand All @@ -790,7 +790,7 @@ func TestGetAllFlagsNoDecide(t *testing.T) {
func TestGetAllFlagsOnlyLocalEvaluationSet(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-get-all-flags-with-fallback-but-only-local-evaluation-set.json")))
}
Expand All @@ -817,7 +817,7 @@ func TestGetAllFlagsOnlyLocalEvaluationSet(t *testing.T) {
func TestComputeInactiveFlagsLocally(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-compute-inactive-flags-locally.json")))
}
Expand All @@ -841,7 +841,7 @@ func TestComputeInactiveFlagsLocally(t *testing.T) {

server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-compute-inactive-flags-locally-2.json")))
}
Expand Down Expand Up @@ -890,7 +890,7 @@ func TestFeatureEnabledSimpleIsTrueWhenRolloutUndefined(t *testing.T) {
func TestGetFeatureFlag(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-simple-flag-person-prop.json")))
}
Expand Down Expand Up @@ -949,7 +949,7 @@ func TestFlagWithVariantOverrides(t *testing.T) {

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-variant-override.json")))
}
Expand Down Expand Up @@ -1013,7 +1013,7 @@ func TestFlagWithVariantOverrides(t *testing.T) {
func TestFlagWithClashingVariantOverrides(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-variant-override-clashing.json")))
}
Expand Down Expand Up @@ -1079,7 +1079,7 @@ func TestFlagWithClashingVariantOverrides(t *testing.T) {
func TestFlagWithInvalidVariantOverrides(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-variant-override-invalid.json")))
}
Expand Down Expand Up @@ -1143,7 +1143,7 @@ func TestFlagWithInvalidVariantOverrides(t *testing.T) {
func TestFlagWithMultipleVariantOverrides(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-variant-override-multiple.json")))
}
Expand Down Expand Up @@ -1229,7 +1229,7 @@ func TestFlagWithMultipleVariantOverrides(t *testing.T) {
func TestCaptureIsCalled(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-simple-flag-person-prop.json")))
}
Expand Down Expand Up @@ -4434,7 +4434,7 @@ func TestFlagWithTimeoutExceeded(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
time.Sleep(1 * time.Second)
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte(fixture("feature_flag/test-flag-group-properties.json")))
} else if strings.HasPrefix(r.URL.Path, "/batch/") {
Expand Down Expand Up @@ -4535,7 +4535,7 @@ func TestFlagDefinitionsWithTimeoutExceeded(t *testing.T) {

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
time.Sleep(11 * time.Second)
w.Write([]byte(fixture("feature_flag/test-flag-group-properties.json")))
Expand Down
71 changes: 39 additions & 32 deletions fixtures/test-decide-v3.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
{
"config": {
"enable_collect_everything": true
},
"editorParams": {},
"isAuthenticated": true,
"supportedCompression": [
"gzip",
"gzip-js",
"lz64"
],
"featureFlags": {
"enabled-flag": true,
"group-flag": true,
"disabled-flag": false,
"multi-variate-flag": "hello",
"simple-flag": true,
"beta-feature": "decide-fallback-value",
"beta-feature2": "variant-2",
"false-flag-2": false,
"test-get-feature": "variant-1",
"continuation-flag": true
},
"featureFlagPayloads": {
"enabled-flag": "{\"foo\": 1}",
"simple-flag": "{\"bar\": 2}",
"continuation-flag": "{\"foo\": \"bar\"}",
"beta-feature": "{\"foo\": \"bar\"}",
"test-get-feature": "this is a string",
"multi-variate-flag": "this is the payload"
},
"sessionRecording": false
}
"config": {
"enable_collect_everything": true
},
"editorParams": {},
"isAuthenticated": true,
"supportedCompression": ["gzip", "gzip-js", "lz64"],
"toolbarParams": {},
"featureFlags": {
"enabled-flag": true,
"group-flag": true,
"disabled-flag": false,
"multi-variate-flag": "hello",
"simple-flag": true,
"beta-feature": "decide-fallback-value",
"beta-feature2": "variant-2",
"false-flag-2": false,
"test-get-feature": "variant-1",
"continuation-flag": true
},
"featureFlagPayloads": {
"enabled-flag": "{\"foo\": 1}",
"simple-flag": "{\"bar\": 2}",
"continuation-flag": "{\"foo\": \"bar\"}",
"beta-feature": "{\"foo\": \"bar\"}",
"test-get-feature": "this is a string",
"multi-variate-flag": "this is the payload"
},
"sessionRecording": false,
"errorsWhileComputingFlags": false,
"capturePerformance": false,
"autocapture_opt_out": true,
"autocaptureExceptions": false,
"analytics": { "endpoint": "/i/v0/e/" },
"__preview_ingestion_endpoints": true,
"elementsChainAsString": true,
"surveys": false,
"heatmaps": false,
"siteApps": []
}
4 changes: 2 additions & 2 deletions posthog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ func TestGetFeatureFlagPayloadWithNoPersonalApiKey(t *testing.T) {
func TestGetFeatureFlagWithNoPersonalApiKey(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if !strings.HasPrefix(r.URL.Path, "/batch") {
t.Errorf("client called an endpoint it shouldn't have: %s", r.URL.Path)
}
Expand Down Expand Up @@ -1606,7 +1606,7 @@ func TestMultiVariateFlag(t *testing.T) {
func TestDisabledFlag(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/decide") {
w.Write([]byte(fixture("test-decide-v2.json")))
w.Write([]byte(fixture("test-decide-v3.json")))
} else if strings.HasPrefix(r.URL.Path, "/api/feature_flag/local_evaluation") {
w.Write([]byte("{}"))
} else if !strings.HasPrefix(r.URL.Path, "/batch") {
Expand Down

0 comments on commit 6fe151b

Please sign in to comment.