aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2025-04-02 14:08:08 +0200
committerTaras Madan <tarasmadan@google.com>2025-04-02 15:59:20 +0000
commitfe048bb3c75adb6fef7300aad81e18aabce4a075 (patch)
treecb57f090c5685b34a5746f7c85be2ecf3e776a3b /pkg
parent6c9acf7b44179e7c4c1549f1965a814199cb16a2 (diff)
pkg/gcs: simplify interface, remove proxy type
Diffstat (limited to 'pkg')
-rw-r--r--pkg/covermerger/bq_csv_reader.go6
-rw-r--r--pkg/gcs/gcs.go22
-rw-r--r--pkg/gcs/mocks/Client.go116
3 files changed, 62 insertions, 82 deletions
diff --git a/pkg/covermerger/bq_csv_reader.go b/pkg/covermerger/bq_csv_reader.go
index f78ac4f18..483af792e 100644
--- a/pkg/covermerger/bq_csv_reader.go
+++ b/pkg/covermerger/bq_csv_reader.go
@@ -100,12 +100,8 @@ func (r *bqCSVReader) initGCSFileReaders(ctx context.Context, bucket, path strin
return fmt.Errorf("err enumerating gcs files: %w", err)
}
for _, obj := range gcsFiles {
- var file *gcs.File
- if file, err = gcsClient.Read(bucket + "/" + obj.Path); err != nil {
- return fmt.Errorf("failed to start reading %s: %w", obj.Path, err)
- }
var readCloser io.ReadCloser
- if readCloser, err = file.Reader(); err != nil {
+ if readCloser, err = gcsClient.FileReader(bucket + "/" + obj.Path); err != nil {
return fmt.Errorf("failed to get %s reader: %w", obj.Path, err)
}
r.closers = append(r.closers, readCloser)
diff --git a/pkg/gcs/gcs.go b/pkg/gcs/gcs.go
index dcdd45f5a..e8500ec2b 100644
--- a/pkg/gcs/gcs.go
+++ b/pkg/gcs/gcs.go
@@ -24,7 +24,7 @@ import (
type Client interface {
Close() error
- Read(path string) (*File, error)
+ FileReader(path string) (io.ReadCloser, error)
FileWriter(path string, contentType string, contentEncoding string) (io.WriteCloser, error)
DeleteFile(path string) error
FileExists(path string) (bool, error)
@@ -71,17 +71,6 @@ type client struct {
ctx context.Context
}
-type File struct {
- Updated time.Time
-
- ctx context.Context
- handle *storage.ObjectHandle
-}
-
-func (file *File) Reader() (io.ReadCloser, error) {
- return file.handle.NewReader(file.ctx)
-}
-
func NewClient(ctx context.Context) (Client, error) {
storageClient, err := storage.NewClient(ctx)
if err != nil {
@@ -98,7 +87,7 @@ func (c *client) Close() error {
return c.client.Close()
}
-func (c *client) Read(gcsFile string) (*File, error) {
+func (c *client) FileReader(gcsFile string) (io.ReadCloser, error) {
bucket, filename, err := split(gcsFile)
if err != nil {
return nil, err
@@ -116,12 +105,7 @@ func (c *client) Read(gcsFile string) (*File, error) {
GenerationMatch: attrs.Generation,
MetagenerationMatch: attrs.Metageneration,
})
- file := &File{
- Updated: attrs.Updated,
- ctx: c.ctx,
- handle: handle,
- }
- return file, nil
+ return handle.NewReader(c.ctx)
}
func (c *client) FileWriter(gcsFile, contentType, contentEncoding string) (io.WriteCloser, error) {
diff --git a/pkg/gcs/mocks/Client.go b/pkg/gcs/mocks/Client.go
index fff5dddd7..d422b9c41 100644
--- a/pkg/gcs/mocks/Client.go
+++ b/pkg/gcs/mocks/Client.go
@@ -170,6 +170,64 @@ func (_c *Client_FileExists_Call) RunAndReturn(run func(string) (bool, error)) *
return _c
}
+// FileReader provides a mock function with given fields: path
+func (_m *Client) FileReader(path string) (io.ReadCloser, error) {
+ ret := _m.Called(path)
+
+ if len(ret) == 0 {
+ panic("no return value specified for FileReader")
+ }
+
+ var r0 io.ReadCloser
+ var r1 error
+ if rf, ok := ret.Get(0).(func(string) (io.ReadCloser, error)); ok {
+ return rf(path)
+ }
+ if rf, ok := ret.Get(0).(func(string) io.ReadCloser); ok {
+ r0 = rf(path)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(io.ReadCloser)
+ }
+ }
+
+ if rf, ok := ret.Get(1).(func(string) error); ok {
+ r1 = rf(path)
+ } else {
+ r1 = ret.Error(1)
+ }
+
+ return r0, r1
+}
+
+// Client_FileReader_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FileReader'
+type Client_FileReader_Call struct {
+ *mock.Call
+}
+
+// FileReader is a helper method to define mock.On call
+// - path string
+func (_e *Client_Expecter) FileReader(path interface{}) *Client_FileReader_Call {
+ return &Client_FileReader_Call{Call: _e.mock.On("FileReader", path)}
+}
+
+func (_c *Client_FileReader_Call) Run(run func(path string)) *Client_FileReader_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ run(args[0].(string))
+ })
+ return _c
+}
+
+func (_c *Client_FileReader_Call) Return(_a0 io.ReadCloser, _a1 error) *Client_FileReader_Call {
+ _c.Call.Return(_a0, _a1)
+ return _c
+}
+
+func (_c *Client_FileReader_Call) RunAndReturn(run func(string) (io.ReadCloser, error)) *Client_FileReader_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
// FileWriter provides a mock function with given fields: path, contentType, contentEncoding
func (_m *Client) FileWriter(path string, contentType string, contentEncoding string) (io.WriteCloser, error) {
ret := _m.Called(path, contentType, contentEncoding)
@@ -334,64 +392,6 @@ func (_c *Client_Publish_Call) RunAndReturn(run func(string) error) *Client_Publ
return _c
}
-// Read provides a mock function with given fields: path
-func (_m *Client) Read(path string) (*gcs.File, error) {
- ret := _m.Called(path)
-
- if len(ret) == 0 {
- panic("no return value specified for Read")
- }
-
- var r0 *gcs.File
- var r1 error
- if rf, ok := ret.Get(0).(func(string) (*gcs.File, error)); ok {
- return rf(path)
- }
- if rf, ok := ret.Get(0).(func(string) *gcs.File); ok {
- r0 = rf(path)
- } else {
- if ret.Get(0) != nil {
- r0 = ret.Get(0).(*gcs.File)
- }
- }
-
- if rf, ok := ret.Get(1).(func(string) error); ok {
- r1 = rf(path)
- } else {
- r1 = ret.Error(1)
- }
-
- return r0, r1
-}
-
-// Client_Read_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Read'
-type Client_Read_Call struct {
- *mock.Call
-}
-
-// Read is a helper method to define mock.On call
-// - path string
-func (_e *Client_Expecter) Read(path interface{}) *Client_Read_Call {
- return &Client_Read_Call{Call: _e.mock.On("Read", path)}
-}
-
-func (_c *Client_Read_Call) Run(run func(path string)) *Client_Read_Call {
- _c.Call.Run(func(args mock.Arguments) {
- run(args[0].(string))
- })
- return _c
-}
-
-func (_c *Client_Read_Call) Return(_a0 *gcs.File, _a1 error) *Client_Read_Call {
- _c.Call.Return(_a0, _a1)
- return _c
-}
-
-func (_c *Client_Read_Call) RunAndReturn(run func(string) (*gcs.File, error)) *Client_Read_Call {
- _c.Call.Return(run)
- return _c
-}
-
// NewClient creates a new instance of Client. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewClient(t interface {