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

feat: Put EvalFlag public #299

Merged
merged 1 commit into from
Oct 28, 2019
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
8 changes: 4 additions & 4 deletions pkg/handler/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (e *eval) PostEvaluation(params evaluation.PostEvaluationParams) middleware
ErrorMessage("empty body"))
}

evalResult := evalFlag(*evalContext)
evalResult := EvalFlag(*evalContext)
resp := evaluation.NewPostEvaluationOK()
resp.SetPayload(evalResult)
return resp
Expand All @@ -61,7 +61,7 @@ func (e *eval) PostEvaluationBatch(params evaluation.PostEvaluationBatchParams)
EntityType: entity.EntityType,
FlagID: flagID,
}
evalResult := evalFlag(evalContext)
evalResult := EvalFlag(evalContext)
results.EvaluationResults = append(results.EvaluationResults, evalResult)
}
for _, flagKey := range flagKeys {
Expand All @@ -72,7 +72,7 @@ func (e *eval) PostEvaluationBatch(params evaluation.PostEvaluationBatchParams)
EntityType: entity.EntityType,
FlagKey: flagKey,
}
evalResult := evalFlag(evalContext)
evalResult := EvalFlag(evalContext)
results.EvaluationResults = append(results.EvaluationResults, evalResult)
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ func BlankResult(f *entity.Flag, evalContext models.EvalContext, msg string) *mo
}
}

