Skip to content

Commit

Permalink
[CHANGE] changed stream exports get by name to return err instead of …
Browse files Browse the repository at this point in the history
…bool
  • Loading branch information
aricart committed Mar 6, 2024
1 parent 197eedb commit 714eb00
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions stream_exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ func (s *streamExports) Delete(subject string) (bool, error) {
return s.deleteExport(subject, false)
}

func (s *streamExports) GetByName(name string) (StreamExport, bool) {
func (s *streamExports) GetByName(name string) (StreamExport, error) {
for _, e := range s.Claim.Exports {
if e.IsStream() && e.Name == name {
se := &StreamExportImpl{}
se.data = s.AccountData
se.export = e
return se, true
return se, nil
}
}
return nil, false
return nil, ErrNotFound
}

func (s *streamExports) List() []StreamExport {
Expand Down
14 changes: 7 additions & 7 deletions tests/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ func (t *ProviderSuite) Test_ExportNameSubject() {

_, err = a.Exports().Streams().Get("t.>")
t.ErrorIs(err, authb.ErrNotFound)
_, ok := a.Exports().Streams().GetByName("s")
t.False(ok)
_, err = a.Exports().Streams().GetByName("s")
t.ErrorIs(err, authb.ErrNotFound)
_, err = a.Exports().Streams().Get("st.>")
t.NoError(err)
_, ok = a.Exports().Streams().GetByName("ss")
t.True(ok)
_, err = a.Exports().Streams().GetByName("ss")
t.NoError(err)
}

func (t *ProviderSuite) Test_ExportDescription() {
Expand Down Expand Up @@ -275,8 +275,8 @@ func (t *ProviderSuite) Test_StreamExportCrud() {
_, err = a.Exports().Streams().Get("q.>")
t.NoError(err)

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

x, err := authb.NewStreamExport("x", "x.>")
t.NoError(err)
Expand All @@ -289,7 +289,7 @@ func (t *ProviderSuite) Test_StreamExportCrud() {
t.Equal("x.>", a.Exports().Streams().List()[0].Subject())
t.Equal("y.>", a.Exports().Streams().List()[1].Subject())

ok, err = a.Exports().Streams().Delete("x.>")
ok, err := a.Exports().Streams().Delete("x.>")
t.NoError(err)
t.True(ok)

Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ type StreamExports interface {
Delete(subject string) (bool, error)
// GetByName returns the StreamExport matching the specified name,
// note that the first stream is returned
GetByName(name string) (StreamExport, bool)
GetByName(name string) (StreamExport, error)
// List returns a list of StreamExport in the account
List() []StreamExport
// Set replaces all streamExports with the specified ones
Expand Down

0 comments on commit 714eb00

Please sign in to comment.