From bf11b770bc43b450e8107aa6bf4383ed2d54cf1b Mon Sep 17 00:00:00 2001 From: Igor Shishkin Date: Sun, 7 Jul 2024 11:13:07 +0300 Subject: [PATCH] Add BLOB repository mock Signed-off-by: Igor Shishkin --- go.mod | 9 +++++++++ go.sum | 12 ++++++++++++ repositories/blob/mock/mock.go | 35 ++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 go.sum create mode 100644 repositories/blob/mock/mock.go diff --git a/go.mod b/go.mod index d717a08..68efd06 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,12 @@ module github.com/teran/archived go 1.22.5 + +require github.com/stretchr/testify v1.9.0 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/objx v0.5.2 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..8565daa --- /dev/null +++ b/go.sum @@ -0,0 +1,12 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/repositories/blob/mock/mock.go b/repositories/blob/mock/mock.go new file mode 100644 index 0000000..b29d6fa --- /dev/null +++ b/repositories/blob/mock/mock.go @@ -0,0 +1,35 @@ +package mock + +import ( + "context" + "io" + + "github.com/stretchr/testify/mock" + + "github.com/teran/archived/repositories/blob" +) + +var _ blob.Repository = (*Mock)(nil) + +type Mock struct { + mock.Mock +} + +func New() *Mock { + return &Mock{} +} + +func (m *Mock) PutBlob(_ context.Context, key string, rd io.Reader) error { + data, err := io.ReadAll(rd) + if err != nil { + return err + } + + args := m.Called(key, data) + return args.Error(0) +} + +func (m *Mock) GetBlobURL(_ context.Context, key string) (string, error) { + args := m.Called(key) + return args.String(0), args.Error(1) +}