Skip to content

Commit

Permalink
service imports Get/GetByName
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Mar 8, 2024
1 parent 210a3e2 commit a4c0cd8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
12 changes: 6 additions & 6 deletions service_imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 15 additions & 15 deletions tests/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.>")
Expand All @@ -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)
Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a4c0cd8

Please sign in to comment.