Skip to content

Commit

Permalink
Merge pull request #299 from tkanos/feature/EvalFag-publicly
Browse files Browse the repository at this point in the history
feat: Put EvalFlag public
  • Loading branch information
zhouzhuojie authored Oct 28, 2019
2 parents ba9c515 + af93b24 commit 2668d5c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
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

0 comments on commit 2668d5c

Please sign in to comment.