From ca952913d25e4b68dab9f47ae84c128b54779ded Mon Sep 17 00:00:00 2001 From: nicufk Date: Wed, 4 Oct 2023 19:26:20 +0300 Subject: [PATCH 1/4] feat: add output stream functions and mocks --- pkg/repository/result/interface.go | 6 + pkg/repository/result/minio_output.go | 15 ++ .../result/mock_output_repository.go | 207 ++++++++++++++++++ pkg/repository/result/mongo_output.go | 14 ++ 4 files changed, 242 insertions(+) create mode 100644 pkg/repository/result/mock_output_repository.go diff --git a/pkg/repository/result/interface.go b/pkg/repository/result/interface.go index 2ade57471f0..36d7faa62db 100644 --- a/pkg/repository/result/interface.go +++ b/pkg/repository/result/interface.go @@ -2,6 +2,7 @@ package result import ( "context" + "io" "time" "github.com/kubeshop/testkube/pkg/api/v1/testkube" @@ -77,6 +78,7 @@ type Sequences interface { GetNextExecutionNumber(ctx context.Context, testName string) (number int32, err error) } +//go:generate mockgen -destination=./mock_output_repository.go -package=result "github.com/kubeshop/testkube/pkg/repository/result" OutputRepository type OutputRepository interface { // GetOutput gets execution output by id or name GetOutput(ctx context.Context, id, testName, testSuiteName string) (output string, err error) @@ -98,4 +100,8 @@ type OutputRepository interface { DeleteAllOutput(ctx context.Context) error // DeleteOutputForAllTestSuite deletes all execution output for test suite DeleteOutputForAllTestSuite(ctx context.Context) error + // StreamOutput streams execution output by id or name + StreamOutput(ctx context.Context, executionID, testName, testSuiteName string) (reader io.Reader, err error) + // GetOutputSize gets execution output metadata by id or name + GetOutputSize(ctx context.Context, executionID, testName, testSuiteName string) (size int, err error) } diff --git a/pkg/repository/result/minio_output.go b/pkg/repository/result/minio_output.go index a685eb23925..411d1850204 100644 --- a/pkg/repository/result/minio_output.go +++ b/pkg/repository/result/minio_output.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "io" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" @@ -15,6 +16,8 @@ import ( "github.com/kubeshop/testkube/pkg/storage/minio" ) +var _ OutputRepository = (*MinioRepository)(nil) + type MinioRepository struct { storage storage.Client executionCollection *mongo.Collection @@ -175,3 +178,15 @@ func (m *MinioRepository) DeleteAllOutput(ctx context.Context) error { } return m.storage.CreateBucket(ctx, m.bucket) } + +func (m *MinioRepository) StreamOutput(ctx context.Context, executionID, testName, testSuiteName string) (reader io.Reader, err error) { + file, err := m.storage.DownloadFileFromBucket(ctx, m.bucket, "", executionID) + if err != nil { + return nil, err + } + return file, nil +} + +func (m *MinioRepository) GetOutputSize(ctx context.Context, executionID, testName, testSuiteName string) (size int, err error) { + return 0, fmt.Errorf("not implemented") +} diff --git a/pkg/repository/result/mock_output_repository.go b/pkg/repository/result/mock_output_repository.go new file mode 100644 index 00000000000..dff3a650011 --- /dev/null +++ b/pkg/repository/result/mock_output_repository.go @@ -0,0 +1,207 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/kubeshop/testkube/pkg/repository/result (interfaces: OutputRepository) + +// Package result is a generated GoMock package. +package result + +import ( + context "context" + io "io" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" +) + +// MockOutputRepository is a mock of OutputRepository interface. +type MockOutputRepository struct { + ctrl *gomock.Controller + recorder *MockOutputRepositoryMockRecorder +} + +// MockOutputRepositoryMockRecorder is the mock recorder for MockOutputRepository. +type MockOutputRepositoryMockRecorder struct { + mock *MockOutputRepository +} + +// NewMockOutputRepository creates a new mock instance. +func NewMockOutputRepository(ctrl *gomock.Controller) *MockOutputRepository { + mock := &MockOutputRepository{ctrl: ctrl} + mock.recorder = &MockOutputRepositoryMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockOutputRepository) EXPECT() *MockOutputRepositoryMockRecorder { + return m.recorder +} + +// DeleteAllOutput mocks base method. +func (m *MockOutputRepository) DeleteAllOutput(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteAllOutput", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteAllOutput indicates an expected call of DeleteAllOutput. +func (mr *MockOutputRepositoryMockRecorder) DeleteAllOutput(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteAllOutput", reflect.TypeOf((*MockOutputRepository)(nil).DeleteAllOutput), arg0) +} + +// DeleteOutput mocks base method. +func (m *MockOutputRepository) DeleteOutput(arg0 context.Context, arg1, arg2, arg3 string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteOutput", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteOutput indicates an expected call of DeleteOutput. +func (mr *MockOutputRepositoryMockRecorder) DeleteOutput(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOutput", reflect.TypeOf((*MockOutputRepository)(nil).DeleteOutput), arg0, arg1, arg2, arg3) +} + +// DeleteOutputByTest mocks base method. +func (m *MockOutputRepository) DeleteOutputByTest(arg0 context.Context, arg1 string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteOutputByTest", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteOutputByTest indicates an expected call of DeleteOutputByTest. +func (mr *MockOutputRepositoryMockRecorder) DeleteOutputByTest(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOutputByTest", reflect.TypeOf((*MockOutputRepository)(nil).DeleteOutputByTest), arg0, arg1) +} + +// DeleteOutputByTestSuite mocks base method. +func (m *MockOutputRepository) DeleteOutputByTestSuite(arg0 context.Context, arg1 string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteOutputByTestSuite", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteOutputByTestSuite indicates an expected call of DeleteOutputByTestSuite. +func (mr *MockOutputRepositoryMockRecorder) DeleteOutputByTestSuite(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOutputByTestSuite", reflect.TypeOf((*MockOutputRepository)(nil).DeleteOutputByTestSuite), arg0, arg1) +} + +// DeleteOutputForAllTestSuite mocks base method. +func (m *MockOutputRepository) DeleteOutputForAllTestSuite(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteOutputForAllTestSuite", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteOutputForAllTestSuite indicates an expected call of DeleteOutputForAllTestSuite. +func (mr *MockOutputRepositoryMockRecorder) DeleteOutputForAllTestSuite(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOutputForAllTestSuite", reflect.TypeOf((*MockOutputRepository)(nil).DeleteOutputForAllTestSuite), arg0) +} + +// DeleteOutputForTestSuites mocks base method. +func (m *MockOutputRepository) DeleteOutputForTestSuites(arg0 context.Context, arg1 []string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteOutputForTestSuites", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteOutputForTestSuites indicates an expected call of DeleteOutputForTestSuites. +func (mr *MockOutputRepositoryMockRecorder) DeleteOutputForTestSuites(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOutputForTestSuites", reflect.TypeOf((*MockOutputRepository)(nil).DeleteOutputForTestSuites), arg0, arg1) +} + +// DeleteOutputForTests mocks base method. +func (m *MockOutputRepository) DeleteOutputForTests(arg0 context.Context, arg1 []string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteOutputForTests", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteOutputForTests indicates an expected call of DeleteOutputForTests. +func (mr *MockOutputRepositoryMockRecorder) DeleteOutputForTests(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOutputForTests", reflect.TypeOf((*MockOutputRepository)(nil).DeleteOutputForTests), arg0, arg1) +} + +// GetOutput mocks base method. +func (m *MockOutputRepository) GetOutput(arg0 context.Context, arg1, arg2, arg3 string) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetOutput", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetOutput indicates an expected call of GetOutput. +func (mr *MockOutputRepositoryMockRecorder) GetOutput(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOutput", reflect.TypeOf((*MockOutputRepository)(nil).GetOutput), arg0, arg1, arg2, arg3) +} + +// GetOutputSize mocks base method. +func (m *MockOutputRepository) GetOutputSize(arg0 context.Context, arg1, arg2, arg3 string) (int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetOutputSize", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetOutputSize indicates an expected call of GetOutputSize. +func (mr *MockOutputRepositoryMockRecorder) GetOutputSize(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOutputSize", reflect.TypeOf((*MockOutputRepository)(nil).GetOutputSize), arg0, arg1, arg2, arg3) +} + +// InsertOutput mocks base method. +func (m *MockOutputRepository) InsertOutput(arg0 context.Context, arg1, arg2, arg3, arg4 string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InsertOutput", arg0, arg1, arg2, arg3, arg4) + ret0, _ := ret[0].(error) + return ret0 +} + +// InsertOutput indicates an expected call of InsertOutput. +func (mr *MockOutputRepositoryMockRecorder) InsertOutput(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InsertOutput", reflect.TypeOf((*MockOutputRepository)(nil).InsertOutput), arg0, arg1, arg2, arg3, arg4) +} + +// StreamOutput mocks base method. +func (m *MockOutputRepository) StreamOutput(arg0 context.Context, arg1, arg2, arg3 string) (io.Reader, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StreamOutput", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(io.Reader) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StreamOutput indicates an expected call of StreamOutput. +func (mr *MockOutputRepositoryMockRecorder) StreamOutput(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StreamOutput", reflect.TypeOf((*MockOutputRepository)(nil).StreamOutput), arg0, arg1, arg2, arg3) +} + +// UpdateOutput mocks base method. +func (m *MockOutputRepository) UpdateOutput(arg0 context.Context, arg1, arg2, arg3, arg4 string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateOutput", arg0, arg1, arg2, arg3, arg4) + ret0, _ := ret[0].(error) + return ret0 +} + +// UpdateOutput indicates an expected call of UpdateOutput. +func (mr *MockOutputRepositoryMockRecorder) UpdateOutput(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateOutput", reflect.TypeOf((*MockOutputRepository)(nil).UpdateOutput), arg0, arg1, arg2, arg3, arg4) +} diff --git a/pkg/repository/result/mongo_output.go b/pkg/repository/result/mongo_output.go index 74dc6a0d179..27fc23b622b 100644 --- a/pkg/repository/result/mongo_output.go +++ b/pkg/repository/result/mongo_output.go @@ -2,6 +2,8 @@ package result import ( "context" + "io" + "strings" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" @@ -93,3 +95,15 @@ func (r *MongoOutputRepository) DeleteAllOutput(ctx context.Context) error { _, err := r.Coll.DeleteMany(ctx, bson.M{}) return err } + +func (r *MongoOutputRepository) StreamOutput(ctx context.Context, executionID, testName, testSuiteName string) (reader io.Reader, err error) { + var eOutput ExecutionOutput + err = r.Coll.FindOne(ctx, bson.M{"$or": bson.A{bson.M{"id": executionID}, bson.M{"name": executionID}}}).Decode(&eOutput) + return strings.NewReader(eOutput.Output), err +} + +func (r *MongoOutputRepository) GetOutputSize(ctx context.Context, executionID, testName, testSuiteName string) (size int, err error) { + var eOutput ExecutionOutput + err = r.Coll.FindOne(ctx, bson.M{"$or": bson.A{bson.M{"id": executionID}, bson.M{"name": executionID}}}).Decode(&eOutput) + return len(eOutput.Output), err +} From 86bff94e37cbec37a530bc513a4a649b3addb06e Mon Sep 17 00:00:00 2001 From: nicufk Date: Fri, 13 Oct 2023 13:38:18 +0300 Subject: [PATCH 2/4] fix: implement size reading and improve interfaces --- pkg/repository/result/minio_output.go | 18 +- pkg/repository/result/minio_output_test.go | 23 ++ pkg/storage/minio/minio.go | 2 +- pkg/storage/storage.go | 4 +- pkg/storage/storage_mock.go | 269 +++++++++++++++++++++ 5 files changed, 313 insertions(+), 3 deletions(-) create mode 100644 pkg/repository/result/minio_output_test.go create mode 100644 pkg/storage/storage_mock.go diff --git a/pkg/repository/result/minio_output.go b/pkg/repository/result/minio_output.go index 411d1850204..398cb783bc4 100644 --- a/pkg/repository/result/minio_output.go +++ b/pkg/repository/result/minio_output.go @@ -188,5 +188,21 @@ func (m *MinioRepository) StreamOutput(ctx context.Context, executionID, testNam } func (m *MinioRepository) GetOutputSize(ctx context.Context, executionID, testName, testSuiteName string) (size int, err error) { - return 0, fmt.Errorf("not implemented") + //TODO: improve with minio client + stream, err := m.StreamOutput(ctx, executionID, testName, testSuiteName) + if err != nil { + return 0, err + } + buf := make([]byte, 1024) + for { + n, err := stream.Read(buf) + if err != nil { + if err == io.EOF { + break + } + return 0, err + } + size += n + } + return size, nil } diff --git a/pkg/repository/result/minio_output_test.go b/pkg/repository/result/minio_output_test.go new file mode 100644 index 00000000000..0a410380ddb --- /dev/null +++ b/pkg/repository/result/minio_output_test.go @@ -0,0 +1,23 @@ +package result + +import ( + "strings" + "testing" + + gomock "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" + + "github.com/kubeshop/testkube/pkg/storage" +) + +func TestGetOutputSize(t *testing.T) { + mockCtrl := gomock.NewController(t) + storageMock := storage.NewMockClient(mockCtrl) + outputClient := NewMinioOutputRepository(storageMock, nil, "test-bucket") + streamContent := "test line" + storageMock.EXPECT().DownloadFileFromBucket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(strings.NewReader(streamContent), nil) + size, err := outputClient.GetOutputSize(nil, "test-id", "test-name", "test-suite-name") + assert.Nil(t, err) + assert.Equal(t, len(streamContent), size) + +} diff --git a/pkg/storage/minio/minio.go b/pkg/storage/minio/minio.go index 05646e62eb0..a56e1706761 100644 --- a/pkg/storage/minio/minio.go +++ b/pkg/storage/minio/minio.go @@ -440,7 +440,7 @@ func (c *Client) DownloadArchive(ctx context.Context, bucketFolder string, masks } // DownloadFileFromBucket downloads file from given bucket -func (c *Client) DownloadFileFromBucket(ctx context.Context, bucket, bucketFolder, file string) (*minio.Object, error) { +func (c *Client) DownloadFileFromBucket(ctx context.Context, bucket, bucketFolder, file string) (io.Reader, error) { c.Log.Debugw("Downloading file", "bucket", bucket, "bucketFolder", bucketFolder, "file", file) return c.downloadFile(ctx, bucket, bucketFolder, file) } diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index bccbc98f8dd..d96c9a6e3eb 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -16,6 +16,8 @@ type Client interface { } // ClientImplicitBucket is storage client abstraction where bucket name is provided from config +// +//go:generate mockgen -destination=./storage_mock.go -package=storage "github.com/kubeshop/testkube/pkg/storage" ClientImplicitBucket type ClientImplicitBucket interface { IsConnectionPossible(ctx context.Context) (bool, error) ListFiles(ctx context.Context, bucketFolder string) ([]testkube.Artifact, error) @@ -32,7 +34,7 @@ type ClientBucket interface { CreateBucket(ctx context.Context, bucket string) error DeleteBucket(ctx context.Context, bucket string, force bool) error ListBuckets(ctx context.Context) ([]string, error) - DownloadFileFromBucket(ctx context.Context, bucket, bucketFolder, file string) (*minio.Object, error) + DownloadFileFromBucket(ctx context.Context, bucket, bucketFolder, file string) (io.Reader, error) DownloadArchiveFromBucket(ctx context.Context, bucket, bucketFolder string, masks []string) (io.Reader, error) UploadFileToBucket(ctx context.Context, bucket, bucketFolder, filePath string, reader io.Reader, objectSize int64) error GetValidBucketName(parentType string, parentName string) string diff --git a/pkg/storage/storage_mock.go b/pkg/storage/storage_mock.go new file mode 100644 index 00000000000..addaa2b5d7a --- /dev/null +++ b/pkg/storage/storage_mock.go @@ -0,0 +1,269 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/kubeshop/testkube/pkg/storage (interfaces: Client) + +// Package storage is a generated GoMock package. +package storage + +import ( + context "context" + io "io" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + testkube "github.com/kubeshop/testkube/pkg/api/v1/testkube" + minio "github.com/minio/minio-go/v7" +) + +// MockClient is a mock of Client interface. +type MockClient struct { + ctrl *gomock.Controller + recorder *MockClientMockRecorder +} + +// MockClientMockRecorder is the mock recorder for MockClient. +type MockClientMockRecorder struct { + mock *MockClient +} + +// NewMockClient creates a new mock instance. +func NewMockClient(ctrl *gomock.Controller) *MockClient { + mock := &MockClient{ctrl: ctrl} + mock.recorder = &MockClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockClient) EXPECT() *MockClientMockRecorder { + return m.recorder +} + +// CreateBucket mocks base method. +func (m *MockClient) CreateBucket(arg0 context.Context, arg1 string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateBucket", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// CreateBucket indicates an expected call of CreateBucket. +func (mr *MockClientMockRecorder) CreateBucket(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateBucket", reflect.TypeOf((*MockClient)(nil).CreateBucket), arg0, arg1) +} + +// DeleteBucket mocks base method. +func (m *MockClient) DeleteBucket(arg0 context.Context, arg1 string, arg2 bool) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteBucket", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteBucket indicates an expected call of DeleteBucket. +func (mr *MockClientMockRecorder) DeleteBucket(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteBucket", reflect.TypeOf((*MockClient)(nil).DeleteBucket), arg0, arg1, arg2) +} + +// DeleteFile mocks base method. +func (m *MockClient) DeleteFile(arg0 context.Context, arg1, arg2 string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteFile", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteFile indicates an expected call of DeleteFile. +func (mr *MockClientMockRecorder) DeleteFile(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteFile", reflect.TypeOf((*MockClient)(nil).DeleteFile), arg0, arg1, arg2) +} + +// DeleteFileFromBucket mocks base method. +func (m *MockClient) DeleteFileFromBucket(arg0 context.Context, arg1, arg2, arg3 string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteFileFromBucket", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteFileFromBucket indicates an expected call of DeleteFileFromBucket. +func (mr *MockClientMockRecorder) DeleteFileFromBucket(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteFileFromBucket", reflect.TypeOf((*MockClient)(nil).DeleteFileFromBucket), arg0, arg1, arg2, arg3) +} + +// DownloadArchive mocks base method. +func (m *MockClient) DownloadArchive(arg0 context.Context, arg1 string, arg2 []string) (io.Reader, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DownloadArchive", arg0, arg1, arg2) + ret0, _ := ret[0].(io.Reader) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DownloadArchive indicates an expected call of DownloadArchive. +func (mr *MockClientMockRecorder) DownloadArchive(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DownloadArchive", reflect.TypeOf((*MockClient)(nil).DownloadArchive), arg0, arg1, arg2) +} + +// DownloadArchiveFromBucket mocks base method. +func (m *MockClient) DownloadArchiveFromBucket(arg0 context.Context, arg1, arg2 string, arg3 []string) (io.Reader, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DownloadArchiveFromBucket", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(io.Reader) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DownloadArchiveFromBucket indicates an expected call of DownloadArchiveFromBucket. +func (mr *MockClientMockRecorder) DownloadArchiveFromBucket(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DownloadArchiveFromBucket", reflect.TypeOf((*MockClient)(nil).DownloadArchiveFromBucket), arg0, arg1, arg2, arg3) +} + +// DownloadFile mocks base method. +func (m *MockClient) DownloadFile(arg0 context.Context, arg1, arg2 string) (*minio.Object, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DownloadFile", arg0, arg1, arg2) + ret0, _ := ret[0].(*minio.Object) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DownloadFile indicates an expected call of DownloadFile. +func (mr *MockClientMockRecorder) DownloadFile(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DownloadFile", reflect.TypeOf((*MockClient)(nil).DownloadFile), arg0, arg1, arg2) +} + +// DownloadFileFromBucket mocks base method. +func (m *MockClient) DownloadFileFromBucket(arg0 context.Context, arg1, arg2, arg3 string) (io.Reader, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DownloadFileFromBucket", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(io.Reader) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DownloadFileFromBucket indicates an expected call of DownloadFileFromBucket. +func (mr *MockClientMockRecorder) DownloadFileFromBucket(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DownloadFileFromBucket", reflect.TypeOf((*MockClient)(nil).DownloadFileFromBucket), arg0, arg1, arg2, arg3) +} + +// GetValidBucketName mocks base method. +func (m *MockClient) GetValidBucketName(arg0, arg1 string) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetValidBucketName", arg0, arg1) + ret0, _ := ret[0].(string) + return ret0 +} + +// GetValidBucketName indicates an expected call of GetValidBucketName. +func (mr *MockClientMockRecorder) GetValidBucketName(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidBucketName", reflect.TypeOf((*MockClient)(nil).GetValidBucketName), arg0, arg1) +} + +// IsConnectionPossible mocks base method. +func (m *MockClient) IsConnectionPossible(arg0 context.Context) (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsConnectionPossible", arg0) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// IsConnectionPossible indicates an expected call of IsConnectionPossible. +func (mr *MockClientMockRecorder) IsConnectionPossible(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsConnectionPossible", reflect.TypeOf((*MockClient)(nil).IsConnectionPossible), arg0) +} + +// ListBuckets mocks base method. +func (m *MockClient) ListBuckets(arg0 context.Context) ([]string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListBuckets", arg0) + ret0, _ := ret[0].([]string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListBuckets indicates an expected call of ListBuckets. +func (mr *MockClientMockRecorder) ListBuckets(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListBuckets", reflect.TypeOf((*MockClient)(nil).ListBuckets), arg0) +} + +// ListFiles mocks base method. +func (m *MockClient) ListFiles(arg0 context.Context, arg1 string) ([]testkube.Artifact, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListFiles", arg0, arg1) + ret0, _ := ret[0].([]testkube.Artifact) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListFiles indicates an expected call of ListFiles. +func (mr *MockClientMockRecorder) ListFiles(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListFiles", reflect.TypeOf((*MockClient)(nil).ListFiles), arg0, arg1) +} + +// PlaceFiles mocks base method. +func (m *MockClient) PlaceFiles(arg0 context.Context, arg1 []string, arg2 string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PlaceFiles", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// PlaceFiles indicates an expected call of PlaceFiles. +func (mr *MockClientMockRecorder) PlaceFiles(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PlaceFiles", reflect.TypeOf((*MockClient)(nil).PlaceFiles), arg0, arg1, arg2) +} + +// SaveFile mocks base method. +func (m *MockClient) SaveFile(arg0 context.Context, arg1, arg2 string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SaveFile", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// SaveFile indicates an expected call of SaveFile. +func (mr *MockClientMockRecorder) SaveFile(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SaveFile", reflect.TypeOf((*MockClient)(nil).SaveFile), arg0, arg1, arg2) +} + +// UploadFile mocks base method. +func (m *MockClient) UploadFile(arg0 context.Context, arg1, arg2 string, arg3 io.Reader, arg4 int64) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UploadFile", arg0, arg1, arg2, arg3, arg4) + ret0, _ := ret[0].(error) + return ret0 +} + +// UploadFile indicates an expected call of UploadFile. +func (mr *MockClientMockRecorder) UploadFile(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UploadFile", reflect.TypeOf((*MockClient)(nil).UploadFile), arg0, arg1, arg2, arg3, arg4) +} + +// UploadFileToBucket mocks base method. +func (m *MockClient) UploadFileToBucket(arg0 context.Context, arg1, arg2, arg3 string, arg4 io.Reader, arg5 int64) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UploadFileToBucket", arg0, arg1, arg2, arg3, arg4, arg5) + ret0, _ := ret[0].(error) + return ret0 +} + +// UploadFileToBucket indicates an expected call of UploadFileToBucket. +func (mr *MockClientMockRecorder) UploadFileToBucket(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UploadFileToBucket", reflect.TypeOf((*MockClient)(nil).UploadFileToBucket), arg0, arg1, arg2, arg3, arg4, arg5) +} From 01066bd795cac06bc3d70f7669d4f97a4d54764b Mon Sep 17 00:00:00 2001 From: nicufk Date: Fri, 13 Oct 2023 13:46:57 +0300 Subject: [PATCH 3/4] fix: literal to const --- pkg/repository/result/minio_output.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/repository/result/minio_output.go b/pkg/repository/result/minio_output.go index 398cb783bc4..3ae1ff6a86f 100644 --- a/pkg/repository/result/minio_output.go +++ b/pkg/repository/result/minio_output.go @@ -193,7 +193,8 @@ func (m *MinioRepository) GetOutputSize(ctx context.Context, executionID, testNa if err != nil { return 0, err } - buf := make([]byte, 1024) + const bufferSize = 1024 + buf := make([]byte, bufferSize) for { n, err := stream.Read(buf) if err != nil { From 2dbf0e6cce93fe7489db216af5773f9fb0e9562a Mon Sep 17 00:00:00 2001 From: nicufk Date: Fri, 13 Oct 2023 13:50:34 +0300 Subject: [PATCH 4/4] fix: nil context --- pkg/repository/result/minio_output_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/repository/result/minio_output_test.go b/pkg/repository/result/minio_output_test.go index 0a410380ddb..4191cd3c2c6 100644 --- a/pkg/repository/result/minio_output_test.go +++ b/pkg/repository/result/minio_output_test.go @@ -1,6 +1,7 @@ package result import ( + "context" "strings" "testing" @@ -16,7 +17,7 @@ func TestGetOutputSize(t *testing.T) { outputClient := NewMinioOutputRepository(storageMock, nil, "test-bucket") streamContent := "test line" storageMock.EXPECT().DownloadFileFromBucket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(strings.NewReader(streamContent), nil) - size, err := outputClient.GetOutputSize(nil, "test-id", "test-name", "test-suite-name") + size, err := outputClient.GetOutputSize(context.Background(), "test-id", "test-name", "test-suite-name") assert.Nil(t, err) assert.Equal(t, len(streamContent), size)