Skip to content

Commit e743c56

Browse files
committed
fixup: more feedbacl
Signed-off-by: Todd Baert <[email protected]>
1 parent 0c169de commit e743c56

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

core/pkg/evaluator/json.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,6 @@ func (je *Resolver) evaluateVariant(ctx context.Context, reqID string, flagKey s
310310

311311
var selector store.Selector
312312
s := ctx.Value(store.SelectorContextKey{})
313-
if s != nil {
314-
selector = s.(store.Selector)
315-
} else {
316-
selector = store.NewSelector("")
317-
}
318313
if s != nil {
319314
selector = s.(store.Selector)
320315
}

core/pkg/notifications/notifications.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const typeField = "type"
1212
type Notifications map[string]any
1313

1414
// Generate notifications (deltas) from old and new flag sets for use in RPC mode PROVIDER_CONFIGURATION_CHANGE events.
15-
func NewFromFlags(oldFlags, newFlags map[string]model.Flag) map[string]interface{} {
15+
func NewFromFlags(oldFlags, newFlags map[string]model.Flag) Notifications {
1616
notifications := map[string]interface{}{}
1717

1818
// flags removed

core/pkg/notifications/notifications_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ func TestNewFromFlags(t *testing.T) {
3131
name string
3232
oldFlags map[string]model.Flag
3333
newFlags map[string]model.Flag
34-
want map[string]interface{}
34+
want Notifications
3535
}{
3636
{
3737
name: "flag added",
3838
oldFlags: map[string]model.Flag{},
3939
newFlags: map[string]model.Flag{"flagA": flagA},
40-
want: map[string]interface{}{
40+
want: Notifications{
4141
"flagA": map[string]interface{}{
4242
"type": string(model.NotificationCreate),
4343
},
@@ -47,7 +47,7 @@ func TestNewFromFlags(t *testing.T) {
4747
name: "flag deleted",
4848
oldFlags: map[string]model.Flag{"flagA": flagA},
4949
newFlags: map[string]model.Flag{},
50-
want: map[string]interface{}{
50+
want: Notifications{
5151
"flagA": map[string]interface{}{
5252
"type": string(model.NotificationDelete),
5353
},
@@ -57,7 +57,7 @@ func TestNewFromFlags(t *testing.T) {
5757
name: "flag changed",
5858
oldFlags: map[string]model.Flag{"flagA": flagA},
5959
newFlags: map[string]model.Flag{"flagA": flagAUpdated},
60-
want: map[string]interface{}{
60+
want: Notifications{
6161
"flagA": map[string]interface{}{
6262
"type": string(model.NotificationUpdate),
6363
},
@@ -67,7 +67,7 @@ func TestNewFromFlags(t *testing.T) {
6767
name: "flag unchanged",
6868
oldFlags: map[string]model.Flag{"flagA": flagA},
6969
newFlags: map[string]model.Flag{"flagA": flagA},
70-
want: map[string]interface{}{},
70+
want: Notifications{},
7171
},
7272
{
7373
name: "mixed changes",
@@ -79,7 +79,7 @@ func TestNewFromFlags(t *testing.T) {
7979
"flagA": flagAUpdated, // updated
8080
"flagC": flagA, // added
8181
},
82-
want: map[string]interface{}{
82+
want: Notifications{
8383
"flagA": map[string]interface{}{
8484
"type": string(model.NotificationUpdate),
8585
},

core/pkg/store/store.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,12 @@ func (s *Store) Get(_ context.Context, key string, selector *Selector) (model.Fl
163163
s.logger.Debug(fmt.Sprintf("getting flag with query: %s, %v", indexId, constraints))
164164
raw, err := txn.First(flagsTable, indexId, constraints...)
165165
flag, ok := raw.(model.Flag)
166-
if (err != nil) || !ok {
166+
if err != nil {
167167
return model.Flag{}, queryMeta, fmt.Errorf("flag %s not found: %w", key, err)
168168
}
169+
if !ok {
170+
return model.Flag{}, queryMeta, fmt.Errorf("flag %s is not a valid flag", key)
171+
}
169172
return flag, queryMeta, nil
170173

171174
}

flagd/pkg/service/flag-evaluation/connect_service_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
mock "github.com/open-feature/flagd/core/pkg/evaluator/mock"
1616
"github.com/open-feature/flagd/core/pkg/logger"
1717
"github.com/open-feature/flagd/core/pkg/model"
18+
"github.com/open-feature/flagd/core/pkg/notifications"
1819
iservice "github.com/open-feature/flagd/core/pkg/service"
1920
"github.com/open-feature/flagd/core/pkg/store"
2021
"github.com/open-feature/flagd/core/pkg/telemetry"
@@ -253,7 +254,7 @@ func TestConnectServiceWatcher(t *testing.T) {
253254
select {
254255
case n := <-sChan:
255256
require.Equal(t, ofType, n.Type, "expected notification type: %s, but received %s", ofType, n.Type)
256-
notifications := n.Data["flags"].(map[string]interface{})
257+
notifications := n.Data["flags"].(notifications.Notifications)
257258
flag1, ok := notifications["flag1"].(map[string]interface{})
258259
require.True(t, ok, "flag1 notification should be a map[string]interface{}")
259260
require.Equal(t, flag1["type"], string(model.NotificationCreate), "expected notification type: %s, but received %s", model.NotificationCreate, flag1["type"])

0 commit comments

Comments
 (0)