-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add service interface with Mock (#7)
Signed-off-by: Igor Shishkin <me@teran.dev>
- Loading branch information
Showing
2 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package service | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
var _ ManageService = (*Mock)(nil) | ||
|
||
type Mock struct { | ||
mock.Mock | ||
} | ||
|
||
func NewMock() *Mock { | ||
return &Mock{} | ||
} | ||
|
||
func (m *Mock) CreateContainer(_ context.Context, name string) error { | ||
args := m.Called(name) | ||
return args.Error(0) | ||
} | ||
|
||
func (m *Mock) ListContainers(context.Context) ([]string, error) { | ||
args := m.Called() | ||
return args.Get(0).([]string), args.Error(1) | ||
} | ||
|
||
func (m *Mock) DeleteContainer(_ context.Context, name string) error { | ||
args := m.Called(name) | ||
return args.Error(0) | ||
} | ||
|
||
func (m *Mock) CreateVersion(_ context.Context, container string) (id string, err error) { | ||
args := m.Called(container) | ||
return args.Get(0).(string), args.Error(1) | ||
} | ||
|
||
func (m *Mock) ListVersions(_ context.Context, container string) ([]string, error) { | ||
args := m.Called(container) | ||
return args.Get(0).([]string), args.Error(1) | ||
} | ||
|
||
func (m *Mock) PublishVersion(_ context.Context, container, id string) error { | ||
args := m.Called(container, id) | ||
return args.Error(0) | ||
} | ||
|
||
func (m *Mock) DeleteVersion(_ context.Context, container, id string) error { | ||
args := m.Called(container, id) | ||
return args.Error(0) | ||
} | ||
|
||
func (m *Mock) AddObject(_ context.Context, container, versionID, key string, objReader io.Reader) error { | ||
data, err := io.ReadAll(objReader) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
args := m.Called(container, versionID, key, data) | ||
return args.Error(0) | ||
} | ||
|
||
func (m *Mock) ListObjects(_ context.Context, container, versionID string) ([]string, error) { | ||
args := m.Called(container, versionID) | ||
return args.Get(0).([]string), args.Error(1) | ||
} | ||
|
||
func (m *Mock) GetObjectURL(ctx context.Context, container, versionID, key string) (string, error) { | ||
args := m.Called(container, versionID, key) | ||
return args.String(0), args.Error(1) | ||
} | ||
|
||
func (m *Mock) DeleteObject(_ context.Context, container, versionID, key string) error { | ||
args := m.Called(container) | ||
return args.Error(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package service | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
"github.com/teran/archived/repositories/blob" | ||
"github.com/teran/archived/repositories/metadata" | ||
) | ||
|
||
type ManageService interface { | ||
AccessService | ||
|
||
CreateContainer(ctx context.Context, name string) error | ||
DeleteContainer(ctx context.Context, name string) error | ||
|
||
CreateVersion(ctx context.Context, container string) (id string, err error) | ||
PublishVersion(ctx context.Context, container, id string) error | ||
DeleteVersion(ctx context.Context, container, id string) error | ||
|
||
AddObject(ctx context.Context, container, versionID, key string, objReader io.Reader) error | ||
DeleteObject(ctx context.Context, container, versionID, key string) error | ||
} | ||
|
||
type AccessService interface { | ||
ListContainers(ctx context.Context) ([]string, error) | ||
|
||
ListVersions(ctx context.Context, container string) ([]string, error) | ||
|
||
ListObjects(ctx context.Context, container, versionID string) ([]string, error) | ||
GetObjectURL(ctx context.Context, container, versionID, key string) (string, error) | ||
} | ||
|
||
type service struct { | ||
mdRepo metadata.Repository | ||
blobRepo blob.Repository | ||
} | ||
|
||
func NewManageService(mdRepo metadata.Repository, blobRepo blob.Repository) ManageService { | ||
return &service{} | ||
} | ||
|
||
func NewAccessService(mdRepo metadata.Repository, blobRepo blob.Repository) AccessService { | ||
return &service{} | ||
} | ||
|
||
func (s *service) CreateContainer(ctx context.Context, name string) error { | ||
return s.mdRepo.CreateContainer(ctx, name) | ||
} | ||
|
||
func (s *service) ListContainers(ctx context.Context) ([]string, error) { | ||
return s.mdRepo.ListContainers(ctx) | ||
} | ||
|
||
func (s *service) DeleteContainer(ctx context.Context, name string) error { | ||
return s.mdRepo.DeleteContainer(ctx, name) | ||
} | ||
|
||
func (s *service) CreateVersion(ctx context.Context, container string) (id string, err error) { | ||
panic("not implemented") | ||
} | ||
|
||
func (s *service) ListVersions(ctx context.Context, container string) ([]string, error) { | ||
panic("not implemented") | ||
} | ||
|
||
func (s *service) PublishVersion(ctx context.Context, container, id string) error { | ||
panic("not implemented") | ||
} | ||
|
||
func (s *service) DeleteVersion(ctx context.Context, container, id string) error { | ||
panic("not implemented") | ||
} | ||
|
||
func (s *service) AddObject(ctx context.Context, container, versionID, key string, objReader io.Reader) error { | ||
panic("not implemented") | ||
} | ||
|
||
func (s *service) ListObjects(ctx context.Context, container, versionID string) ([]string, error) { | ||
panic("not implemented") | ||
} | ||
|
||
func (s *service) GetObjectURL(ctx context.Context, container, versionID, key string) (string, error) { | ||
panic("not implemented") | ||
} | ||
|
||
func (s *service) DeleteObject(ctx context.Context, container, versionID, key string) error { | ||
panic("not implemented") | ||
} |