-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from splitio/feat/manager_calls
add support for `getTreatment(s)WithConfig` & manager methods
- Loading branch information
Showing
42 changed files
with
1,728 additions
and
633 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package mocks | ||
|
||
import ( | ||
"github.com/splitio/go-client/v6/splitio/engine/evaluator" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type EvaluatorMock struct { | ||
mock.Mock | ||
} | ||
|
||
// EvaluateFeature implements evaluator.Interface | ||
func (e *EvaluatorMock) EvaluateFeature(key string, bucketingKey *string, feature string, attributes map[string]interface{}) *evaluator.Result { | ||
args := e.Called(key, bucketingKey, feature, attributes) | ||
return args.Get(0).(*evaluator.Result) | ||
} | ||
|
||
// EvaluateFeatures implements evaluator.Interface | ||
func (e *EvaluatorMock) EvaluateFeatures(key string, bucketingKey *string, features []string, attributes map[string]interface{}) evaluator.Results { | ||
args := e.Called(key, bucketingKey, features, attributes) | ||
return args.Get(0).(evaluator.Results) | ||
} | ||
|
||
var _ evaluator.Interface = (*EvaluatorMock)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package mocks | ||
|
||
import ( | ||
"github.com/splitio/go-split-commons/v4/dtos" | ||
"github.com/splitio/go-split-commons/v4/provisional" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type ImpressionManagerMock struct { | ||
mock.Mock | ||
} | ||
|
||
// ProcessImpressions implements provisional.ImpressionManager | ||
func (m *ImpressionManagerMock) ProcessImpressions(impressions []dtos.Impression) ([]dtos.Impression, []dtos.Impression) { | ||
args := m.Called(impressions) | ||
return args.Get(0).([]dtos.Impression), args.Get(1).([]dtos.Impression) | ||
} | ||
|
||
// ProcessSingle implements provisional.ImpressionManager | ||
func (m *ImpressionManagerMock) ProcessSingle(impression *dtos.Impression) bool { | ||
args := m.Called(impression) | ||
return args.Bool(0) | ||
} | ||
|
||
var _ provisional.ImpressionManager = (*ImpressionManagerMock)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package mocks | ||
|
||
import ( | ||
"github.com/splitio/go-split-commons/v4/dtos" | ||
"github.com/splitio/go-split-commons/v4/service" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type ImpressionRecorderMock struct { | ||
mock.Mock | ||
} | ||
|
||
// Record implements service.ImpressionsRecorder | ||
func (m *ImpressionRecorderMock) Record(impressions []dtos.ImpressionsDTO, metadata dtos.Metadata, extraHeaders map[string]string) error { | ||
args := m.Called(impressions, metadata, extraHeaders) | ||
return args.Error(0) | ||
} | ||
|
||
// RecordImpressionsCount implements service.ImpressionsRecorder | ||
func (m *ImpressionRecorderMock) RecordImpressionsCount(pf dtos.ImpressionsCountDTO, metadata dtos.Metadata) error { | ||
args := m.Called(pf, metadata) | ||
return args.Error(0) | ||
} | ||
|
||
var _ service.ImpressionsRecorder = (*ImpressionRecorderMock)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package mocks | ||
|
||
import ( | ||
"github.com/splitio/go-split-commons/v4/dtos" | ||
"github.com/splitio/go-split-commons/v4/storage" | ||
"github.com/splitio/go-toolkit/v5/datastructures/set" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type SplitStorageMock struct{ mock.Mock } | ||
|
||
func (m *SplitStorageMock) All() []dtos.SplitDTO { | ||
args := m.Called() | ||
return args.Get(0).([]dtos.SplitDTO) | ||
} | ||
|
||
func (m *SplitStorageMock) ChangeNumber() (int64, error) { | ||
args := m.Called() | ||
return args.Get(0).(int64), args.Error(1) | ||
} | ||
|
||
func (m *SplitStorageMock) FetchMany(names []string) map[string]*dtos.SplitDTO { | ||
args := m.Called(names) | ||
return args.Get(0).(map[string]*dtos.SplitDTO) | ||
} | ||
|
||
func (m *SplitStorageMock) KillLocally(name string, defaultTreatment string, newCn int64) { | ||
m.Called(name, defaultTreatment, newCn) | ||
} | ||
|
||
func (m *SplitStorageMock) SegmentNames() *set.ThreadUnsafeSet { | ||
args := m.Called() | ||
return args.Get(0).(*set.ThreadUnsafeSet) | ||
} | ||
|
||
func (m *SplitStorageMock) SetChangeNumber(changeNumber int64) error { | ||
args := m.Called(changeNumber) | ||
return args.Error(0) | ||
|
||
} | ||
|
||
func (m *SplitStorageMock) Split(splitName string) *dtos.SplitDTO { | ||
args := m.Called(splitName) | ||
return args.Get(0).(*dtos.SplitDTO) | ||
} | ||
|
||
func (m *SplitStorageMock) SplitNames() []string { | ||
args := m.Called() | ||
return args.Get(0).([]string) | ||
} | ||
|
||
func (m *SplitStorageMock) Update(toAdd []dtos.SplitDTO, toRemove []dtos.SplitDTO, newCN int64) { | ||
m.Called() | ||
} | ||
|
||
func (m *SplitStorageMock) TrafficTypeExists(trafficType string) bool { | ||
args := m.Called(trafficType) | ||
return args.Bool(0) | ||
} | ||
|
||
var _ storage.SplitStorage = (*SplitStorageMock)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package splitio | ||
|
||
const CommitSHA = "e1ecfc9" | ||
const CommitSHA = "29ff22d" |
2 changes: 1 addition & 1 deletion
2
splitio/util/conf/helpers.go → splitio/common/lang/functools.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package conf | ||
package lang | ||
|
||
func SetIfNotNil[T any](dst *T, src *T) { | ||
if src != nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package lang | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestConfHelpers(t *testing.T) { | ||
var x int | ||
SetIfNotEmpty(&x, Ref(0)) | ||
assert.Equal(t, 0, x) | ||
SetIfNotNil(&x, nil) | ||
assert.Equal(t, 0, x) | ||
|
||
SetIfNotEmpty(&x, Ref(5)) | ||
assert.Equal(t, 5, x) | ||
SetIfNotNil(&x, Ref(25)) | ||
assert.Equal(t, 25, x) | ||
|
||
x = 0 | ||
MapIfNotEmpty(&x, Ref(0), func(z int) int { return z + 1 }) | ||
assert.Equal(t, 0, x) | ||
MapIfNotNil(&x, nil, func(z int) int { return z + 1 }) | ||
assert.Equal(t, 0, x) | ||
MapIfNotNil(&x, Ref(10), func(z int) int { return z + 1 }) | ||
assert.Equal(t, 11, x) | ||
|
||
MapIfNotEmpty(&x, Ref(1), func(z int) int { return z + 1 }) | ||
assert.Equal(t, 2, x) | ||
MapIfNotEmpty(&x, Ref(2), func(z int) int { return z + 1 }) | ||
assert.Equal(t, 3, x) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package lang | ||
|
||
func Ref[T any](t T) *T { | ||
return &t | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package conf | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/splitio/splitd/splitio/link/protocol" | ||
"github.com/splitio/splitd/splitio/link/serializer" | ||
"github.com/splitio/splitd/splitio/link/transfer" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParseProtocol(t *testing.T) { | ||
pv, err := parseProtocolVersion("v1") | ||
assert.Nil(t, err) | ||
assert.Equal(t, protocol.V1, pv) | ||
|
||
pv, err = parseProtocolVersion("v2") | ||
assert.NotNil(t, err) | ||
assert.NotEqual(t, pv, protocol.V1) | ||
} | ||
|
||
func TestParseConnType(t *testing.T) { | ||
ct, err := parseConnType("unix-stream") | ||
assert.Nil(t, err) | ||
assert.Equal(t, transfer.ConnTypeUnixStream, ct) | ||
|
||
ct, err = parseConnType("unix-seqpacket") | ||
assert.Nil(t, err) | ||
assert.Equal(t, transfer.ConnTypeUnixSeqPacket, ct) | ||
|
||
ct, err = parseConnType("something-else") | ||
assert.NotNil(t, err) | ||
assert.NotEqual(t, transfer.ConnTypeUnixSeqPacket, ct) | ||
assert.NotEqual(t, transfer.ConnTypeUnixStream, ct) | ||
} | ||
|
||
func TestParseSerializer(t *testing.T) { | ||
sm, err := parseSerializer("msgpack") | ||
assert.Nil(t, err) | ||
assert.Equal(t, serializer.MsgPack, sm) | ||
|
||
sm, err = parseSerializer("something_esle") | ||
assert.NotNil(t, err) | ||
assert.NotEqual(t, serializer.MsgPack, sm) | ||
|
||
} |
Oops, something went wrong.