@@ -22,6 +22,12 @@ func TestNewProvider(t *testing.T) {
2222 grpc .WithAuthority ("test-authority" ),
2323 }
2424
25+ enrichment := make (map [string ]any )
26+ enrichment ["test" ] = "test"
27+
28+ expectedEnrichment := make (map [string ]any )
29+ expectedEnrichment ["test" ] = "test"
30+ expectedEnrichment ["test2" ] = "test2"
2531 tests := []struct {
2632 name string
2733 expectedResolver ResolverType
@@ -41,6 +47,7 @@ func TestNewProvider(t *testing.T) {
4147 expectCustomSyncProviderUri string
4248 expectOfflineFlagSourcePath string
4349 expectGrpcDialOptionsOverride []grpc.DialOption
50+ expectContextEnrichment map [string ]any
4451 options []ProviderOption
4552 }{
4653 {
@@ -269,6 +276,41 @@ func TestNewProvider(t *testing.T) {
269276 WithOfflineFilePath ("offlineFilePath" ),
270277 },
271278 },
279+ {
280+ name : "with ContextEnricher inprocess resolver" ,
281+ expectedResolver : inProcess ,
282+ expectHost : defaultHost ,
283+ expectPort : defaultInProcessPort ,
284+ expectCacheType : defaultCache ,
285+ expectCacheSize : defaultMaxCacheSize ,
286+ expectMaxRetries : defaultMaxEventStreamRetries ,
287+ expectContextEnrichment : enrichment ,
288+ options : []ProviderOption {
289+ WithInProcessResolver (),
290+ WithContextEnricher (func (m map [string ]any ) * of.EvaluationContext {
291+ context := of .NewTargetlessEvaluationContext (m )
292+ return & context
293+ }),
294+ },
295+ },
296+ {
297+ name : "with ContextEnricher inprocess resolver adding values" ,
298+ expectedResolver : inProcess ,
299+ expectHost : defaultHost ,
300+ expectPort : defaultInProcessPort ,
301+ expectCacheType : defaultCache ,
302+ expectCacheSize : defaultMaxCacheSize ,
303+ expectMaxRetries : defaultMaxEventStreamRetries ,
304+ expectContextEnrichment : expectedEnrichment ,
305+ options : []ProviderOption {
306+ WithInProcessResolver (),
307+ WithContextEnricher (func (m map [string ]any ) * of.EvaluationContext {
308+ m ["test2" ] = "test2"
309+ context := of .NewTargetlessEvaluationContext (m )
310+ return & context
311+ }),
312+ },
313+ },
272314 }
273315
274316 for _ , test := range tests {
@@ -369,6 +411,15 @@ func TestNewProvider(t *testing.T) {
369411 }
370412 }
371413
414+ if test .expectContextEnrichment != nil {
415+ enriched := config .ContextEnricher (enrichment ).Attributes ()
416+ for k , v := range test .expectContextEnrichment {
417+ if enriched [k ] != v {
418+ t .Errorf ("incorrect context_enrichment attribute, expected %v, got %v" , v , enriched [k ])
419+ }
420+ }
421+ }
422+
372423 // this line will fail linting if this provider is no longer compatible with the openfeature sdk
373424 var _ of.FeatureProvider = flagdProvider
374425 })
0 commit comments