Skip to content

Commit 07f4974

Browse files
feat: EvaluationContext add constructor without TargetingKey (#204)
Add constructor without TargetingKey Signed-off-by: Thomas Poignant <thomas.poignant@gofeatureflag.org>
1 parent a2987b8 commit 07f4974

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

pkg/openfeature/evaluation_context.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,10 @@ func NewEvaluationContext(targetingKey string, attributes map[string]interface{}
4646
attributes: attrs,
4747
}
4848
}
49+
50+
// NewTargetlessEvaluationContext constructs an EvaluationContext with an empty targeting key
51+
//
52+
// attributes - contextual data used in flag evaluation
53+
func NewTargetlessEvaluationContext(attributes map[string]interface{}) EvaluationContext {
54+
return NewEvaluationContext("", attributes)
55+
}

pkg/openfeature/evaluation_context_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,17 @@ func TestEvaluationContext_AttributesFuncNotPassedByReference(t *testing.T) {
171171
t.Error("mutation of map passed to SetAttributes caused a mutation of its attributes field")
172172
}
173173
}
174+
175+
func TestNewTargetlessEvaluationContext(t *testing.T) {
176+
attributes := map[string]interface{}{
177+
"foo": "bar",
178+
}
179+
evalCtx := NewTargetlessEvaluationContext(attributes)
180+
if evalCtx.targetingKey != "" {
181+
t.Error("targeting key should not be set with NewTargetlessEvaluationContext")
182+
}
183+
184+
if !reflect.DeepEqual(evalCtx.Attributes(), attributes) {
185+
t.Errorf("we expect no difference in the attributes")
186+
}
187+
}

0 commit comments

Comments
 (0)