diff --git a/service_imports.go b/service_imports.go index 7c2d0a6..a1b7edc 100644 --- a/service_imports.go +++ b/service_imports.go @@ -39,24 +39,24 @@ func (s *serviceImports) AddWithConfig(i ServiceImport) error { return s.update() } -func (s *serviceImports) Get(subject string) (ServiceImport, bool) { +func (s *serviceImports) Get(subject string) (ServiceImport, error) { si := s.getServiceImport(subject) if si != nil { - return si, true + return si, nil } - return nil, false + return nil, ErrNotFound } -func (s *serviceImports) GetByName(name string) (ServiceImport, bool) { +func (s *serviceImports) GetByName(name string) (ServiceImport, error) { for _, e := range s.Claim.Imports { if e.IsService() && e.Name == name { se := &ServiceImportImpl{} se.data = s.AccountData se.in = e - return se, true + return se, nil } } - return nil, false + return nil, ErrNotFound } func (s *serviceImports) Delete(subject string) (bool, error) { diff --git a/tests/imports_test.go b/tests/imports_test.go index 9e5b0d3..f7f9a6a 100644 --- a/tests/imports_test.go +++ b/tests/imports_test.go @@ -76,14 +76,14 @@ func (t *ProviderSuite) Test_ImportNameSubject() { t.NoError(im.SetSubject("qq.>")) t.NoError(im.SetAccount(akk.Public)) - _, ok := a.Imports().Services().Get("q.>") - t.False(ok) - _, ok = a.Imports().Services().GetByName("q") - t.False(ok) - _, ok = a.Imports().Services().Get("qq.>") - t.True(ok) - _, ok = a.Imports().Services().GetByName("xx") - t.True(ok) + _, err = a.Imports().Services().Get("q.>") + t.ErrorIs(err, authb.ErrNotFound) + _, err = a.Imports().Services().GetByName("q") + t.ErrorIs(err, authb.ErrNotFound) + _, err = a.Imports().Services().Get("qq.>") + t.NoError(err) + _, err = a.Imports().Services().GetByName("xx") + t.NoError(err) s, err := a.Imports().Streams().Add("s", ak.Public, "t.>") t.NoError(err) @@ -132,8 +132,8 @@ func (t *ProviderSuite) Test_ImportLocalSubject() { t.NoError(auth.Reload()) a = t.GetAccount(auth, "O", "A") - im, ok := a.Imports().Services().Get("q") - t.True(ok) + im, err = a.Imports().Services().Get("q") + t.NoError(err) t.Equal("myq", im.LocalSubject()) s, err = a.Imports().Streams().Get("t.>") @@ -153,11 +153,11 @@ func (t *ProviderSuite) Test_ServiceImportCrud() { t.NoError(err) t.NotNil(im) - _, ok := a.Imports().Services().Get("q.>") - t.True(ok) + _, err = a.Imports().Services().Get("q.>") + t.NoError(err) - _, ok = a.Imports().Services().GetByName("q") - t.True(ok) + _, err = a.Imports().Services().GetByName("q") + t.NoError(err) x, err := authb.NewServiceImport("x", ak.Public, "x.>") t.NoError(err) @@ -172,7 +172,7 @@ func (t *ProviderSuite) Test_ServiceImportCrud() { t.Equal("x.>", a.Imports().Services().List()[0].Subject()) t.Equal("y.>", a.Imports().Services().List()[1].Subject()) - ok, err = a.Imports().Services().Delete("x.>") + ok, err := a.Imports().Services().Delete("x.>") t.NoError(err) t.True(ok) diff --git a/types.go b/types.go index 489af1d..f81d73f 100644 --- a/types.go +++ b/types.go @@ -486,10 +486,10 @@ type ServiceImports interface { // AddWithConfig adds a copy of the specified import configuration to the account AddWithConfig(i ServiceImport) error // Get returns imports that are exported by accounts under the specified subject - Get(subject string) (ServiceImport, bool) + Get(subject string) (ServiceImport, error) // GetByName returns an import stored under the specified name. Note that // the first import is returned. - GetByName(name string) (ServiceImport, bool) + GetByName(name string) (ServiceImport, error) Delete(subject string) (bool, error) List() []ServiceImport Set(imports ...ServiceImport) error