Skip to content

Commit b5c90f7

Browse files
fix(go): Fail hard on empty AccoundId (#194)
1 parent 7a9f157 commit b5c90f7

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

openfeature-provider/go/confidence/local_resolver_provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ func (p *LocalResolverProvider) Init(evaluationContext openfeature.EvaluationCon
394394
}
395395

396396
if accountId == "" {
397-
p.logger.Warn("AccountID is empty after state fetch")
398-
accountId = "unknown"
397+
p.logger.Error("AccountID is empty in the fetched state, this should not happen")
398+
return fmt.Errorf("AccountID is empty in the initial state")
399399
}
400400

401401
// Update resolver with initial state (triggers WASM compilation and initialization)

openfeature-provider/go/confidence/local_resolver_provider_test.go

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -525,24 +525,15 @@ func TestLocalResolverProvider_Init_StateProviderError(t *testing.T) {
525525
}
526526
}
527527

528-
// TestLocalResolverProvider_Init_EmptyAccountID verifies Init handles empty accountID
528+
// TestLocalResolverProvider_Init_EmptyAccountID verifies Init fails when accountID is empty
529529
func TestLocalResolverProvider_Init_EmptyAccountID(t *testing.T) {
530-
updateStateCalled := false
531-
receivedAccountID := ""
532-
533530
mockStateProvider := &mockStateProviderForInit{
534531
provideFunc: func(ctx context.Context) ([]byte, string, error) {
535532
return []byte("test-state"), "", nil // Empty accountID
536533
},
537534
}
538535

539-
mockResolverAPI := &mockResolverAPIForInit{
540-
updateStateFunc: func(state []byte, accountID string) error {
541-
updateStateCalled = true
542-
receivedAccountID = accountID
543-
return nil
544-
},
545-
}
536+
mockResolverAPI := &mockResolverAPIForInit{}
546537

547538
provider := NewLocalResolverProvider(
548539
mockResolverAPI,
@@ -553,17 +544,11 @@ func TestLocalResolverProvider_Init_EmptyAccountID(t *testing.T) {
553544
)
554545

555546
err := provider.Init(openfeature.EvaluationContext{})
556-
if err != nil {
557-
t.Fatalf("Expected no error, got: %v", err)
558-
}
559-
560-
if !updateStateCalled {
561-
t.Error("Expected UpdateStateAndFlushLogs to be called")
547+
if err == nil {
548+
t.Fatal("Expected error when accountID is empty")
562549
}
563-
564-
// Should use "unknown" when accountID is empty
565-
if receivedAccountID != "unknown" {
566-
t.Errorf("Expected accountID to be 'unknown', got: %s", receivedAccountID)
550+
if err.Error() != "AccountID is empty in the initial state" {
551+
t.Errorf("Expected specific error message, got: %v", err)
567552
}
568553
}
569554

0 commit comments

Comments
 (0)