@@ -77,6 +77,12 @@ func (m *ClientMock) MockIterWithCallback(prefix string, objects []string, err e
7777// Get mocks objstore.Bucket.Get()
7878func (m * ClientMock ) Get (ctx context.Context , name string ) (io.ReadCloser , error ) {
7979 args := m .Called (ctx , name )
80+
81+ // Allow to mock the Get() with a function which is called each time.
82+ if fn , ok := args .Get (0 ).(func (ctx context.Context , name string ) (io.ReadCloser , error )); ok {
83+ return fn (ctx , name )
84+ }
85+
8086 val , err := args .Get (0 ), args .Error (1 )
8187 if val == nil {
8288 return nil , err
@@ -96,9 +102,8 @@ func (m *ClientMock) MockGet(name, content string, err error) {
96102 // Since we return an ReadCloser and it can be consumed only once,
97103 // each time the mocked Get() is called we do create a new one, so
98104 // that getting the same mocked object twice works as expected.
99- mockedGet := m .On ("Get" , mock .Anything , name )
100- mockedGet .Run (func (args mock.Arguments ) {
101- mockedGet .Return (ioutil .NopCloser (bytes .NewReader ([]byte (content ))), err )
105+ m .On ("Get" , mock .Anything , name ).Return (func (_ context.Context , _ string ) (io.ReadCloser , error ) {
106+ return ioutil .NopCloser (bytes .NewReader ([]byte (content ))), err
102107 })
103108 } else {
104109 m .On ("Exists" , mock .Anything , name ).Return (false , err )
0 commit comments