From f0e2256ff134284839ef843d0c53b6dbad38ecc0 Mon Sep 17 00:00:00 2001 From: Katrina Rogan Date: Fri, 16 Apr 2021 09:25:53 -0700 Subject: [PATCH] Generate mocks for data storage for use in tests (#79) --- storage/mocks/composed_protobuf_store.go | 261 +++++++++++++++++++++++ storage/mocks/raw_store.go | 195 +++++++++++++++++ storage/mocks/reference_constructor.go | 61 ++++++ storage/storage.go | 6 + 4 files changed, 523 insertions(+) create mode 100644 storage/mocks/composed_protobuf_store.go create mode 100644 storage/mocks/raw_store.go create mode 100644 storage/mocks/reference_constructor.go diff --git a/storage/mocks/composed_protobuf_store.go b/storage/mocks/composed_protobuf_store.go new file mode 100644 index 0000000000..4bd5c31850 --- /dev/null +++ b/storage/mocks/composed_protobuf_store.go @@ -0,0 +1,261 @@ +// Code generated by mockery v1.0.1. DO NOT EDIT. + +package mocks + +import ( + context "context" + io "io" + + mock "github.com/stretchr/testify/mock" + + protoiface "google.golang.org/protobuf/runtime/protoiface" + + storage "github.com/flyteorg/flytestdlib/storage" +) + +// ComposedProtobufStore is an autogenerated mock type for the ComposedProtobufStore type +type ComposedProtobufStore struct { + mock.Mock +} + +type ComposedProtobufStore_CopyRaw struct { + *mock.Call +} + +func (_m ComposedProtobufStore_CopyRaw) Return(_a0 error) *ComposedProtobufStore_CopyRaw { + return &ComposedProtobufStore_CopyRaw{Call: _m.Call.Return(_a0)} +} + +func (_m *ComposedProtobufStore) OnCopyRaw(ctx context.Context, source storage.DataReference, destination storage.DataReference, opts storage.Options) *ComposedProtobufStore_CopyRaw { + c := _m.On("CopyRaw", ctx, source, destination, opts) + return &ComposedProtobufStore_CopyRaw{Call: c} +} + +func (_m *ComposedProtobufStore) OnCopyRawMatch(matchers ...interface{}) *ComposedProtobufStore_CopyRaw { + c := _m.On("CopyRaw", matchers...) + return &ComposedProtobufStore_CopyRaw{Call: c} +} + +// CopyRaw provides a mock function with given fields: ctx, source, destination, opts +func (_m *ComposedProtobufStore) CopyRaw(ctx context.Context, source storage.DataReference, destination storage.DataReference, opts storage.Options) error { + ret := _m.Called(ctx, source, destination, opts) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, storage.DataReference, storage.DataReference, storage.Options) error); ok { + r0 = rf(ctx, source, destination, opts) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type ComposedProtobufStore_GetBaseContainerFQN struct { + *mock.Call +} + +func (_m ComposedProtobufStore_GetBaseContainerFQN) Return(_a0 storage.DataReference) *ComposedProtobufStore_GetBaseContainerFQN { + return &ComposedProtobufStore_GetBaseContainerFQN{Call: _m.Call.Return(_a0)} +} + +func (_m *ComposedProtobufStore) OnGetBaseContainerFQN(ctx context.Context) *ComposedProtobufStore_GetBaseContainerFQN { + c := _m.On("GetBaseContainerFQN", ctx) + return &ComposedProtobufStore_GetBaseContainerFQN{Call: c} +} + +func (_m *ComposedProtobufStore) OnGetBaseContainerFQNMatch(matchers ...interface{}) *ComposedProtobufStore_GetBaseContainerFQN { + c := _m.On("GetBaseContainerFQN", matchers...) + return &ComposedProtobufStore_GetBaseContainerFQN{Call: c} +} + +// GetBaseContainerFQN provides a mock function with given fields: ctx +func (_m *ComposedProtobufStore) GetBaseContainerFQN(ctx context.Context) storage.DataReference { + ret := _m.Called(ctx) + + var r0 storage.DataReference + if rf, ok := ret.Get(0).(func(context.Context) storage.DataReference); ok { + r0 = rf(ctx) + } else { + r0 = ret.Get(0).(storage.DataReference) + } + + return r0 +} + +type ComposedProtobufStore_Head struct { + *mock.Call +} + +func (_m ComposedProtobufStore_Head) Return(_a0 storage.Metadata, _a1 error) *ComposedProtobufStore_Head { + return &ComposedProtobufStore_Head{Call: _m.Call.Return(_a0, _a1)} +} + +func (_m *ComposedProtobufStore) OnHead(ctx context.Context, reference storage.DataReference) *ComposedProtobufStore_Head { + c := _m.On("Head", ctx, reference) + return &ComposedProtobufStore_Head{Call: c} +} + +func (_m *ComposedProtobufStore) OnHeadMatch(matchers ...interface{}) *ComposedProtobufStore_Head { + c := _m.On("Head", matchers...) + return &ComposedProtobufStore_Head{Call: c} +} + +// Head provides a mock function with given fields: ctx, reference +func (_m *ComposedProtobufStore) Head(ctx context.Context, reference storage.DataReference) (storage.Metadata, error) { + ret := _m.Called(ctx, reference) + + var r0 storage.Metadata + if rf, ok := ret.Get(0).(func(context.Context, storage.DataReference) storage.Metadata); ok { + r0 = rf(ctx, reference) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(storage.Metadata) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, storage.DataReference) error); ok { + r1 = rf(ctx, reference) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +type ComposedProtobufStore_ReadProtobuf struct { + *mock.Call +} + +func (_m ComposedProtobufStore_ReadProtobuf) Return(_a0 error) *ComposedProtobufStore_ReadProtobuf { + return &ComposedProtobufStore_ReadProtobuf{Call: _m.Call.Return(_a0)} +} + +func (_m *ComposedProtobufStore) OnReadProtobuf(ctx context.Context, reference storage.DataReference, msg protoiface.MessageV1) *ComposedProtobufStore_ReadProtobuf { + c := _m.On("ReadProtobuf", ctx, reference, msg) + return &ComposedProtobufStore_ReadProtobuf{Call: c} +} + +func (_m *ComposedProtobufStore) OnReadProtobufMatch(matchers ...interface{}) *ComposedProtobufStore_ReadProtobuf { + c := _m.On("ReadProtobuf", matchers...) + return &ComposedProtobufStore_ReadProtobuf{Call: c} +} + +// ReadProtobuf provides a mock function with given fields: ctx, reference, msg +func (_m *ComposedProtobufStore) ReadProtobuf(ctx context.Context, reference storage.DataReference, msg protoiface.MessageV1) error { + ret := _m.Called(ctx, reference, msg) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, storage.DataReference, protoiface.MessageV1) error); ok { + r0 = rf(ctx, reference, msg) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type ComposedProtobufStore_ReadRaw struct { + *mock.Call +} + +func (_m ComposedProtobufStore_ReadRaw) Return(_a0 io.ReadCloser, _a1 error) *ComposedProtobufStore_ReadRaw { + return &ComposedProtobufStore_ReadRaw{Call: _m.Call.Return(_a0, _a1)} +} + +func (_m *ComposedProtobufStore) OnReadRaw(ctx context.Context, reference storage.DataReference) *ComposedProtobufStore_ReadRaw { + c := _m.On("ReadRaw", ctx, reference) + return &ComposedProtobufStore_ReadRaw{Call: c} +} + +func (_m *ComposedProtobufStore) OnReadRawMatch(matchers ...interface{}) *ComposedProtobufStore_ReadRaw { + c := _m.On("ReadRaw", matchers...) + return &ComposedProtobufStore_ReadRaw{Call: c} +} + +// ReadRaw provides a mock function with given fields: ctx, reference +func (_m *ComposedProtobufStore) ReadRaw(ctx context.Context, reference storage.DataReference) (io.ReadCloser, error) { + ret := _m.Called(ctx, reference) + + var r0 io.ReadCloser + if rf, ok := ret.Get(0).(func(context.Context, storage.DataReference) io.ReadCloser); ok { + r0 = rf(ctx, reference) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(io.ReadCloser) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, storage.DataReference) error); ok { + r1 = rf(ctx, reference) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +type ComposedProtobufStore_WriteProtobuf struct { + *mock.Call +} + +func (_m ComposedProtobufStore_WriteProtobuf) Return(_a0 error) *ComposedProtobufStore_WriteProtobuf { + return &ComposedProtobufStore_WriteProtobuf{Call: _m.Call.Return(_a0)} +} + +func (_m *ComposedProtobufStore) OnWriteProtobuf(ctx context.Context, reference storage.DataReference, opts storage.Options, msg protoiface.MessageV1) *ComposedProtobufStore_WriteProtobuf { + c := _m.On("WriteProtobuf", ctx, reference, opts, msg) + return &ComposedProtobufStore_WriteProtobuf{Call: c} +} + +func (_m *ComposedProtobufStore) OnWriteProtobufMatch(matchers ...interface{}) *ComposedProtobufStore_WriteProtobuf { + c := _m.On("WriteProtobuf", matchers...) + return &ComposedProtobufStore_WriteProtobuf{Call: c} +} + +// WriteProtobuf provides a mock function with given fields: ctx, reference, opts, msg +func (_m *ComposedProtobufStore) WriteProtobuf(ctx context.Context, reference storage.DataReference, opts storage.Options, msg protoiface.MessageV1) error { + ret := _m.Called(ctx, reference, opts, msg) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, storage.DataReference, storage.Options, protoiface.MessageV1) error); ok { + r0 = rf(ctx, reference, opts, msg) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type ComposedProtobufStore_WriteRaw struct { + *mock.Call +} + +func (_m ComposedProtobufStore_WriteRaw) Return(_a0 error) *ComposedProtobufStore_WriteRaw { + return &ComposedProtobufStore_WriteRaw{Call: _m.Call.Return(_a0)} +} + +func (_m *ComposedProtobufStore) OnWriteRaw(ctx context.Context, reference storage.DataReference, size int64, opts storage.Options, raw io.Reader) *ComposedProtobufStore_WriteRaw { + c := _m.On("WriteRaw", ctx, reference, size, opts, raw) + return &ComposedProtobufStore_WriteRaw{Call: c} +} + +func (_m *ComposedProtobufStore) OnWriteRawMatch(matchers ...interface{}) *ComposedProtobufStore_WriteRaw { + c := _m.On("WriteRaw", matchers...) + return &ComposedProtobufStore_WriteRaw{Call: c} +} + +// WriteRaw provides a mock function with given fields: ctx, reference, size, opts, raw +func (_m *ComposedProtobufStore) WriteRaw(ctx context.Context, reference storage.DataReference, size int64, opts storage.Options, raw io.Reader) error { + ret := _m.Called(ctx, reference, size, opts, raw) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, storage.DataReference, int64, storage.Options, io.Reader) error); ok { + r0 = rf(ctx, reference, size, opts, raw) + } else { + r0 = ret.Error(0) + } + + return r0 +} diff --git a/storage/mocks/raw_store.go b/storage/mocks/raw_store.go new file mode 100644 index 0000000000..1ec9815b0c --- /dev/null +++ b/storage/mocks/raw_store.go @@ -0,0 +1,195 @@ +// Code generated by mockery v1.0.1. DO NOT EDIT. + +package mocks + +import ( + context "context" + io "io" + + mock "github.com/stretchr/testify/mock" + + storage "github.com/flyteorg/flytestdlib/storage" +) + +// RawStore is an autogenerated mock type for the RawStore type +type RawStore struct { + mock.Mock +} + +type RawStore_CopyRaw struct { + *mock.Call +} + +func (_m RawStore_CopyRaw) Return(_a0 error) *RawStore_CopyRaw { + return &RawStore_CopyRaw{Call: _m.Call.Return(_a0)} +} + +func (_m *RawStore) OnCopyRaw(ctx context.Context, source storage.DataReference, destination storage.DataReference, opts storage.Options) *RawStore_CopyRaw { + c := _m.On("CopyRaw", ctx, source, destination, opts) + return &RawStore_CopyRaw{Call: c} +} + +func (_m *RawStore) OnCopyRawMatch(matchers ...interface{}) *RawStore_CopyRaw { + c := _m.On("CopyRaw", matchers...) + return &RawStore_CopyRaw{Call: c} +} + +// CopyRaw provides a mock function with given fields: ctx, source, destination, opts +func (_m *RawStore) CopyRaw(ctx context.Context, source storage.DataReference, destination storage.DataReference, opts storage.Options) error { + ret := _m.Called(ctx, source, destination, opts) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, storage.DataReference, storage.DataReference, storage.Options) error); ok { + r0 = rf(ctx, source, destination, opts) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type RawStore_GetBaseContainerFQN struct { + *mock.Call +} + +func (_m RawStore_GetBaseContainerFQN) Return(_a0 storage.DataReference) *RawStore_GetBaseContainerFQN { + return &RawStore_GetBaseContainerFQN{Call: _m.Call.Return(_a0)} +} + +func (_m *RawStore) OnGetBaseContainerFQN(ctx context.Context) *RawStore_GetBaseContainerFQN { + c := _m.On("GetBaseContainerFQN", ctx) + return &RawStore_GetBaseContainerFQN{Call: c} +} + +func (_m *RawStore) OnGetBaseContainerFQNMatch(matchers ...interface{}) *RawStore_GetBaseContainerFQN { + c := _m.On("GetBaseContainerFQN", matchers...) + return &RawStore_GetBaseContainerFQN{Call: c} +} + +// GetBaseContainerFQN provides a mock function with given fields: ctx +func (_m *RawStore) GetBaseContainerFQN(ctx context.Context) storage.DataReference { + ret := _m.Called(ctx) + + var r0 storage.DataReference + if rf, ok := ret.Get(0).(func(context.Context) storage.DataReference); ok { + r0 = rf(ctx) + } else { + r0 = ret.Get(0).(storage.DataReference) + } + + return r0 +} + +type RawStore_Head struct { + *mock.Call +} + +func (_m RawStore_Head) Return(_a0 storage.Metadata, _a1 error) *RawStore_Head { + return &RawStore_Head{Call: _m.Call.Return(_a0, _a1)} +} + +func (_m *RawStore) OnHead(ctx context.Context, reference storage.DataReference) *RawStore_Head { + c := _m.On("Head", ctx, reference) + return &RawStore_Head{Call: c} +} + +func (_m *RawStore) OnHeadMatch(matchers ...interface{}) *RawStore_Head { + c := _m.On("Head", matchers...) + return &RawStore_Head{Call: c} +} + +// Head provides a mock function with given fields: ctx, reference +func (_m *RawStore) Head(ctx context.Context, reference storage.DataReference) (storage.Metadata, error) { + ret := _m.Called(ctx, reference) + + var r0 storage.Metadata + if rf, ok := ret.Get(0).(func(context.Context, storage.DataReference) storage.Metadata); ok { + r0 = rf(ctx, reference) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(storage.Metadata) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, storage.DataReference) error); ok { + r1 = rf(ctx, reference) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +type RawStore_ReadRaw struct { + *mock.Call +} + +func (_m RawStore_ReadRaw) Return(_a0 io.ReadCloser, _a1 error) *RawStore_ReadRaw { + return &RawStore_ReadRaw{Call: _m.Call.Return(_a0, _a1)} +} + +func (_m *RawStore) OnReadRaw(ctx context.Context, reference storage.DataReference) *RawStore_ReadRaw { + c := _m.On("ReadRaw", ctx, reference) + return &RawStore_ReadRaw{Call: c} +} + +func (_m *RawStore) OnReadRawMatch(matchers ...interface{}) *RawStore_ReadRaw { + c := _m.On("ReadRaw", matchers...) + return &RawStore_ReadRaw{Call: c} +} + +// ReadRaw provides a mock function with given fields: ctx, reference +func (_m *RawStore) ReadRaw(ctx context.Context, reference storage.DataReference) (io.ReadCloser, error) { + ret := _m.Called(ctx, reference) + + var r0 io.ReadCloser + if rf, ok := ret.Get(0).(func(context.Context, storage.DataReference) io.ReadCloser); ok { + r0 = rf(ctx, reference) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(io.ReadCloser) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, storage.DataReference) error); ok { + r1 = rf(ctx, reference) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +type RawStore_WriteRaw struct { + *mock.Call +} + +func (_m RawStore_WriteRaw) Return(_a0 error) *RawStore_WriteRaw { + return &RawStore_WriteRaw{Call: _m.Call.Return(_a0)} +} + +func (_m *RawStore) OnWriteRaw(ctx context.Context, reference storage.DataReference, size int64, opts storage.Options, raw io.Reader) *RawStore_WriteRaw { + c := _m.On("WriteRaw", ctx, reference, size, opts, raw) + return &RawStore_WriteRaw{Call: c} +} + +func (_m *RawStore) OnWriteRawMatch(matchers ...interface{}) *RawStore_WriteRaw { + c := _m.On("WriteRaw", matchers...) + return &RawStore_WriteRaw{Call: c} +} + +// WriteRaw provides a mock function with given fields: ctx, reference, size, opts, raw +func (_m *RawStore) WriteRaw(ctx context.Context, reference storage.DataReference, size int64, opts storage.Options, raw io.Reader) error { + ret := _m.Called(ctx, reference, size, opts, raw) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, storage.DataReference, int64, storage.Options, io.Reader) error); ok { + r0 = rf(ctx, reference, size, opts, raw) + } else { + r0 = ret.Error(0) + } + + return r0 +} diff --git a/storage/mocks/reference_constructor.go b/storage/mocks/reference_constructor.go new file mode 100644 index 0000000000..08bc957daa --- /dev/null +++ b/storage/mocks/reference_constructor.go @@ -0,0 +1,61 @@ +// Code generated by mockery v1.0.1. DO NOT EDIT. + +package mocks + +import ( + context "context" + + storage "github.com/flyteorg/flytestdlib/storage" + mock "github.com/stretchr/testify/mock" +) + +// ReferenceConstructor is an autogenerated mock type for the ReferenceConstructor type +type ReferenceConstructor struct { + mock.Mock +} + +type ReferenceConstructor_ConstructReference struct { + *mock.Call +} + +func (_m ReferenceConstructor_ConstructReference) Return(_a0 storage.DataReference, _a1 error) *ReferenceConstructor_ConstructReference { + return &ReferenceConstructor_ConstructReference{Call: _m.Call.Return(_a0, _a1)} +} + +func (_m *ReferenceConstructor) OnConstructReference(ctx context.Context, reference storage.DataReference, nestedKeys ...string) *ReferenceConstructor_ConstructReference { + c := _m.On("ConstructReference", ctx, reference, nestedKeys) + return &ReferenceConstructor_ConstructReference{Call: c} +} + +func (_m *ReferenceConstructor) OnConstructReferenceMatch(matchers ...interface{}) *ReferenceConstructor_ConstructReference { + c := _m.On("ConstructReference", matchers...) + return &ReferenceConstructor_ConstructReference{Call: c} +} + +// ConstructReference provides a mock function with given fields: ctx, reference, nestedKeys +func (_m *ReferenceConstructor) ConstructReference(ctx context.Context, reference storage.DataReference, nestedKeys ...string) (storage.DataReference, error) { + _va := make([]interface{}, len(nestedKeys)) + for _i := range nestedKeys { + _va[_i] = nestedKeys[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, reference) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 storage.DataReference + if rf, ok := ret.Get(0).(func(context.Context, storage.DataReference, ...string) storage.DataReference); ok { + r0 = rf(ctx, reference, nestedKeys...) + } else { + r0 = ret.Get(0).(storage.DataReference) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, storage.DataReference, ...string) error); ok { + r1 = rf(ctx, reference, nestedKeys...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} diff --git a/storage/storage.go b/storage/storage.go index ffbc2c62b0..c6dbdde9fd 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -40,6 +40,8 @@ type DataStore struct { ReferenceConstructor } +//go:generate mockery -name RawStore -case=underscore + // Defines a low level interface for accessing and storing bytes. type RawStore interface { // returns a FQN DataReference with the configured base init container @@ -58,6 +60,8 @@ type RawStore interface { CopyRaw(ctx context.Context, source, destination DataReference, opts Options) error } +//go:generate mockery -name ReferenceConstructor -case=underscore + // Defines an interface for building data reference paths. type ReferenceConstructor interface { // Creates a new dataReference that matches the storage structure. @@ -73,6 +77,8 @@ type ProtobufStore interface { WriteProtobuf(ctx context.Context, reference DataReference, opts Options, msg proto.Message) error } +//go:generate mockery -name ComposedProtobufStore -case=underscore + // A ProtobufStore needs a RawStore to get the RawData. This interface provides all the necessary components to make // Protobuf fetching work type ComposedProtobufStore interface {