diff --git a/stream_exports.go b/stream_exports.go index 37d2956..de69089 100644 --- a/stream_exports.go +++ b/stream_exports.go @@ -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 { diff --git a/tests/exports_test.go b/tests/exports_test.go index 7b9dc03..c66def7 100644 --- a/tests/exports_test.go +++ b/tests/exports_test.go @@ -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() { @@ -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) @@ -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) diff --git a/types.go b/types.go index 5d2d671..f698201 100644 --- a/types.go +++ b/types.go @@ -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