Skip to content

Commit

Permalink
[CHANGE] changed stream exports get to return err instead of bool
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Mar 6, 2024
1 parent 6ad8532 commit 197eedb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions stream_exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ type streamExports struct {
*AccountData
}

func (s *streamExports) Get(subject string) (StreamExport, bool) {
func (s *streamExports) Get(subject string) (StreamExport, error) {
se := s.getStreamExport(subject)
if se != nil {
return se, true
return se, nil
}
return nil, false
return nil, ErrNotFound
}

func (s *streamExports) AddWithConfig(e StreamExport) error {
Expand Down
32 changes: 16 additions & 16 deletions tests/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (t *ProviderSuite) Test_ExportTokenRequired() {
t.NoError(err)
t.True(service.TokenRequired())

stream, ok := a.Exports().Streams().Get("t.>")
t.True(ok)
stream, err = a.Exports().Streams().Get("t.>")
t.NoError(err)
t.True(stream.TokenRequired())
}

Expand Down Expand Up @@ -114,12 +114,12 @@ func (t *ProviderSuite) Test_ExportNameSubject() {
t.NoError(stream.SetName("ss"))
t.NoError(stream.SetSubject("st.>"))

_, ok := a.Exports().Streams().Get("t.>")
t.False(ok)
_, ok = a.Exports().Streams().GetByName("s")
_, err = a.Exports().Streams().Get("t.>")
t.ErrorIs(err, authb.ErrNotFound)
_, ok := a.Exports().Streams().GetByName("s")
t.False(ok)
_, ok = a.Exports().Streams().Get("st.>")
t.True(ok)
_, err = a.Exports().Streams().Get("st.>")
t.NoError(err)
_, ok = a.Exports().Streams().GetByName("ss")
t.True(ok)
}
Expand All @@ -146,8 +146,8 @@ func (t *ProviderSuite) Test_ExportDescription() {
t.NoError(err)
t.Equal("desc", service.Description())

stream, ok := a.Exports().Streams().Get("t.>")
t.True(ok)
stream, err = a.Exports().Streams().Get("t.>")
t.NoError(err)
t.Equal("desc", stream.Description())
}

Expand All @@ -173,8 +173,8 @@ func (t *ProviderSuite) Test_ExportInfoURL() {
t.NoError(err)
t.Equal("https://service.com", service.InfoURL())

stream, ok := a.Exports().Streams().Get("t.>")
t.True(ok)
stream, err = a.Exports().Streams().Get("t.>")
t.NoError(err)
t.Equal("https://stream.com", stream.InfoURL())
}

Expand All @@ -200,8 +200,8 @@ func (t *ProviderSuite) Test_ExportAccountTokenPosition() {
t.NoError(err)
t.Equal(uint(2), service.AccountTokenPosition())

stream, ok := a.Exports().Streams().Get("t.*")
t.True(ok)
stream, err = a.Exports().Streams().Get("t.*")
t.NoError(err)
t.Equal(uint(2), stream.AccountTokenPosition())
}

Expand Down Expand Up @@ -272,10 +272,10 @@ func (t *ProviderSuite) Test_StreamExportCrud() {
t.NoError(err)
t.Len(a.Exports().Streams().List(), 1)

_, ok := a.Exports().Streams().Get("q.>")
t.True(ok)
_, err = a.Exports().Streams().Get("q.>")
t.NoError(err)

_, ok = a.Exports().Streams().GetByName("q")
_, ok := a.Exports().Streams().GetByName("q")
t.True(ok)

x, err := authb.NewStreamExport("x", "x.>")
Expand Down
8 changes: 4 additions & 4 deletions tests/revocations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func (t *ProviderSuite) Test_ExportRevocationRequiresAccountToken() {
t.Len(revocations, 1)
t.Equal(ak.Public, revocations[0].PublicKey())

stream, ok := a.Exports().Streams().Get("t.>")
t.True(ok)
stream, err = a.Exports().Streams().Get("t.>")
t.NoError(err)
revocations = stream.Revocations().List()
t.Len(revocations, 1)
t.Equal(ak.Public, revocations[0].PublicKey())
Expand Down Expand Up @@ -91,8 +91,8 @@ func (t *ProviderSuite) Test_ExportRevocationWildCardIsAllowed() {
t.Len(revocations, 1)
t.Equal("*", revocations[0].PublicKey())

stream, ok := a.Exports().Streams().Get("t.>")
t.True(ok)
stream, err = a.Exports().Streams().Get("t.>")
t.NoError(err)
revocations = stream.Revocations().List()
t.Len(revocations, 1)
t.Equal("*", revocations[0].PublicKey())
Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ type StreamExports interface {
// AddWithConfig adds a copy of the specified configuration to the account
AddWithConfig(e StreamExport) error
// Get returns the StreamExport matching the subject or nil if not found
Get(subject string) (StreamExport, bool)
Get(subject string) (StreamExport, error)
// Delete deletes the StreamExport matching the subject
Delete(subject string) (bool, error)
// GetByName returns the StreamExport matching the specified name,
Expand Down

0 comments on commit 197eedb

Please sign in to comment.