Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
fix(broker/nats): use errors.Is(..) to compare errors
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Oct 5, 2024
1 parent 47fd638 commit e672507
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion broker/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package broker

import (
"context"
"errors"
"fmt"
"log/slog"
"math"
Expand Down Expand Up @@ -714,7 +715,7 @@ bucketSetup:
}

// That means that bucket has been already created
if err == jetstream.ErrStreamNameAlreadyInUse {
if errors.Is(err, jetstream.ErrStreamNameAlreadyInUse) {
newBucket = false
bucket, err = n.js.KeyValue(context.Background(), key)

Expand Down
10 changes: 5 additions & 5 deletions broker/nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func TestNATSBroker_Sessions(t *testing.T) {
require.NoError(t, anotherBroker.Start(nil))
defer anotherBroker.Shutdown(context.Background()) // nolint: errcheck

require.NoError(t, anotherBroker.Ready())
require.NoError(t, anotherBroker.Ready(jetstreamReadyTimeout))

restored, err := anotherBroker.RestoreSession("test123")

Expand Down Expand Up @@ -292,7 +292,7 @@ func TestNATSBroker_SessionsTTLChange(t *testing.T) {

defer broker.Shutdown(context.Background()) // nolint: errcheck

require.NoError(t, broker.Ready())
require.NoError(t, broker.Ready(jetstreamReadyTimeout))

err = broker.CommitSession("test123", &TestCacheable{"cache-me"})
require.NoError(t, err)
Expand All @@ -304,7 +304,7 @@ func TestNATSBroker_SessionsTTLChange(t *testing.T) {
require.NoError(t, anotherBroker.Start(nil))
defer anotherBroker.Shutdown(context.Background()) // nolint: errcheck

require.NoError(t, anotherBroker.Ready())
require.NoError(t, anotherBroker.Ready(jetstreamReadyTimeout))

// The session must be missing since we recreated the bucket due to TTL change
missing, err := anotherBroker.RestoreSession("test123")
Expand Down Expand Up @@ -358,7 +358,7 @@ func TestNATSBroker_Epoch(t *testing.T) {
require.NoError(t, err)
defer broker.Shutdown(context.Background()) // nolint: errcheck

require.NoError(t, broker.Ready())
require.NoError(t, broker.Ready(jetstreamReadyTimeout))
broker.Reset() // nolint: errcheck

epoch := broker.Epoch()
Expand All @@ -367,7 +367,7 @@ func TestNATSBroker_Epoch(t *testing.T) {
require.NoError(t, anotherBroker.Start(nil))
defer anotherBroker.Shutdown(context.Background()) // nolint: errcheck

require.NoError(t, anotherBroker.Ready())
require.NoError(t, anotherBroker.Ready(jetstreamReadyTimeout))

assert.Equal(t, epoch, anotherBroker.Epoch())

Expand Down

0 comments on commit e672507

Please sign in to comment.