Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Return store.ErrNotFound to be consistent with other stores #140

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 8 additions & 10 deletions v4/store/nats-js-kv/nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import (
func TestNats(t *testing.T) {
// Setup without calling Init on purpose
var err error
var cancel func()
var ctx context.Context
for i := 0; i < 5; i++ {
ctx, cancel = context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
addr := startNatsServer(ctx, t)
s := NewStore(store.Nodes(addr), EncodeKeys())

Expand All @@ -33,8 +32,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 All @@ -46,7 +45,6 @@ func TestNats(t *testing.T) {
cancel()
return
}
cancel()
t.Fatal(err)
}

Expand Down Expand Up @@ -111,8 +109,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 +168,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
Loading