Skip to content

Commit

Permalink
fixed test to map
Browse files Browse the repository at this point in the history
  • Loading branch information
mmelograno committed Jan 25, 2024
1 parent 5fd06c2 commit 96fdc17
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions splitio/sdk/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,27 +218,39 @@ func TestTreatmentsByFlagSet(t *testing.T) {
}}).
Once()

expectedImpressions := []dtos.Impression{
{KeyName: "key1", BucketingKey: "", FeatureName: "f1", Treatment: "on", Label: "label1", ChangeNumber: 123},
{KeyName: "key1", BucketingKey: "", FeatureName: "f2", Treatment: "on", Label: "label2", ChangeNumber: 124},
{KeyName: "key1", BucketingKey: "", FeatureName: "f3", Treatment: "on", Label: "label3", ChangeNumber: 125},
expectedImpressions := map[string]*dtos.Impression{
"f1": {KeyName: "key1", BucketingKey: "", FeatureName: "f1", Treatment: "on", Label: "label1", ChangeNumber: 123},
"f2": {KeyName: "key1", BucketingKey: "", FeatureName: "f2", Treatment: "on", Label: "label2", ChangeNumber: 124},
"f3": {KeyName: "key1", BucketingKey: "", FeatureName: "f3", Treatment: "on", Label: "label3", ChangeNumber: 125},
}
im := &mocks.ImpressionManagerMock{}
im.On("ProcessSingle", mock.Anything).
Run(func(args mock.Arguments) {
assertImpEq(t, &expectedImpressions[0], args.Get(0).(*dtos.Impression))
imp, ok := args.Get(0).(*dtos.Impression)
if !ok {
t.Error("not an impression")
}
assertImpEq(t, expectedImpressions[imp.FeatureName], args.Get(0).(*dtos.Impression))
}).
Return(true).
Once()
im.On("ProcessSingle", mock.Anything).
Run(func(args mock.Arguments) {
assertImpEq(t, &expectedImpressions[1], args.Get(0).(*dtos.Impression))
imp, ok := args.Get(0).(*dtos.Impression)
if !ok {
t.Error("not an impression")
}
assertImpEq(t, expectedImpressions[imp.FeatureName], args.Get(0).(*dtos.Impression))
}).
Return(true).
Once()
im.On("ProcessSingle", mock.Anything).
Run(func(args mock.Arguments) {
assertImpEq(t, &expectedImpressions[2], args.Get(0).(*dtos.Impression))
imp, ok := args.Get(0).(*dtos.Impression)
if !ok {
t.Error("not an impression")
}
assertImpEq(t, expectedImpressions[imp.FeatureName], args.Get(0).(*dtos.Impression))
}).
Return(true).
Once()
Expand All @@ -258,9 +270,9 @@ func TestTreatmentsByFlagSet(t *testing.T) {
assert.Nil(t, res["f1"].Config)
assert.Nil(t, res["f2"].Config)
assert.Nil(t, res["f3"].Config)
assertImpEq(t, &expectedImpressions[0], res["f1"].Impression)
assertImpEq(t, &expectedImpressions[1], res["f2"].Impression)
assertImpEq(t, &expectedImpressions[2], res["f3"].Impression)
assertImpEq(t, expectedImpressions["f1"], res["f1"].Impression)
assertImpEq(t, expectedImpressions["f2"], res["f2"].Impression)
assertImpEq(t, expectedImpressions["f3"], res["f3"].Impression)

err = is.RangeAndClear(func(md types.ClientMetadata, st *storage.LockingQueue[dtos.Impression]) {
assert.Equal(t, types.ClientMetadata{ID: "some", SdkVersion: "go-1.2.3"}, md)
Expand All @@ -271,9 +283,9 @@ func TestTreatmentsByFlagSet(t *testing.T) {
assert.Nil(t, nil)
assert.Equal(t, 3, n)
assert.Equal(t, 3, len(imps))
assertImpEq(t, &expectedImpressions[0], &imps[0])
assertImpEq(t, &expectedImpressions[1], &imps[1])
assertImpEq(t, &expectedImpressions[2], &imps[2])
assertImpEq(t, expectedImpressions[imps[0].FeatureName], &imps[0])
assertImpEq(t, expectedImpressions[imps[1].FeatureName], &imps[1])
assertImpEq(t, expectedImpressions[imps[2].FeatureName], &imps[2])
n, err = st.Pop(1, &imps)
assert.Equal(t, 0, n)
assert.ErrorIs(t, err, storage.ErrQueueEmpty)
Expand Down

0 comments on commit 96fdc17

Please sign in to comment.