Skip to content

Commit

Permalink
Return store.ErrNotFound to be consistent with other stores
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Jun 3, 2024
1 parent 94a49ba commit 339f5f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion v4/store/nats-js-kv/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (n *natsStore) mustGetBucket(kv *nats.KeyValueConfig) (nats.KeyValue, error
func (n *natsStore) getRecord(bucket nats.KeyValue, key string) (*store.Record, bool, error) {
obj, err := bucket.Get(key)
if errors.Is(err, nats.ErrKeyNotFound) {
return nil, false, nil
return nil, false, store.ErrNotFound
} else if err != nil {
return nil, false, errors.Wrap(err, "Failed to get object from bucket")
}
Expand Down
12 changes: 6 additions & 6 deletions v4/store/nats-js-kv/nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func TestNats(t *testing.T) {

// Test reading non-existing key
r, err := s.Read("this-is-a-random-key")
if err != nil {
t.Fatal(err)
if !errors.Is(err, store.ErrNotFound) {
t.Errorf("Expected %# v, got %# v", store.ErrNotFound, err)
}
if len(r) > 0 {
t.Fatal("Lenth should be 0")
Expand Down Expand Up @@ -111,8 +111,8 @@ func TestTTL(t *testing.T) {

for _, r := range table {
res, err := s.Read(r.Record.Key, store.ReadFrom(r.Database+id, r.Table))
if err != nil {
t.Fatal(err)
if !errors.Is(err, store.ErrNotFound) {
t.Errorf("Expected %# v, got %# v", store.ErrNotFound, err)
}
if len(res) > 0 {
t.Fatal("Fetched record while it should have expired")
Expand Down Expand Up @@ -170,8 +170,8 @@ func TestDelete(t *testing.T) {
time.Sleep(time.Second)

res, err := s.Read(r.Record.Key, store.ReadFrom(r.Database, r.Table))
if err != nil {
t.Fatal(err)
if !errors.Is(err, store.ErrNotFound) {
t.Errorf("Expected %# v, got %# v", store.ErrNotFound, err)
}
if len(res) > 0 {
t.Fatalf("Failed to delete %s:%s from %s %s (len: %d)", r.Record.Key, r.Record.Value, r.Database, r.Table, len(res))
Expand Down

0 comments on commit 339f5f0

Please sign in to comment.