-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathtracking_test.go
56 lines (51 loc) · 1.57 KB
/
tracking_test.go
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
package ffclient_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
ffclient "github.com/thomaspoignant/go-feature-flag"
"github.com/thomaspoignant/go-feature-flag/ffcontext"
"github.com/thomaspoignant/go-feature-flag/retriever/fileretriever"
"github.com/thomaspoignant/go-feature-flag/testutils/mock"
)
func TestValidTrackingEvent(t *testing.T) {
exp := mock.TrackingEventExporter{Bulk: false}
goff, err := ffclient.New(ffclient.Config{
PollingInterval: 500 * time.Millisecond,
Retriever: &fileretriever.Retriever{Path: "./testdata/flag-config.yaml"},
DataExporters: []ffclient.DataExporter{
{
FlushInterval: 100 * time.Millisecond,
MaxEventInMemory: 100,
Exporter: &exp,
ExporterEventType: ffclient.TrackingEventExporter,
},
},
})
assert.NoError(t, err)
goff.Track(
"my-feature-flag",
ffcontext.NewEvaluationContextBuilder("1668d845-051d-4dd9-907a-7ebe6aa2c9da").
AddCustom("admin", true).
AddCustom("anonymous", true).
Build(),
map[string]interface{}{"additional data": "value"},
)
assert.Equal(t, 1, len(exp.ExportedEvents))
assert.Equal(t, "1668d845-051d-4dd9-907a-7ebe6aa2c9da", exp.ExportedEvents[0].UserKey)
assert.Equal(t, "my-feature-flag", exp.ExportedEvents[0].Key)
assert.Equal(
t,
map[string]interface{}{
"targetingKey": "1668d845-051d-4dd9-907a-7ebe6aa2c9da",
"admin": true,
"anonymous": true,
},
exp.ExportedEvents[0].EvaluationContext,
)
assert.Equal(
t,
map[string]interface{}{"additional data": "value"},
exp.ExportedEvents[0].TrackingDetails,
)
}