Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize properties map when sending feature flags #26

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions posthog.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ func (c *client) Enqueue(msg Message) (err error) {
if err != nil {
c.Errorf("unable to get feature variants - %s", err)
}

if m.Properties == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch, thanks @zaynetro , could you please also add a testcase for sendFeatureFlags in capture?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test

m.Properties = NewProperties()
}

for feature, variant := range featureVariants {
propKey := fmt.Sprintf("$feature/%s", feature)
m.Properties[propKey] = variant
Expand Down
38 changes: 38 additions & 0 deletions posthog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,3 +929,41 @@ func TestDisabledFlag(t *testing.T) {
t.Errorf("flag listed in /decide/ response should have value 'false'")
}
}

func TestCaptureSendFlags(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(fixture("test-api-feature-flag.json")))
}))
defer server.Close()

client, _ := NewWithConfig("Csyjlnlun3OzyNJAafdlv", Config{
Endpoint: server.URL,
Verbose: true,
Logger: t,
BatchSize: 1,
now: mockTime,
uid: mockId,

PersonalApiKey: "some very secret key",
})
defer client.Close()

// Without this call client.Close hangs forever
// Ref: https://github.com/PostHog/posthog-go/issues/28
client.IsFeatureEnabled(
FeatureFlagPayload{
Key: "simpleFlag",
DistinctId: "hey",
},
)

err := client.Enqueue(Capture{
Event: "Download",
DistinctId: "123456",
SendFeatureFlags: true,
})

if err != nil {
t.Fatal(err)
}
}
Loading