var evalFlag = func(evalContext models.EvalContext) *models.EvalResult {
var EvalFlag = func(evalContext models.EvalContext) *models.EvalResult {
cache := GetEvalCache()
flagID := util.SafeUint(evalContext.FlagID)
flagKey := util.SafeString(evalContext.FlagKey)
Expand Down
26 changes: 13 additions & 13 deletions pkg/handler/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ func TestEvalFlag(t *testing.T) {

t.Run("test empty evalContext", func(t *testing.T) {
defer gostub.StubFunc(&GetEvalCache, GenFixtureEvalCache()).Reset()
result := evalFlag(models.EvalContext{FlagID: int64(100)})
result := EvalFlag(models.EvalContext{FlagID: int64(100)})
assert.Zero(t, result.VariantID)
assert.NotZero(t, result.FlagID)
assert.NotEmpty(t, result.EvalContext.EntityID)
})

t.Run("test happy code path", func(t *testing.T) {
defer gostub.StubFunc(&GetEvalCache, GenFixtureEvalCache()).Reset()
result := evalFlag(models.EvalContext{
result := EvalFlag(models.EvalContext{
EnableDebug: true,
EntityContext: map[string]interface{}{"dl_state": "CA"},
EntityID: "entityID1",
Expand All @@ -167,7 +167,7 @@ func TestEvalFlag(t *testing.T) {

t.Run("test happy code path with flagKey", func(t *testing.T) {
defer gostub.StubFunc(&GetEvalCache, GenFixtureEvalCache()).Reset()
result := evalFlag(models.EvalContext{
result := EvalFlag(models.EvalContext{
EnableDebug: true,
EntityContext: map[string]interface{}{"dl_state": "CA"},
EntityID: "entityID1",
Expand All @@ -180,7 +180,7 @@ func TestEvalFlag(t *testing.T) {

t.Run("test happy code path with flagKey", func(t *testing.T) {
defer gostub.StubFunc(&GetEvalCache, GenFixtureEvalCache()).Reset()
result := evalFlag(models.EvalContext{
result := EvalFlag(models.EvalContext{
EnableDebug: true,
EntityContext: map[string]interface{}{"dl_state": "CA"},
EntityID: "entityID1",
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestEvalFlag(t *testing.T) {
f.PrepareEvaluation()
cache := &EvalCache{idCache: map[string]*entity.Flag{"100": &f}}
defer gostub.StubFunc(&GetEvalCache, cache).Reset()
result := evalFlag(models.EvalContext{
result := EvalFlag(models.EvalContext{
EnableDebug: true,
EntityContext: map[string]interface{}{"dl_state": "CA", "state": "CA", "rate": 2000},
EntityID: "entityID1",
Expand All @@ -239,7 +239,7 @@ func TestEvalFlag(t *testing.T) {
f.PrepareEvaluation()
cache := &EvalCache{idCache: map[string]*entity.Flag{"100": &f}}
defer gostub.StubFunc(&GetEvalCache, cache).Reset()
result := evalFlag(models.EvalContext{
result := EvalFlag(models.EvalContext{
EnableDebug: true,
EntityContext: map[string]interface{}{"dl_state": "CA", "state": "CA", "rate": 2000},
EntityID: "entityID1",
Expand Down Expand Up @@ -271,7 +271,7 @@ func TestEvalFlag(t *testing.T) {
f.PrepareEvaluation()
cache := &EvalCache{idCache: map[string]*entity.Flag{"100": &f}}
defer gostub.StubFunc(&GetEvalCache, cache).Reset()
result := evalFlag(models.EvalContext{
result := EvalFlag(models.EvalContext{
EnableDebug: true,
EntityContext: map[string]interface{}{"dl_state": "CA", "state": "NY"},
EntityID: "entityID1",
Expand All @@ -287,7 +287,7 @@ func TestEvalFlag(t *testing.T) {
f.Enabled = false
cache := &EvalCache{idCache: map[string]*entity.Flag{"100": &f}}
defer gostub.StubFunc(&GetEvalCache, cache).Reset()
result := evalFlag(models.EvalContext{
result := EvalFlag(models.EvalContext{
EnableDebug: true,
EntityContext: map[string]interface{}{"dl_state": "CA"},
EntityID: "entityID1",
Expand All @@ -304,7 +304,7 @@ func TestEvalFlag(t *testing.T) {
f.EntityType = ""
cache := &EvalCache{idCache: map[string]*entity.Flag{"100": &f}}
defer gostub.StubFunc(&GetEvalCache, cache).Reset()
result := evalFlag(models.EvalContext{
result := EvalFlag(models.EvalContext{
EnableDebug: true,
EntityContext: map[string]interface{}{"dl_state": "CA"},
EntityID: "entityID1",
Expand All @@ -320,7 +320,7 @@ func TestEvalFlag(t *testing.T) {
f.EntityType = "some_entity_type"
cache := &EvalCache{idCache: map[string]*entity.Flag{"100": &f}}
defer gostub.StubFunc(&GetEvalCache, cache).Reset()
result := evalFlag(models.EvalContext{
result := EvalFlag(models.EvalContext{
EnableDebug: true,
EntityContext: map[string]interface{}{"dl_state": "CA"},
EntityID: "entityID1",
Expand All @@ -337,14 +337,14 @@ func TestEvalFlag(t *testing.T) {

func TestPostEvaluation(t *testing.T) {
t.Run("test empty body", func(t *testing.T) {
defer gostub.StubFunc(&evalFlag, &models.EvalResult{}).Reset()
defer gostub.StubFunc(&EvalFlag, &models.EvalResult{}).Reset()
e := NewEval()
resp := e.PostEvaluation(evaluation.PostEvaluationParams{})
assert.NotNil(t, resp)
})

t.Run("test happy code path", func(t *testing.T) {
defer gostub.StubFunc(&evalFlag, &models.EvalResult{}).Reset()
defer gostub.StubFunc(&EvalFlag, &models.EvalResult{}).Reset()
e := NewEval()
resp := e.PostEvaluation(evaluation.PostEvaluationParams{
Body: &models.EvalContext{
Expand All @@ -361,7 +361,7 @@ func TestPostEvaluation(t *testing.T) {

func TestPostEvaluationBatch(t *testing.T) {
t.Run("test happy code path", func(t *testing.T) {
defer gostub.StubFunc(&evalFlag, &models.EvalResult{}).Reset()
defer gostub.StubFunc(&EvalFlag, &models.EvalResult{}).Reset()
e := NewEval()
resp := e.PostEvaluationBatch(evaluation.PostEvaluationBatchParams{
Body: &models.EvaluationBatchRequest{
Expand Down