Skip to content

Commit

Permalink
Merge pull request #27 from splitio/task/flagSetTest
Browse files Browse the repository at this point in the history
Task/flag set test
  • Loading branch information
mmelograno authored Jan 25, 2024
2 parents f91c19d + fe969b3 commit 639a07b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 33 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

- name: Version validation
if: ${{ github.event_name == 'pull_request' }}
uses: mukunku/tag-exists-action@v1.2.0
uses: mukunku/tag-exists-action@v1.5.0
id: checkTag
with:
tag: v${{ env.VERSION }}
Expand All @@ -36,12 +36,12 @@ jobs:

- name: Fail workflow if tag exists
if: ${{ github.event_name == 'pull_request' && steps.checkTag.outputs.exists == 'true' }}
uses: actions/github-script@v6.4.0
uses: actions/github-script@v7.0.1
with:
script: core.setFailed('[ERROR] Tag already exists.')

- name: Setup Go version
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '^1.20.7'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Login to Artifactory
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: splitio-docker.jfrog.io
username: ${{ secrets.ARTIFACTORY_DOCKER_USER }}
Expand All @@ -24,7 +24,7 @@ jobs:
run: echo "VERSION=$(cat splitio/version.go | grep 'Version =' | awk '{print $4}' | tr -d '"')" >> $GITHUB_ENV

- name: Docker build and push
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
file: "infra/sidecar.Dockerfile"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unstable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Login to Artifactory
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: splitio-docker-dev.jfrog.io
username: ${{ secrets.ARTIFACTORY_DOCKER_USER }}
Expand All @@ -23,7 +23,7 @@ jobs:
run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV

- name: Docker Build and Push
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
file: "infra/sidecar.Dockerfile"
Expand Down
76 changes: 50 additions & 26 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 All @@ -295,27 +307,39 @@ func TestTreatmentsByFlagSets(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 @@ -335,9 +359,9 @@ func TestTreatmentsByFlagSets(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 @@ -348,9 +372,9 @@ func TestTreatmentsByFlagSets(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 639a07b

Please sign in to comment.