From 3be71cf3b73f6b9b4c1562074e130a900e9cb619 Mon Sep 17 00:00:00 2001 From: Saurabh Prakash Date: Fri, 15 Jul 2022 11:52:34 +0530 Subject: [PATCH] Refactored SAS URL API (#222) * Refactored SAS URL API * fixes found while testing * Addressed PR comments --- .github/workflows/premerge.yml | 2 +- Makefile | 9 ++ README.md | 2 +- go.mod | 5 +- go.sum | 1 - {testutils/mocks => mocks}/AzureClient.go | 31 ++++- mocks/BlockTestService.go | 43 ++++++ mocks/Builder.go | 51 +++++++ {testutils/mocks => mocks}/CacheStore.go | 13 +- mocks/CoverageService.go | 44 ++++++ mocks/DiffManager.go | 53 +++++++ mocks/DockerRunner.go | 131 ++++++++++++++++++ mocks/Driver.go | 58 ++++++++ .../mocks => mocks}/ExecutionManager.go | 13 +- mocks/GitManager.go | 44 ++++++ mocks/ListSubModuleService.go | 43 ++++++ mocks/LogWriterStrategy.go | 47 +++++++ mocks/Logger.go | 92 ++++++++++++ mocks/PayloadManager.go | 67 +++++++++ mocks/Requests.go | 59 ++++++++ {testutils/mocks => mocks}/SecretParser.go | 17 ++- mocks/SecretsManager.go | 109 +++++++++++++++ mocks/SynapseManager.go | 36 +++++ .../mocks => mocks}/TASConfigManager.go | 13 +- mocks/Task.go | 44 ++++++ .../mocks => mocks}/TestDiscoveryService.go | 19 +-- .../mocks => mocks}/TestExecutionService.go | 19 +-- mocks/TestStats.go | 39 ++++++ {testutils/mocks => mocks}/ZstdCompressor.go | 17 ++- pkg/azure/client.go | 22 ++- pkg/blocktestservice/setup.go | 13 +- pkg/cachemanager/cachemanager.go | 11 +- pkg/command/run_test.go | 2 +- pkg/command/script_test.go | 2 +- pkg/core/interfaces.go | 4 +- pkg/core/models.go | 33 ++--- pkg/core/runner.go | 49 ++++--- pkg/driver/driver_v1.go | 12 +- pkg/driver/driver_v2.go | 18 +-- pkg/gitmanager/setup_test.go | 2 +- pkg/global/nucleusconstants.go | 1 - pkg/listsubmoduleservice/setup.go | 9 +- pkg/logwriter/setup.go | 10 +- pkg/logwriter/setup_test.go | 20 +-- pkg/payloadmanager/setup.go | 22 +-- pkg/payloadmanager/setup_test.go | 12 +- pkg/requestutils/request.go | 18 ++- pkg/runner/docker/config.go | 17 +-- pkg/runner/docker/docker.go | 27 ++-- pkg/service/coverage/coverage_test.go | 2 +- pkg/tasconfigmanager/setup.go | 5 +- pkg/task/task.go | 9 +- pkg/testdiscoveryservice/testdiscovery.go | 9 +- .../testdiscovery_test.go | 2 +- pkg/testexecutionservice/testexecution.go | 25 +--- .../testexecution_test.go | 2 +- pkg/utils/utils.go | 12 +- pkg/zstd/zstd_test.go | 2 +- testutils/mocks/Reader.go | 31 ----- 59 files changed, 1223 insertions(+), 301 deletions(-) rename {testutils/mocks => mocks}/AzureClient.go (76%) create mode 100644 mocks/BlockTestService.go create mode 100644 mocks/Builder.go rename {testutils/mocks => mocks}/CacheStore.go (86%) create mode 100644 mocks/CoverageService.go create mode 100644 mocks/DiffManager.go create mode 100644 mocks/DockerRunner.go create mode 100644 mocks/Driver.go rename {testutils/mocks => mocks}/ExecutionManager.go (87%) create mode 100644 mocks/GitManager.go create mode 100644 mocks/ListSubModuleService.go create mode 100644 mocks/LogWriterStrategy.go create mode 100644 mocks/Logger.go create mode 100644 mocks/PayloadManager.go create mode 100644 mocks/Requests.go rename {testutils/mocks => mocks}/SecretParser.go (80%) create mode 100644 mocks/SecretsManager.go create mode 100644 mocks/SynapseManager.go rename {testutils/mocks => mocks}/TASConfigManager.go (82%) create mode 100644 mocks/Task.go rename {testutils/mocks => mocks}/TestDiscoveryService.go (67%) rename {testutils/mocks => mocks}/TestExecutionService.go (71%) create mode 100644 mocks/TestStats.go rename {testutils/mocks => mocks}/ZstdCompressor.go (74%) delete mode 100644 testutils/mocks/Reader.go diff --git a/.github/workflows/premerge.yml b/.github/workflows/premerge.yml index f5e48c0b..5afc8884 100644 --- a/.github/workflows/premerge.yml +++ b/.github/workflows/premerge.yml @@ -17,7 +17,7 @@ jobs: - name: Install Go uses: actions/setup-go@v2 with: - go-version: 1.16 + go-version: 1.17 - name: Checkout code uses: actions/checkout@v2 diff --git a/Makefile b/Makefile index 90a9f9d4..9ff9f70e 100644 --- a/Makefile +++ b/Makefile @@ -24,3 +24,12 @@ build-synapse-image: ## Builds synapse docker image build-synapse-bin: ## Builds synapse binary bash build/synapse/build.sh + +install-mockery-mac: + brew install mockery + +install-mockery-linux: + apt update && apt install -y mockery + +gen-mock-files: + mockery --dir=./pkg --all diff --git a/README.md b/README.md index 1e9a33a4..38729869 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ curl https://raw.githubusercontent.com/LambdaTest/test-at-scale/main/.sample.syn docker info --format "CPU: {{.NCPU}}, RAM: {{.MemTotal}}" ``` - Execute the above command to ensure that resources usable by Docker are atleast `CPU: 2, RAM: 4294967296`. - > **NOTE:** In order to run test-at-scale you require a minimum configuration of 2 CPU cores and 4 GBs of RAM. + > **NOTE:** In order to run test-at-scale you require a minimum configuration of 2 CPU cores and 4 GiBs of RAM. - The `.synapse.json` configuration file made in [Step 2](#step-2---creating-a-configuration-file-for-self-hosted-setup) will be required before executing the next command. - Download and run the docker compose file using the following command. diff --git a/go.mod b/go.mod index bfdc388f..70f8ce46 100644 --- a/go.mod +++ b/go.mod @@ -3,16 +3,17 @@ module github.com/LambdaTest/test-at-scale go 1.17 require ( + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0 github.com/bmatcuk/doublestar/v4 v4.0.2 github.com/cenkalti/backoff/v4 v4.1.3 github.com/denisbrodbeck/machineid v1.0.1 github.com/docker/docker v20.10.12+incompatible + github.com/docker/go-units v0.4.0 github.com/gin-gonic/gin v1.7.7 github.com/go-playground/locales v0.14.0 github.com/go-playground/universal-translator v0.18.0 github.com/go-playground/validator/v10 v10.10.0 - github.com/golang/mock v1.6.0 github.com/google/uuid v1.2.0 github.com/gorilla/websocket v1.4.2 github.com/joho/godotenv v1.4.0 @@ -30,7 +31,6 @@ require ( ) require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 // indirect github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 // indirect github.com/Microsoft/go-winio v0.4.17 // indirect github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect @@ -39,7 +39,6 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/docker/distribution v2.8.0+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect - github.com/docker/go-units v0.4.0 // indirect github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/gin-contrib/sse v0.1.0 // indirect diff --git a/go.sum b/go.sum index ceb1ac34..3342df9b 100644 --- a/go.sum +++ b/go.sum @@ -404,7 +404,6 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= diff --git a/testutils/mocks/AzureClient.go b/mocks/AzureClient.go similarity index 76% rename from testutils/mocks/AzureClient.go rename to mocks/AzureClient.go index 543f8c49..ba07ac62 100644 --- a/testutils/mocks/AzureClient.go +++ b/mocks/AzureClient.go @@ -1,3 +1,5 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + package mocks import ( @@ -123,23 +125,38 @@ func (_m *AzureClient) FindUsingSASUrl(ctx context.Context, sasURL string) (io.R return r0, r1 } -// GetSASURL provides a mock function with given fields: ctx, containerPath, containerType -func (_m *AzureClient) GetSASURL(ctx context.Context, containerPath string, containerType core.ContainerType) (string, error) { - ret := _m.Called(ctx, containerPath, containerType) +// GetSASURL provides a mock function with given fields: ctx, purpose, query +func (_m *AzureClient) GetSASURL(ctx context.Context, purpose core.SASURLPurpose, query map[string]interface{}) (string, error) { + ret := _m.Called(ctx, purpose, query) var r0 string - if rf, ok := ret.Get(0).(func(context.Context, string, core.ContainerType) string); ok { - r0 = rf(ctx, containerPath, containerType) + if rf, ok := ret.Get(0).(func(context.Context, core.SASURLPurpose, map[string]interface{}) string); ok { + r0 = rf(ctx, purpose, query) } else { r0 = ret.Get(0).(string) } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, core.ContainerType) error); ok { - r1 = rf(ctx, containerPath, containerType) + if rf, ok := ret.Get(1).(func(context.Context, core.SASURLPurpose, map[string]interface{}) error); ok { + r1 = rf(ctx, purpose, query) } else { r1 = ret.Error(1) } return r0, r1 } + +type mockConstructorTestingTNewAzureClient interface { + mock.TestingT + Cleanup(func()) +} + +// NewAzureClient creates a new instance of AzureClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewAzureClient(t mockConstructorTestingTNewAzureClient) *AzureClient { + mock := &AzureClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/BlockTestService.go b/mocks/BlockTestService.go new file mode 100644 index 00000000..6492cc9a --- /dev/null +++ b/mocks/BlockTestService.go @@ -0,0 +1,43 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// BlockTestService is an autogenerated mock type for the BlockTestService type +type BlockTestService struct { + mock.Mock +} + +// GetBlockTests provides a mock function with given fields: ctx, blocklistYAML, branch +func (_m *BlockTestService) GetBlockTests(ctx context.Context, blocklistYAML []string, branch string) error { + ret := _m.Called(ctx, blocklistYAML, branch) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []string, string) error); ok { + r0 = rf(ctx, blocklistYAML, branch) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type mockConstructorTestingTNewBlockTestService interface { + mock.TestingT + Cleanup(func()) +} + +// NewBlockTestService creates a new instance of BlockTestService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewBlockTestService(t mockConstructorTestingTNewBlockTestService) *BlockTestService { + mock := &BlockTestService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/Builder.go b/mocks/Builder.go new file mode 100644 index 00000000..a2f8466b --- /dev/null +++ b/mocks/Builder.go @@ -0,0 +1,51 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + core "github.com/LambdaTest/test-at-scale/pkg/core" + mock "github.com/stretchr/testify/mock" +) + +// Builder is an autogenerated mock type for the Builder type +type Builder struct { + mock.Mock +} + +// GetDriver provides a mock function with given fields: version +func (_m *Builder) GetDriver(version int) (core.Driver, error) { + ret := _m.Called(version) + + var r0 core.Driver + if rf, ok := ret.Get(0).(func(int) core.Driver); ok { + r0 = rf(version) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(core.Driver) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(int) error); ok { + r1 = rf(version) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +type mockConstructorTestingTNewBuilder interface { + mock.TestingT + Cleanup(func()) +} + +// NewBuilder creates a new instance of Builder. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewBuilder(t mockConstructorTestingTNewBuilder) *Builder { + mock := &Builder{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/testutils/mocks/CacheStore.go b/mocks/CacheStore.go similarity index 86% rename from testutils/mocks/CacheStore.go rename to mocks/CacheStore.go index 61d676d9..55a2966d 100644 --- a/testutils/mocks/CacheStore.go +++ b/mocks/CacheStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.12.1. DO NOT EDIT. +// Code generated by mockery v2.14.0. DO NOT EDIT. package mocks @@ -6,8 +6,6 @@ import ( context "context" mock "github.com/stretchr/testify/mock" - - testing "testing" ) // CacheStore is an autogenerated mock type for the CacheStore type @@ -78,8 +76,13 @@ func (_m *CacheStore) Upload(ctx context.Context, cacheKey string, itemsToCompre return r0 } -// NewCacheStore creates a new instance of CacheStore. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewCacheStore(t testing.TB) *CacheStore { +type mockConstructorTestingTNewCacheStore interface { + mock.TestingT + Cleanup(func()) +} + +// NewCacheStore creates a new instance of CacheStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewCacheStore(t mockConstructorTestingTNewCacheStore) *CacheStore { mock := &CacheStore{} mock.Mock.Test(t) diff --git a/mocks/CoverageService.go b/mocks/CoverageService.go new file mode 100644 index 00000000..ae3c8fe3 --- /dev/null +++ b/mocks/CoverageService.go @@ -0,0 +1,44 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + core "github.com/LambdaTest/test-at-scale/pkg/core" + mock "github.com/stretchr/testify/mock" +) + +// CoverageService is an autogenerated mock type for the CoverageService type +type CoverageService struct { + mock.Mock +} + +// MergeAndUpload provides a mock function with given fields: ctx, payload +func (_m *CoverageService) MergeAndUpload(ctx context.Context, payload *core.Payload) error { + ret := _m.Called(ctx, payload) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *core.Payload) error); ok { + r0 = rf(ctx, payload) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type mockConstructorTestingTNewCoverageService interface { + mock.TestingT + Cleanup(func()) +} + +// NewCoverageService creates a new instance of CoverageService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewCoverageService(t mockConstructorTestingTNewCoverageService) *CoverageService { + mock := &CoverageService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/DiffManager.go b/mocks/DiffManager.go new file mode 100644 index 00000000..0278238e --- /dev/null +++ b/mocks/DiffManager.go @@ -0,0 +1,53 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + core "github.com/LambdaTest/test-at-scale/pkg/core" + mock "github.com/stretchr/testify/mock" +) + +// DiffManager is an autogenerated mock type for the DiffManager type +type DiffManager struct { + mock.Mock +} + +// GetChangedFiles provides a mock function with given fields: ctx, payload, oauth +func (_m *DiffManager) GetChangedFiles(ctx context.Context, payload *core.Payload, oauth *core.Oauth) (map[string]int, error) { + ret := _m.Called(ctx, payload, oauth) + + var r0 map[string]int + if rf, ok := ret.Get(0).(func(context.Context, *core.Payload, *core.Oauth) map[string]int); ok { + r0 = rf(ctx, payload, oauth) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[string]int) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, *core.Payload, *core.Oauth) error); ok { + r1 = rf(ctx, payload, oauth) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +type mockConstructorTestingTNewDiffManager interface { + mock.TestingT + Cleanup(func()) +} + +// NewDiffManager creates a new instance of DiffManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewDiffManager(t mockConstructorTestingTNewDiffManager) *DiffManager { + mock := &DiffManager{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/DockerRunner.go b/mocks/DockerRunner.go new file mode 100644 index 00000000..d288bf7e --- /dev/null +++ b/mocks/DockerRunner.go @@ -0,0 +1,131 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + core "github.com/LambdaTest/test-at-scale/pkg/core" + mock "github.com/stretchr/testify/mock" +) + +// DockerRunner is an autogenerated mock type for the DockerRunner type +type DockerRunner struct { + mock.Mock +} + +// Create provides a mock function with given fields: _a0, _a1 +func (_m *DockerRunner) Create(_a0 context.Context, _a1 *core.RunnerOptions) core.ContainerStatus { + ret := _m.Called(_a0, _a1) + + var r0 core.ContainerStatus + if rf, ok := ret.Get(0).(func(context.Context, *core.RunnerOptions) core.ContainerStatus); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Get(0).(core.ContainerStatus) + } + + return r0 +} + +// Destroy provides a mock function with given fields: ctx, r +func (_m *DockerRunner) Destroy(ctx context.Context, r *core.RunnerOptions) error { + ret := _m.Called(ctx, r) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *core.RunnerOptions) error); ok { + r0 = rf(ctx, r) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetInfo provides a mock function with given fields: _a0 +func (_m *DockerRunner) GetInfo(_a0 context.Context) (float32, int64) { + ret := _m.Called(_a0) + + var r0 float32 + if rf, ok := ret.Get(0).(func(context.Context) float32); ok { + r0 = rf(_a0) + } else { + r0 = ret.Get(0).(float32) + } + + var r1 int64 + if rf, ok := ret.Get(1).(func(context.Context) int64); ok { + r1 = rf(_a0) + } else { + r1 = ret.Get(1).(int64) + } + + return r0, r1 +} + +// Initiate provides a mock function with given fields: _a0, _a1, _a2 +func (_m *DockerRunner) Initiate(_a0 context.Context, _a1 *core.RunnerOptions, _a2 chan core.ContainerStatus) { + _m.Called(_a0, _a1, _a2) +} + +// KillRunningDocker provides a mock function with given fields: ctx +func (_m *DockerRunner) KillRunningDocker(ctx context.Context) { + _m.Called(ctx) +} + +// PullImage provides a mock function with given fields: containerImageConfig, r +func (_m *DockerRunner) PullImage(containerImageConfig *core.ContainerImageConfig, r *core.RunnerOptions) error { + ret := _m.Called(containerImageConfig, r) + + var r0 error + if rf, ok := ret.Get(0).(func(*core.ContainerImageConfig, *core.RunnerOptions) error); ok { + r0 = rf(containerImageConfig, r) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Run provides a mock function with given fields: _a0, _a1 +func (_m *DockerRunner) Run(_a0 context.Context, _a1 *core.RunnerOptions) core.ContainerStatus { + ret := _m.Called(_a0, _a1) + + var r0 core.ContainerStatus + if rf, ok := ret.Get(0).(func(context.Context, *core.RunnerOptions) core.ContainerStatus); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Get(0).(core.ContainerStatus) + } + + return r0 +} + +// WaitForCompletion provides a mock function with given fields: ctx, r +func (_m *DockerRunner) WaitForCompletion(ctx context.Context, r *core.RunnerOptions) error { + ret := _m.Called(ctx, r) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *core.RunnerOptions) error); ok { + r0 = rf(ctx, r) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type mockConstructorTestingTNewDockerRunner interface { + mock.TestingT + Cleanup(func()) +} + +// NewDockerRunner creates a new instance of DockerRunner. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewDockerRunner(t mockConstructorTestingTNewDockerRunner) *DockerRunner { + mock := &DockerRunner{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/Driver.go b/mocks/Driver.go new file mode 100644 index 00000000..6bcdce2d --- /dev/null +++ b/mocks/Driver.go @@ -0,0 +1,58 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + core "github.com/LambdaTest/test-at-scale/pkg/core" + mock "github.com/stretchr/testify/mock" +) + +// Driver is an autogenerated mock type for the Driver type +type Driver struct { + mock.Mock +} + +// RunDiscovery provides a mock function with given fields: ctx, payload, taskPayload, oauth, coverageDir, secretMap +func (_m *Driver) RunDiscovery(ctx context.Context, payload *core.Payload, taskPayload *core.TaskPayload, oauth *core.Oauth, coverageDir string, secretMap map[string]string) error { + ret := _m.Called(ctx, payload, taskPayload, oauth, coverageDir, secretMap) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *core.Payload, *core.TaskPayload, *core.Oauth, string, map[string]string) error); ok { + r0 = rf(ctx, payload, taskPayload, oauth, coverageDir, secretMap) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// RunExecution provides a mock function with given fields: ctx, payload, taskPayload, oauth, coverageDir, secretMap +func (_m *Driver) RunExecution(ctx context.Context, payload *core.Payload, taskPayload *core.TaskPayload, oauth *core.Oauth, coverageDir string, secretMap map[string]string) error { + ret := _m.Called(ctx, payload, taskPayload, oauth, coverageDir, secretMap) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *core.Payload, *core.TaskPayload, *core.Oauth, string, map[string]string) error); ok { + r0 = rf(ctx, payload, taskPayload, oauth, coverageDir, secretMap) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type mockConstructorTestingTNewDriver interface { + mock.TestingT + Cleanup(func()) +} + +// NewDriver creates a new instance of Driver. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewDriver(t mockConstructorTestingTNewDriver) *Driver { + mock := &Driver{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/testutils/mocks/ExecutionManager.go b/mocks/ExecutionManager.go similarity index 87% rename from testutils/mocks/ExecutionManager.go rename to mocks/ExecutionManager.go index 02b5895a..5411b60c 100644 --- a/testutils/mocks/ExecutionManager.go +++ b/mocks/ExecutionManager.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.12.1. DO NOT EDIT. +// Code generated by mockery v2.14.0. DO NOT EDIT. package mocks @@ -7,8 +7,6 @@ import ( core "github.com/LambdaTest/test-at-scale/pkg/core" mock "github.com/stretchr/testify/mock" - - testing "testing" ) // ExecutionManager is an autogenerated mock type for the ExecutionManager type @@ -67,8 +65,13 @@ func (_m *ExecutionManager) GetEnvVariables(envMap map[string]string, secretData return r0, r1 } -// NewExecutionManager creates a new instance of ExecutionManager. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewExecutionManager(t testing.TB) *ExecutionManager { +type mockConstructorTestingTNewExecutionManager interface { + mock.TestingT + Cleanup(func()) +} + +// NewExecutionManager creates a new instance of ExecutionManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewExecutionManager(t mockConstructorTestingTNewExecutionManager) *ExecutionManager { mock := &ExecutionManager{} mock.Mock.Test(t) diff --git a/mocks/GitManager.go b/mocks/GitManager.go new file mode 100644 index 00000000..91df524d --- /dev/null +++ b/mocks/GitManager.go @@ -0,0 +1,44 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + core "github.com/LambdaTest/test-at-scale/pkg/core" + mock "github.com/stretchr/testify/mock" +) + +// GitManager is an autogenerated mock type for the GitManager type +type GitManager struct { + mock.Mock +} + +// Clone provides a mock function with given fields: ctx, payload, oauth +func (_m *GitManager) Clone(ctx context.Context, payload *core.Payload, oauth *core.Oauth) error { + ret := _m.Called(ctx, payload, oauth) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *core.Payload, *core.Oauth) error); ok { + r0 = rf(ctx, payload, oauth) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type mockConstructorTestingTNewGitManager interface { + mock.TestingT + Cleanup(func()) +} + +// NewGitManager creates a new instance of GitManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewGitManager(t mockConstructorTestingTNewGitManager) *GitManager { + mock := &GitManager{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/ListSubModuleService.go b/mocks/ListSubModuleService.go new file mode 100644 index 00000000..daa46e6c --- /dev/null +++ b/mocks/ListSubModuleService.go @@ -0,0 +1,43 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// ListSubModuleService is an autogenerated mock type for the ListSubModuleService type +type ListSubModuleService struct { + mock.Mock +} + +// Send provides a mock function with given fields: ctx, buildID, totalSubmodule +func (_m *ListSubModuleService) Send(ctx context.Context, buildID string, totalSubmodule int) error { + ret := _m.Called(ctx, buildID, totalSubmodule) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, int) error); ok { + r0 = rf(ctx, buildID, totalSubmodule) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type mockConstructorTestingTNewListSubModuleService interface { + mock.TestingT + Cleanup(func()) +} + +// NewListSubModuleService creates a new instance of ListSubModuleService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewListSubModuleService(t mockConstructorTestingTNewListSubModuleService) *ListSubModuleService { + mock := &ListSubModuleService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/LogWriterStrategy.go b/mocks/LogWriterStrategy.go new file mode 100644 index 00000000..97d0710b --- /dev/null +++ b/mocks/LogWriterStrategy.go @@ -0,0 +1,47 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + io "io" + + mock "github.com/stretchr/testify/mock" +) + +// LogWriterStrategy is an autogenerated mock type for the LogWriterStrategy type +type LogWriterStrategy struct { + mock.Mock +} + +// Write provides a mock function with given fields: ctx, reader +func (_m *LogWriterStrategy) Write(ctx context.Context, reader io.Reader) <-chan error { + ret := _m.Called(ctx, reader) + + var r0 <-chan error + if rf, ok := ret.Get(0).(func(context.Context, io.Reader) <-chan error); ok { + r0 = rf(ctx, reader) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(<-chan error) + } + } + + return r0 +} + +type mockConstructorTestingTNewLogWriterStrategy interface { + mock.TestingT + Cleanup(func()) +} + +// NewLogWriterStrategy creates a new instance of LogWriterStrategy. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewLogWriterStrategy(t mockConstructorTestingTNewLogWriterStrategy) *LogWriterStrategy { + mock := &LogWriterStrategy{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/Logger.go b/mocks/Logger.go new file mode 100644 index 00000000..8753444a --- /dev/null +++ b/mocks/Logger.go @@ -0,0 +1,92 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + lumber "github.com/LambdaTest/test-at-scale/pkg/lumber" + mock "github.com/stretchr/testify/mock" +) + +// Logger is an autogenerated mock type for the Logger type +type Logger struct { + mock.Mock +} + +// Debugf provides a mock function with given fields: format, args +func (_m *Logger) Debugf(format string, args ...interface{}) { + var _ca []interface{} + _ca = append(_ca, format) + _ca = append(_ca, args...) + _m.Called(_ca...) +} + +// Errorf provides a mock function with given fields: format, args +func (_m *Logger) Errorf(format string, args ...interface{}) { + var _ca []interface{} + _ca = append(_ca, format) + _ca = append(_ca, args...) + _m.Called(_ca...) +} + +// Fatalf provides a mock function with given fields: format, args +func (_m *Logger) Fatalf(format string, args ...interface{}) { + var _ca []interface{} + _ca = append(_ca, format) + _ca = append(_ca, args...) + _m.Called(_ca...) +} + +// Infof provides a mock function with given fields: format, args +func (_m *Logger) Infof(format string, args ...interface{}) { + var _ca []interface{} + _ca = append(_ca, format) + _ca = append(_ca, args...) + _m.Called(_ca...) +} + +// Panicf provides a mock function with given fields: format, args +func (_m *Logger) Panicf(format string, args ...interface{}) { + var _ca []interface{} + _ca = append(_ca, format) + _ca = append(_ca, args...) + _m.Called(_ca...) +} + +// Warnf provides a mock function with given fields: format, args +func (_m *Logger) Warnf(format string, args ...interface{}) { + var _ca []interface{} + _ca = append(_ca, format) + _ca = append(_ca, args...) + _m.Called(_ca...) +} + +// WithFields provides a mock function with given fields: keyValues +func (_m *Logger) WithFields(keyValues lumber.Fields) lumber.Logger { + ret := _m.Called(keyValues) + + var r0 lumber.Logger + if rf, ok := ret.Get(0).(func(lumber.Fields) lumber.Logger); ok { + r0 = rf(keyValues) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(lumber.Logger) + } + } + + return r0 +} + +type mockConstructorTestingTNewLogger interface { + mock.TestingT + Cleanup(func()) +} + +// NewLogger creates a new instance of Logger. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewLogger(t mockConstructorTestingTNewLogger) *Logger { + mock := &Logger{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/PayloadManager.go b/mocks/PayloadManager.go new file mode 100644 index 00000000..fa266a02 --- /dev/null +++ b/mocks/PayloadManager.go @@ -0,0 +1,67 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + core "github.com/LambdaTest/test-at-scale/pkg/core" + mock "github.com/stretchr/testify/mock" +) + +// PayloadManager is an autogenerated mock type for the PayloadManager type +type PayloadManager struct { + mock.Mock +} + +// FetchPayload provides a mock function with given fields: ctx, payloadAddress +func (_m *PayloadManager) FetchPayload(ctx context.Context, payloadAddress string) (*core.Payload, error) { + ret := _m.Called(ctx, payloadAddress) + + var r0 *core.Payload + if rf, ok := ret.Get(0).(func(context.Context, string) *core.Payload); ok { + r0 = rf(ctx, payloadAddress) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*core.Payload) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, payloadAddress) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ValidatePayload provides a mock function with given fields: ctx, payload +func (_m *PayloadManager) ValidatePayload(ctx context.Context, payload *core.Payload) error { + ret := _m.Called(ctx, payload) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *core.Payload) error); ok { + r0 = rf(ctx, payload) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type mockConstructorTestingTNewPayloadManager interface { + mock.TestingT + Cleanup(func()) +} + +// NewPayloadManager creates a new instance of PayloadManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewPayloadManager(t mockConstructorTestingTNewPayloadManager) *PayloadManager { + mock := &PayloadManager{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/Requests.go b/mocks/Requests.go new file mode 100644 index 00000000..ca4b560d --- /dev/null +++ b/mocks/Requests.go @@ -0,0 +1,59 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// Requests is an autogenerated mock type for the Requests type +type Requests struct { + mock.Mock +} + +// MakeAPIRequest provides a mock function with given fields: ctx, httpMethod, endpoint, body, params, headers +func (_m *Requests) MakeAPIRequest(ctx context.Context, httpMethod string, endpoint string, body []byte, params map[string]interface{}, headers map[string]string) ([]byte, int, error) { + ret := _m.Called(ctx, httpMethod, endpoint, body, params, headers) + + var r0 []byte + if rf, ok := ret.Get(0).(func(context.Context, string, string, []byte, map[string]interface{}, map[string]string) []byte); ok { + r0 = rf(ctx, httpMethod, endpoint, body, params, headers) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + var r1 int + if rf, ok := ret.Get(1).(func(context.Context, string, string, []byte, map[string]interface{}, map[string]string) int); ok { + r1 = rf(ctx, httpMethod, endpoint, body, params, headers) + } else { + r1 = ret.Get(1).(int) + } + + var r2 error + if rf, ok := ret.Get(2).(func(context.Context, string, string, []byte, map[string]interface{}, map[string]string) error); ok { + r2 = rf(ctx, httpMethod, endpoint, body, params, headers) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +type mockConstructorTestingTNewRequests interface { + mock.TestingT + Cleanup(func()) +} + +// NewRequests creates a new instance of Requests. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewRequests(t mockConstructorTestingTNewRequests) *Requests { + mock := &Requests{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/testutils/mocks/SecretParser.go b/mocks/SecretParser.go similarity index 80% rename from testutils/mocks/SecretParser.go rename to mocks/SecretParser.go index c0a4ee15..018f1cd0 100644 --- a/testutils/mocks/SecretParser.go +++ b/mocks/SecretParser.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.14.0. DO NOT EDIT. package mocks @@ -92,3 +92,18 @@ func (_m *SecretParser) SubstituteSecret(command string, secretData map[string]s return r0, r1 } + +type mockConstructorTestingTNewSecretParser interface { + mock.TestingT + Cleanup(func()) +} + +// NewSecretParser creates a new instance of SecretParser. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewSecretParser(t mockConstructorTestingTNewSecretParser) *SecretParser { + mock := &SecretParser{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/SecretsManager.go b/mocks/SecretsManager.go new file mode 100644 index 00000000..526c706b --- /dev/null +++ b/mocks/SecretsManager.go @@ -0,0 +1,109 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + config "github.com/LambdaTest/test-at-scale/config" + core "github.com/LambdaTest/test-at-scale/pkg/core" + + mock "github.com/stretchr/testify/mock" +) + +// SecretsManager is an autogenerated mock type for the SecretsManager type +type SecretsManager struct { + mock.Mock +} + +// GetDockerSecrets provides a mock function with given fields: r +func (_m *SecretsManager) GetDockerSecrets(r *core.RunnerOptions) (core.ContainerImageConfig, error) { + ret := _m.Called(r) + + var r0 core.ContainerImageConfig + if rf, ok := ret.Get(0).(func(*core.RunnerOptions) core.ContainerImageConfig); ok { + r0 = rf(r) + } else { + r0 = ret.Get(0).(core.ContainerImageConfig) + } + + var r1 error + if rf, ok := ret.Get(1).(func(*core.RunnerOptions) error); ok { + r1 = rf(r) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetLambdatestSecrets provides a mock function with given fields: +func (_m *SecretsManager) GetLambdatestSecrets() *config.LambdatestConfig { + ret := _m.Called() + + var r0 *config.LambdatestConfig + if rf, ok := ret.Get(0).(func() *config.LambdatestConfig); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*config.LambdatestConfig) + } + } + + return r0 +} + +// GetSynapseName provides a mock function with given fields: +func (_m *SecretsManager) GetSynapseName() string { + ret := _m.Called() + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// WriteGitSecrets provides a mock function with given fields: path +func (_m *SecretsManager) WriteGitSecrets(path string) error { + ret := _m.Called(path) + + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { + r0 = rf(path) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// WriteRepoSecrets provides a mock function with given fields: repo, path +func (_m *SecretsManager) WriteRepoSecrets(repo string, path string) error { + ret := _m.Called(repo, path) + + var r0 error + if rf, ok := ret.Get(0).(func(string, string) error); ok { + r0 = rf(repo, path) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type mockConstructorTestingTNewSecretsManager interface { + mock.TestingT + Cleanup(func()) +} + +// NewSecretsManager creates a new instance of SecretsManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewSecretsManager(t mockConstructorTestingTNewSecretsManager) *SecretsManager { + mock := &SecretsManager{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/SynapseManager.go b/mocks/SynapseManager.go new file mode 100644 index 00000000..cc9675ae --- /dev/null +++ b/mocks/SynapseManager.go @@ -0,0 +1,36 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + + sync "sync" +) + +// SynapseManager is an autogenerated mock type for the SynapseManager type +type SynapseManager struct { + mock.Mock +} + +// InitiateConnection provides a mock function with given fields: ctx, wg, connectionFailed +func (_m *SynapseManager) InitiateConnection(ctx context.Context, wg *sync.WaitGroup, connectionFailed chan struct{}) { + _m.Called(ctx, wg, connectionFailed) +} + +type mockConstructorTestingTNewSynapseManager interface { + mock.TestingT + Cleanup(func()) +} + +// NewSynapseManager creates a new instance of SynapseManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewSynapseManager(t mockConstructorTestingTNewSynapseManager) *SynapseManager { + mock := &SynapseManager{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/testutils/mocks/TASConfigManager.go b/mocks/TASConfigManager.go similarity index 82% rename from testutils/mocks/TASConfigManager.go rename to mocks/TASConfigManager.go index 2d7f6307..ebbe7410 100644 --- a/testutils/mocks/TASConfigManager.go +++ b/mocks/TASConfigManager.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.12.1. DO NOT EDIT. +// Code generated by mockery v2.14.0. DO NOT EDIT. package mocks @@ -7,8 +7,6 @@ import ( core "github.com/LambdaTest/test-at-scale/pkg/core" mock "github.com/stretchr/testify/mock" - - testing "testing" ) // TASConfigManager is an autogenerated mock type for the TASConfigManager type @@ -60,8 +58,13 @@ func (_m *TASConfigManager) LoadAndValidate(ctx context.Context, version int, pa return r0, r1 } -// NewTASConfigManager creates a new instance of TASConfigManager. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewTASConfigManager(t testing.TB) *TASConfigManager { +type mockConstructorTestingTNewTASConfigManager interface { + mock.TestingT + Cleanup(func()) +} + +// NewTASConfigManager creates a new instance of TASConfigManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewTASConfigManager(t mockConstructorTestingTNewTASConfigManager) *TASConfigManager { mock := &TASConfigManager{} mock.Mock.Test(t) diff --git a/mocks/Task.go b/mocks/Task.go new file mode 100644 index 00000000..edc50d6b --- /dev/null +++ b/mocks/Task.go @@ -0,0 +1,44 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + core "github.com/LambdaTest/test-at-scale/pkg/core" + mock "github.com/stretchr/testify/mock" +) + +// Task is an autogenerated mock type for the Task type +type Task struct { + mock.Mock +} + +// UpdateStatus provides a mock function with given fields: ctx, payload +func (_m *Task) UpdateStatus(ctx context.Context, payload *core.TaskPayload) error { + ret := _m.Called(ctx, payload) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *core.TaskPayload) error); ok { + r0 = rf(ctx, payload) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type mockConstructorTestingTNewTask interface { + mock.TestingT + Cleanup(func()) +} + +// NewTask creates a new instance of Task. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewTask(t mockConstructorTestingTNewTask) *Task { + mock := &Task{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/testutils/mocks/TestDiscoveryService.go b/mocks/TestDiscoveryService.go similarity index 67% rename from testutils/mocks/TestDiscoveryService.go rename to mocks/TestDiscoveryService.go index c0439373..c2fbb5a0 100644 --- a/testutils/mocks/TestDiscoveryService.go +++ b/mocks/TestDiscoveryService.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.12.1. DO NOT EDIT. +// Code generated by mockery v2.14.0. DO NOT EDIT. package mocks @@ -7,8 +7,6 @@ import ( core "github.com/LambdaTest/test-at-scale/pkg/core" mock "github.com/stretchr/testify/mock" - - testing "testing" ) // TestDiscoveryService is an autogenerated mock type for the TestDiscoveryService type @@ -17,11 +15,11 @@ type TestDiscoveryService struct { } // Discover provides a mock function with given fields: ctx, args -func (_m *TestDiscoveryService) Discover(ctx context.Context, args core.DiscoveyArgs) (*core.DiscoveryResult, error) { +func (_m *TestDiscoveryService) Discover(ctx context.Context, args *core.DiscoveyArgs) (*core.DiscoveryResult, error) { ret := _m.Called(ctx, args) var r0 *core.DiscoveryResult - if rf, ok := ret.Get(0).(func(context.Context, core.DiscoveyArgs) *core.DiscoveryResult); ok { + if rf, ok := ret.Get(0).(func(context.Context, *core.DiscoveyArgs) *core.DiscoveryResult); ok { r0 = rf(ctx, args) } else { if ret.Get(0) != nil { @@ -30,7 +28,7 @@ func (_m *TestDiscoveryService) Discover(ctx context.Context, args core.Discovey } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, core.DiscoveyArgs) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *core.DiscoveyArgs) error); ok { r1 = rf(ctx, args) } else { r1 = ret.Error(1) @@ -53,8 +51,13 @@ func (_m *TestDiscoveryService) SendResult(ctx context.Context, testDiscoveryRes return r0 } -// NewTestDiscoveryService creates a new instance of TestDiscoveryService. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewTestDiscoveryService(t testing.TB) *TestDiscoveryService { +type mockConstructorTestingTNewTestDiscoveryService interface { + mock.TestingT + Cleanup(func()) +} + +// NewTestDiscoveryService creates a new instance of TestDiscoveryService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewTestDiscoveryService(t mockConstructorTestingTNewTestDiscoveryService) *TestDiscoveryService { mock := &TestDiscoveryService{} mock.Mock.Test(t) diff --git a/testutils/mocks/TestExecutionService.go b/mocks/TestExecutionService.go similarity index 71% rename from testutils/mocks/TestExecutionService.go rename to mocks/TestExecutionService.go index cef9c548..152548de 100644 --- a/testutils/mocks/TestExecutionService.go +++ b/mocks/TestExecutionService.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.12.1. DO NOT EDIT. +// Code generated by mockery v2.14.0. DO NOT EDIT. package mocks @@ -7,8 +7,6 @@ import ( core "github.com/LambdaTest/test-at-scale/pkg/core" mock "github.com/stretchr/testify/mock" - - testing "testing" ) // TestExecutionService is an autogenerated mock type for the TestExecutionService type @@ -17,11 +15,11 @@ type TestExecutionService struct { } // Run provides a mock function with given fields: ctx, testExecutionArgs -func (_m *TestExecutionService) Run(ctx context.Context, testExecutionArgs core.TestExecutionArgs) (*core.ExecutionResults, error) { +func (_m *TestExecutionService) Run(ctx context.Context, testExecutionArgs *core.TestExecutionArgs) (*core.ExecutionResults, error) { ret := _m.Called(ctx, testExecutionArgs) var r0 *core.ExecutionResults - if rf, ok := ret.Get(0).(func(context.Context, core.TestExecutionArgs) *core.ExecutionResults); ok { + if rf, ok := ret.Get(0).(func(context.Context, *core.TestExecutionArgs) *core.ExecutionResults); ok { r0 = rf(ctx, testExecutionArgs) } else { if ret.Get(0) != nil { @@ -30,7 +28,7 @@ func (_m *TestExecutionService) Run(ctx context.Context, testExecutionArgs core. } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, core.TestExecutionArgs) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *core.TestExecutionArgs) error); ok { r1 = rf(ctx, testExecutionArgs) } else { r1 = ret.Error(1) @@ -62,8 +60,13 @@ func (_m *TestExecutionService) SendResults(ctx context.Context, payload *core.E return r0, r1 } -// NewTestExecutionService creates a new instance of TestExecutionService. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewTestExecutionService(t testing.TB) *TestExecutionService { +type mockConstructorTestingTNewTestExecutionService interface { + mock.TestingT + Cleanup(func()) +} + +// NewTestExecutionService creates a new instance of TestExecutionService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewTestExecutionService(t mockConstructorTestingTNewTestExecutionService) *TestExecutionService { mock := &TestExecutionService{} mock.Mock.Test(t) diff --git a/mocks/TestStats.go b/mocks/TestStats.go new file mode 100644 index 00000000..66341ff7 --- /dev/null +++ b/mocks/TestStats.go @@ -0,0 +1,39 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// TestStats is an autogenerated mock type for the TestStats type +type TestStats struct { + mock.Mock +} + +// CaptureTestStats provides a mock function with given fields: pid, collectStats +func (_m *TestStats) CaptureTestStats(pid int32, collectStats bool) error { + ret := _m.Called(pid, collectStats) + + var r0 error + if rf, ok := ret.Get(0).(func(int32, bool) error); ok { + r0 = rf(pid, collectStats) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type mockConstructorTestingTNewTestStats interface { + mock.TestingT + Cleanup(func()) +} + +// NewTestStats creates a new instance of TestStats. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewTestStats(t mockConstructorTestingTNewTestStats) *TestStats { + mock := &TestStats{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/testutils/mocks/ZstdCompressor.go b/mocks/ZstdCompressor.go similarity index 74% rename from testutils/mocks/ZstdCompressor.go rename to mocks/ZstdCompressor.go index aae7f7fe..e9c0d708 100644 --- a/testutils/mocks/ZstdCompressor.go +++ b/mocks/ZstdCompressor.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.14.0. DO NOT EDIT. package mocks @@ -47,3 +47,18 @@ func (_m *ZstdCompressor) Decompress(ctx context.Context, filePath string, prese return r0 } + +type mockConstructorTestingTNewZstdCompressor interface { + mock.TestingT + Cleanup(func()) +} + +// NewZstdCompressor creates a new instance of ZstdCompressor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewZstdCompressor(t mockConstructorTestingTNewZstdCompressor) *ZstdCompressor { + mock := &ZstdCompressor{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/azure/client.go b/pkg/azure/client.go index b189b0aa..1e1dfa84 100644 --- a/pkg/azure/client.go +++ b/pkg/azure/client.go @@ -8,7 +8,6 @@ import ( "io" "net/http" "net/url" - "os" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" @@ -38,8 +37,7 @@ type store struct { // request body for getting SAS URL API. type request struct { - BlobPath string `json:"blob_path"` - BlobType core.ContainerType `json:"blob_type"` + Purpose core.SASURLPurpose `json:"purpose" validate:"oneof=cache workspace_cache pre_run_logs post_run_logs execution_logs"` } // response body for get SAS URL API. @@ -155,21 +153,21 @@ func (s *store) Create(ctx context.Context, path string, reader io.Reader, mimeT } // GetSASURL calls request neuron to get the SAS url -func (s *store) GetSASURL(ctx context.Context, containerPath string, containerType core.ContainerType) (string, error) { - reqPayload := &request{ - BlobPath: containerPath, - BlobType: containerType, - } +func (s *store) GetSASURL(ctx context.Context, purpose core.SASURLPurpose, query map[string]interface{}) (string, error) { + reqPayload := &request{Purpose: purpose} reqBody, err := json.Marshal(reqPayload) if err != nil { s.logger.Errorf("failed to marshal request body %v", err) return "", err } - params := utils.FetchQueryParams() - headers := map[string]string{ - "Authorization": fmt.Sprintf("%s %s", "Bearer", os.Getenv("TOKEN")), + defaultQuery, headers := utils.GetDefaultQueryAndHeaders() + for key, val := range defaultQuery { + if query == nil { + query = make(map[string]interface{}) + } + query[key] = val } - rawBytes, _, err := s.requests.MakeAPIRequest(ctx, http.MethodPost, s.endpoint, reqBody, params, headers) + rawBytes, _, err := s.requests.MakeAPIRequest(ctx, http.MethodPost, s.endpoint, reqBody, query, headers) if err != nil { return "", err } diff --git a/pkg/blocktestservice/setup.go b/pkg/blocktestservice/setup.go index 78c58cc3..ccb9315c 100644 --- a/pkg/blocktestservice/setup.go +++ b/pkg/blocktestservice/setup.go @@ -4,10 +4,8 @@ package blocktestservice import ( "context" "encoding/json" - "fmt" "io/ioutil" "net/http" - "os" "strings" "sync" @@ -67,15 +65,10 @@ func NewTestBlockTestService(cfg *config.NucleusConfig, requests core.Requests, func (tbs *TestBlockTestService) fetchBlockListFromNeuron(ctx context.Context, branch string) error { var inp []blocktestAPIResponse - params := utils.FetchQueryParams() - params["branch"] = branch - params["taskID"] = tbs.cfg.TaskID + query, headers := utils.GetDefaultQueryAndHeaders() + query["branch"] = branch - headers := map[string]string{ - "Authorization": fmt.Sprintf("%s %s", "Bearer", os.Getenv("TOKEN")), - } - - rawBytes, statusCode, err := tbs.requests.MakeAPIRequest(ctx, http.MethodGet, tbs.endpoint, nil, params, headers) + rawBytes, statusCode, err := tbs.requests.MakeAPIRequest(ctx, http.MethodGet, tbs.endpoint, nil, query, headers) if statusCode == http.StatusNotFound { return nil } diff --git a/pkg/cachemanager/cachemanager.go b/pkg/cachemanager/cachemanager.go index 476ef58a..35ddee6e 100644 --- a/pkg/cachemanager/cachemanager.go +++ b/pkg/cachemanager/cachemanager.go @@ -54,16 +54,16 @@ func New(z core.ZstdCompressor, azureClient core.AzureClient, logger lumber.Logg }, nil } -func (c *cache) getCacheSASURL(ctx context.Context, containerPath string) (string, error) { +func (c *cache) getCacheSASURL(ctx context.Context, cacheKey string) (string, error) { c.once.Do(func() { - cacheBlobURL, apiErr = c.azureClient.GetSASURL(ctx, containerPath, core.CacheContainer) + query := map[string]interface{}{"key": cacheKey} + cacheBlobURL, apiErr = c.azureClient.GetSASURL(ctx, core.PurposeCache, query) }) return cacheBlobURL, apiErr } func (c *cache) Download(ctx context.Context, cacheKey string) error { - containerPath := fmt.Sprintf("%s/%s", cacheKey, defaultCompressedFileName) - sasURL, err := c.getCacheSASURL(ctx, containerPath) + sasURL, err := c.getCacheSASURL(ctx, cacheKey) if err != nil { c.logger.Errorf("Error while generating SAS Token, error %v", err) return err @@ -139,8 +139,7 @@ func (c *cache) Upload(ctx context.Context, cacheKey string, itemsToCompress ... } defer f.Close() - containerPath := fmt.Sprintf("%s/%s", cacheKey, defaultCompressedFileName) - sasURL, err := c.getCacheSASURL(ctx, containerPath) + sasURL, err := c.getCacheSASURL(ctx, cacheKey) if err != nil { c.logger.Errorf("Error while generating SAS Token, error %v", err) return err diff --git a/pkg/command/run_test.go b/pkg/command/run_test.go index c6be2f30..d86693eb 100644 --- a/pkg/command/run_test.go +++ b/pkg/command/run_test.go @@ -7,11 +7,11 @@ import ( "sort" "testing" + "github.com/LambdaTest/test-at-scale/mocks" "github.com/LambdaTest/test-at-scale/pkg/core" "github.com/LambdaTest/test-at-scale/pkg/lumber" "github.com/LambdaTest/test-at-scale/pkg/secret" "github.com/LambdaTest/test-at-scale/testutils" - "github.com/LambdaTest/test-at-scale/testutils/mocks" ) func TestNewExecutionManager(t *testing.T) { diff --git a/pkg/command/script_test.go b/pkg/command/script_test.go index e3a72d0f..a6f8b483 100644 --- a/pkg/command/script_test.go +++ b/pkg/command/script_test.go @@ -3,11 +3,11 @@ package command import ( "testing" + "github.com/LambdaTest/test-at-scale/mocks" "github.com/LambdaTest/test-at-scale/pkg/core" "github.com/LambdaTest/test-at-scale/pkg/errs" "github.com/LambdaTest/test-at-scale/pkg/lumber" "github.com/LambdaTest/test-at-scale/testutils" - "github.com/LambdaTest/test-at-scale/testutils/mocks" "github.com/stretchr/testify/mock" ) diff --git a/pkg/core/interfaces.go b/pkg/core/interfaces.go index 6418dcfa..8b3f9024 100644 --- a/pkg/core/interfaces.go +++ b/pkg/core/interfaces.go @@ -85,7 +85,7 @@ type AzureClient interface { Find(ctx context.Context, path string) (io.ReadCloser, error) Create(ctx context.Context, path string, reader io.Reader, mimeType string) (string, error) CreateUsingSASURL(ctx context.Context, sasURL string, reader io.Reader, mimeType string) (string, error) - GetSASURL(ctx context.Context, containerPath string, containerType ContainerType) (string, error) + GetSASURL(ctx context.Context, purpose SASURLPurpose, query map[string]interface{}) (string, error) Exists(ctx context.Context, path string) (bool, error) } @@ -144,7 +144,7 @@ type ExecutionManager interface { // Requests is a util interface for making API Requests type Requests interface { // MakeAPIRequest makes an HTTP request with auth - MakeAPIRequest(ctx context.Context, httpMethod, endpoint string, body []byte, params, + MakeAPIRequest(ctx context.Context, httpMethod, endpoint string, body []byte, params map[string]interface{}, headers map[string]string) (rawbody []byte, statusCode int, err error) } diff --git a/pkg/core/models.go b/pkg/core/models.go index fe42fca8..69a8a458 100644 --- a/pkg/core/models.go +++ b/pkg/core/models.go @@ -13,14 +13,20 @@ import ( // ExecutionID type type ExecutionID string -// Tier type of synapse -type Tier string +// SASURLPurpose defines reasons for which SAS Url is required +type SASURLPurpose string -// CommandType defines type of command -type CommandType string +// SASURLPurpose values +const ( + PurposeCache SASURLPurpose = "cache" + PurposeWorkspaceCache SASURLPurpose = "workspace_cache" + PurposePreRunLogs SASURLPurpose = "pre_run_logs" + PurposePostRunLogs SASURLPurpose = "post_run_logs" + PurposeExecutionLogs SASURLPurpose = "execution_logs" +) -// ContainerType defines types of container -type ContainerType string +// Tier type of synapse +type Tier string // TaskTier values. const ( @@ -49,6 +55,9 @@ const ( TestSplit SplitMode = "test" ) +// CommandType defines type of command +type CommandType string + // Types of Command string const ( PreRun CommandType = "prerun" @@ -63,13 +72,6 @@ const ( RenameCloneFile CommandType = "renameclonefile" ) -// Types of containers -const ( - CacheContainer ContainerType = "cache" - LogsContainer ContainerType = "logs" - PayloadContainer ContainerType = "container-payload" -) - // EventType represents the webhook event type EventType string @@ -332,9 +334,8 @@ type CoverageThreshold struct { // Cache represents the user's cached directories type Cache struct { - Key string `yaml:"key" validate:"required"` - Paths []string `yaml:"paths" validate:"required"` - Version string + Key string `yaml:"key" validate:"required"` + Paths []string `yaml:"paths" validate:"required"` } // Modifier defines struct for modifier diff --git a/pkg/core/runner.go b/pkg/core/runner.go index bdec2aa4..528dac66 100644 --- a/pkg/core/runner.go +++ b/pkg/core/runner.go @@ -15,12 +15,12 @@ type Specs struct { // TierOpts is const map which map each tier to specs var TierOpts = map[Tier]Specs{ - Internal: {CPU: 0.5, RAM: 384}, - XSmall: {CPU: 1, RAM: 2000}, - Small: {CPU: 2, RAM: 4000}, - Medium: {CPU: 4, RAM: 8000}, - Large: {CPU: 8, RAM: 16000}, - XLarge: {CPU: 16, RAM: 32000}, + Internal: {CPU: 0.5, RAM: 256}, + XSmall: {CPU: 1, RAM: 2048}, + Small: {CPU: 2, RAM: 4096}, + Medium: {CPU: 4, RAM: 8192}, + Large: {CPU: 8, RAM: 16384}, + XLarge: {CPU: 16, RAM: 32768}, } // ContainerStatus contains status of container @@ -66,25 +66,24 @@ type DockerRunner interface { // RunnerOptions provides the the required instructions for execution engine. type RunnerOptions struct { - ContainerID string `json:"container_id"` - DockerImage string `json:"docker_image"` - ContainerPort int `json:"container_port"` - HostPort int `json:"host_port"` - Label map[string]string `json:"label"` - NameSpace string `json:"name_space"` - ServiceAccount string `json:"service_account"` - PodName string `json:"pod_name"` - ContainerName string `json:"container_name"` - ContainerArgs []string `json:"container_args"` - ContainerCommands []string `json:"container_commands"` - HostVolumePath string `json:"host_volume_path"` - PersistentVolumeClaimName string `json:"persistent_volume_claim_name"` - Env []string `json:"env"` - OrgID string `json:"org_id"` - Vault *VaultOpts `json:"vault"` - LogfilePath string `json:"logfile_path"` - PodType PodType `json:"pod_type"` - Tier Tier `json:"tier"` + ContainerID string `json:"container_id"` + DockerImage string `json:"docker_image"` + ContainerPort int `json:"container_port"` + HostPort int `json:"host_port"` + Label map[string]string `json:"label"` + NameSpace string `json:"name_space"` + ServiceAccount string `json:"service_account"` + PodName string `json:"pod_name"` + ContainerName string `json:"container_name"` + ContainerArgs []string `json:"container_args"` + ContainerCommands []string `json:"container_commands"` + HostVolumePath string `json:"host_volume_path"` + Env []string `json:"env"` + OrgID string `json:"org_id"` + Vault *VaultOpts `json:"vault"` + LogfilePath string `json:"logfile_path"` + PodType PodType `json:"pod_type"` + Tier Tier `json:"tier"` } // VaultOpts provides the vault path options diff --git a/pkg/driver/driver_v1.go b/pkg/driver/driver_v1.go index e27b8fa5..cf2dcda2 100644 --- a/pkg/driver/driver_v1.go +++ b/pkg/driver/driver_v1.go @@ -6,7 +6,6 @@ package driver import ( "context" "errors" - "fmt" "os" "github.com/LambdaTest/test-at-scale/pkg/core" @@ -64,8 +63,7 @@ func (d *driverV1) RunDiscovery(ctx context.Context, payload *core.Payload, if tasConfig.Prerun != nil { d.logger.Infof("Running pre-run steps for top module") - blobPath := fmt.Sprintf("%s/%s/%s/%s.log", payload.OrgID, payload.BuildID, os.Getenv("TASK_ID"), core.PreRun) - azureLogWriter := logwriter.NewAzureLogWriter(d.AzureClient, blobPath, d.logger) + azureLogWriter := logwriter.NewAzureLogWriter(d.AzureClient, core.PurposePreRunLogs, d.logger) err = d.ExecutionManager.ExecuteUserCommands(ctx, core.PreRun, payload, tasConfig.Prerun, secretMap, azureLogWriter, global.RepoDir) if err != nil { d.logger.Errorf("Unable to run pre-run steps %v", err) @@ -149,8 +147,7 @@ func (d *driverV1) RunExecution(ctx context.Context, payload *core.Payload, } taskPayload.Status = resp.TaskStatus - blobPath := fmt.Sprintf("%s/%s/%s/%s.log", payload.OrgID, payload.BuildID, os.Getenv("TASK_ID"), core.PostRun) - logWriter := logwriter.NewAzureLogWriter(d.AzureClient, blobPath, d.logger) + logWriter := logwriter.NewAzureLogWriter(d.AzureClient, core.PurposePostRunLogs, d.logger) if tasConfig.Postrun != nil { d.logger.Infof("Running post-run steps") @@ -170,7 +167,7 @@ func (d *driverV1) setUp(ctx context.Context, payload *core.Payload, cacheKey := "" if language == languageJs { - cacheKey = fmt.Sprintf("%s/%s/%s/%s", tasConfig.Cache.Version, payload.OrgID, payload.RepoID, tasConfig.Cache.Key) + cacheKey = tasConfig.Cache.Key } os.Setenv("REPO_CACHE_DIR", global.RepoCacheDir) @@ -251,8 +248,7 @@ func (d *driverV1) buildTestExecutionArgs(payload *core.Payload, tasConfig *core secretMap map[string]string, coverageDir string) core.TestExecutionArgs { testPattern, envMap := d.getEnvAndPattern(payload, tasConfig) - blobPath := fmt.Sprintf("%s/%s/%s/%s.log", payload.OrgID, payload.BuildID, payload.TaskID, core.Execution) - logWriter := logwriter.NewAzureLogWriter(d.AzureClient, blobPath, d.logger) + logWriter := logwriter.NewAzureLogWriter(d.AzureClient, core.PurposeExecutionLogs, d.logger) return core.TestExecutionArgs{ Payload: payload, CoverageDir: coverageDir, diff --git a/pkg/driver/driver_v2.go b/pkg/driver/driver_v2.go index 1ef186d2..bb716abb 100644 --- a/pkg/driver/driver_v2.go +++ b/pkg/driver/driver_v2.go @@ -7,7 +7,6 @@ import ( "bytes" "context" "errors" - "fmt" "os" "path" "strings" @@ -63,11 +62,9 @@ func (d *driverV2) RunDiscovery(ctx context.Context, payload *core.Payload, return err } mainBuffer := new(bytes.Buffer) - blobPath := fmt.Sprintf("%s/%s/%s/%s.log", payload.OrgID, payload.BuildID, os.Getenv("TASK_ID"), core.PreRun) - azureLogWriter := logwriter.NewAzureLogWriter(d.AzureClient, blobPath, d.logger) + azureLogWriter := logwriter.NewAzureLogWriter(d.AzureClient, core.PurposePreRunLogs, d.logger) defer func() { - d.logger.Debugf("Writing the preRUN logs to path %s", blobPath) if writeErr := <-azureLogWriter.Write(ctx, mainBuffer); writeErr != nil { // error in writing log should not fail the build d.logger.Errorf("error in writing pre run log, error %v", writeErr) @@ -140,9 +137,7 @@ func (d *driverV2) RunExecution(ctx context.Context, payload *core.Payload, if subModule.Postrun != nil { d.logger.Infof("Running post-run steps") - blobPath := fmt.Sprintf("%s/%s/%s/%s.log", payload.OrgID, payload.BuildID, os.Getenv("TASK_ID"), core.PostRun) - - azureLogwriter := logwriter.NewAzureLogWriter(d.AzureClient, blobPath, d.logger) + azureLogwriter := logwriter.NewAzureLogWriter(d.AzureClient, core.PurposePostRunLogs, d.logger) err = d.ExecutionManager.ExecuteUserCommands(ctx, core.PostRun, payload, subModule.Postrun, secretMap, azureLogwriter, modulePath) if err != nil { @@ -169,9 +164,7 @@ func (d *driverV2) runPreRunBeforeTestExecution(ctx context.Context, } d.logger.Infof("Running pre-run steps for submodule %s", subModule.Name) - blobPath := fmt.Sprintf("%s/%s/%s/%s.log", payload.OrgID, payload.BuildID, os.Getenv("TASK_ID"), core.PreRun) - - azureLogwriter := logwriter.NewAzureLogWriter(d.AzureClient, blobPath, d.logger) + azureLogwriter := logwriter.NewAzureLogWriter(d.AzureClient, core.PurposePreRunLogs, d.logger) err := d.ExecutionManager.ExecuteUserCommands(ctx, core.PreRun, payload, subModule.Prerun, secretMap, azureLogwriter, modulePath) if err != nil { d.logger.Errorf("Unable to run pre-run steps %v", err) @@ -362,7 +355,7 @@ func (d *driverV2) setUpDiscovery(ctx context.Context, payload *core.Payload, tasConfig *core.TASConfigV2, oauth *core.Oauth) (*setUpResultV2, error) { - cacheKey := fmt.Sprintf("%s/%s/%s/%s", tasConfig.Cache.Version, payload.OrgID, payload.RepoID, tasConfig.Cache.Key) + cacheKey := tasConfig.Cache.Key g, errCtx := errgroup.WithContext(ctx) g.Go(func() error { @@ -479,11 +472,10 @@ func (d *driverV2) buildTestExecutionArgs(payload *core.Payload, secretMap map[string]string, coverageDir string) core.TestExecutionArgs { target := subModule.Patterns - blobPath := fmt.Sprintf("%s/%s/%s/%s.log", payload.OrgID, payload.BuildID, os.Getenv("TASK_ID"), core.Execution) envMap := getEnv(payload, tasConfig, subModule) modulePath := path.Join(global.RepoDir, subModule.Path) - azureLogWriter := logwriter.NewAzureLogWriter(d.AzureClient, blobPath, d.logger) + azureLogWriter := logwriter.NewAzureLogWriter(d.AzureClient, core.PurposeExecutionLogs, d.logger) return core.TestExecutionArgs{ Payload: payload, CoverageDir: coverageDir, diff --git a/pkg/gitmanager/setup_test.go b/pkg/gitmanager/setup_test.go index 55ff46b8..dc0e4f10 100644 --- a/pkg/gitmanager/setup_test.go +++ b/pkg/gitmanager/setup_test.go @@ -12,12 +12,12 @@ import ( "strings" "testing" + "github.com/LambdaTest/test-at-scale/mocks" "github.com/LambdaTest/test-at-scale/pkg/command" "github.com/LambdaTest/test-at-scale/pkg/core" "github.com/LambdaTest/test-at-scale/pkg/global" "github.com/LambdaTest/test-at-scale/pkg/lumber" "github.com/LambdaTest/test-at-scale/testutils" - "github.com/LambdaTest/test-at-scale/testutils/mocks" "github.com/stretchr/testify/mock" ) diff --git a/pkg/global/nucleusconstants.go b/pkg/global/nucleusconstants.go index 33297260..ec529d26 100644 --- a/pkg/global/nucleusconstants.go +++ b/pkg/global/nucleusconstants.go @@ -29,7 +29,6 @@ const ( ExpiryDelta = 15 * time.Minute NewTASVersion = 2 ModulePath = "MODULE_PATH" - CacheVersion = "v1" PackageJSON = "package.json" SubModuleName = "SUBMODULE_NAME" ArgPattern = "--pattern" diff --git a/pkg/listsubmoduleservice/setup.go b/pkg/listsubmoduleservice/setup.go index a5bf9ef2..5ff3a0aa 100644 --- a/pkg/listsubmoduleservice/setup.go +++ b/pkg/listsubmoduleservice/setup.go @@ -3,9 +3,7 @@ package listsubmoduleservice import ( "context" "encoding/json" - "fmt" "net/http" - "os" "github.com/LambdaTest/test-at-scale/pkg/core" "github.com/LambdaTest/test-at-scale/pkg/global" @@ -37,12 +35,9 @@ func (s *subModuleListService) Send(ctx context.Context, buildID string, totalSu s.logger.Errorf("error while json marshal %v", err) return err } - params := utils.FetchQueryParams() - headers := map[string]string{ - "Authorization": fmt.Sprintf("%s %s", "Bearer", os.Getenv("TOKEN")), - } + query, headers := utils.GetDefaultQueryAndHeaders() if _, statusCode, err := s.requests.MakeAPIRequest(ctx, http.MethodPost, s.subModuleListEndpoint, - reqBody, params, headers); err != nil || statusCode != 200 { + reqBody, query, headers); err != nil || statusCode != 200 { s.logger.Errorf("error while making submodule-list api call status code %d, err %v", statusCode, err) return err } diff --git a/pkg/logwriter/setup.go b/pkg/logwriter/setup.go index e4ad5760..37896cc5 100644 --- a/pkg/logwriter/setup.go +++ b/pkg/logwriter/setup.go @@ -19,17 +19,17 @@ type ( AzureLogWriter struct { azureClient core.AzureClient - blobPath string + purpose core.SASURLPurpose logger lumber.Logger } ) func NewAzureLogWriter(azureClient core.AzureClient, - blobPath string, + purpose core.SASURLPurpose, logger lumber.Logger) core.LogWriterStrategy { return &AzureLogWriter{ azureClient: azureClient, - blobPath: blobPath, + purpose: purpose, logger: logger, } } @@ -66,9 +66,9 @@ func (b *BufferLogWriter) Write(ctx context.Context, reader io.Reader) <-chan er func (a *AzureLogWriter) Write(ctx context.Context, reader io.Reader) <-chan error { errChan := make(chan error, 1) go func() { - sasURL, err := a.azureClient.GetSASURL(ctx, a.blobPath, core.LogsContainer) + sasURL, err := a.azureClient.GetSASURL(ctx, a.purpose, nil) if err != nil { - a.logger.Errorf("failed to genereate SAS URL for path %s, error: %v", a.blobPath, err) + a.logger.Errorf("failed to genereate SAS URL for purpose %s, error: %v", a.purpose, err) errChan <- err return } diff --git a/pkg/logwriter/setup_test.go b/pkg/logwriter/setup_test.go index ba7a1053..6a18101f 100644 --- a/pkg/logwriter/setup_test.go +++ b/pkg/logwriter/setup_test.go @@ -3,12 +3,13 @@ package logwriter import ( "context" "io" + "strings" "testing" + "github.com/LambdaTest/test-at-scale/mocks" "github.com/LambdaTest/test-at-scale/pkg/core" "github.com/LambdaTest/test-at-scale/pkg/errs" "github.com/LambdaTest/test-at-scale/testutils" - "github.com/LambdaTest/test-at-scale/testutils/mocks" "github.com/stretchr/testify/mock" ) @@ -57,7 +58,7 @@ func Test_azure_write_logger_strategy(t *testing.T) { args{ ctx: context.TODO(), blobPath: "blobpath", - reader: &mocks.Reader{}, + reader: &strings.Reader{}, }, errGetSASURL, true, @@ -69,7 +70,7 @@ func Test_azure_write_logger_strategy(t *testing.T) { args{ ctx: context.TODO(), blobPath: "blobpath", - reader: &mocks.Reader{}, + reader: &strings.Reader{}, }, errCreateUsingSASURL, true, @@ -81,7 +82,7 @@ func Test_azure_write_logger_strategy(t *testing.T) { args{ ctx: context.TODO(), blobPath: "blobpath", - reader: &mocks.Reader{}, + reader: &strings.Reader{}, }, errSuccess, false, @@ -94,7 +95,7 @@ func Test_azure_write_logger_strategy(t *testing.T) { t.Run(tt.name, func(t *testing.T) { m := &AzureLogWriter{ logger: logger, - blobPath: tt.args.blobPath, + purpose: core.PurposeCache, azureClient: tt.fields.azureClient, } got := m.Write(tt.args.ctx, tt.args.reader) @@ -114,12 +115,13 @@ func Test_azure_write_logger_strategy(t *testing.T) { } func mockUtil(azureClient *mocks.AzureClient, msgGet, msgCreate, errGet, errCreate string, wantErrGet, wantErrCreate bool) { + var x map[string]interface{} azureClient.On("GetSASURL", mock.AnythingOfType("*context.emptyCtx"), - mock.AnythingOfType("string"), mock.AnythingOfType("core.ContainerType")).Return( - func(ctx context.Context, containerPath string, containerType core.ContainerType) string { + mock.AnythingOfType("core.SASURLPurpose"), x).Return( + func(ctx context.Context, purpose core.SASURLPurpose, data map[string]interface{}) string { return msgGet }, - func(ctx context.Context, containerPath string, containerType core.ContainerType) error { + func(ctx context.Context, purpose core.SASURLPurpose, data map[string]interface{}) error { if !wantErrGet { return nil } @@ -127,7 +129,7 @@ func mockUtil(azureClient *mocks.AzureClient, msgGet, msgCreate, errGet, errCrea }) azureClient.On("CreateUsingSASURL", mock.AnythingOfType("*context.emptyCtx"), - mock.AnythingOfType("string"), mock.AnythingOfType("*mocks.Reader"), "text/plain").Return( + mock.AnythingOfType("string"), mock.AnythingOfType("*strings.Reader"), "text/plain").Return( func(ctx context.Context, sasURL string, reader io.Reader, mimeType string) string { return msgCreate }, diff --git a/pkg/payloadmanager/setup.go b/pkg/payloadmanager/setup.go index f8d63b76..05e916da 100644 --- a/pkg/payloadmanager/setup.go +++ b/pkg/payloadmanager/setup.go @@ -4,11 +4,7 @@ package payloadmanager import ( "context" "encoding/json" - "errors" - "fmt" "net/http" - "net/url" - "strings" "github.com/LambdaTest/test-at-scale/config" "github.com/LambdaTest/test-at-scale/pkg/core" @@ -36,23 +32,7 @@ func NewPayloadManger(azureClient core.AzureClient, } func (pm *payloadManager) FetchPayload(ctx context.Context, payloadAddress string) (*core.Payload, error) { - if payloadAddress == "" { - return nil, errors.New("invalid payload address") - } - - u, err := url.Parse(payloadAddress) - if err != nil { - return nil, err - } - // string the container name to get blob path - blobPath := strings.Replace(u.Path, fmt.Sprintf("/%s/", core.PayloadContainer), "", -1) - - sasURL, err := pm.azureClient.GetSASURL(ctx, blobPath, core.PayloadContainer) - if err != nil { - return nil, err - } - - rawBytes, _, err := pm.requests.MakeAPIRequest(ctx, http.MethodGet, sasURL, nil, nil, nil) + rawBytes, _, err := pm.requests.MakeAPIRequest(ctx, http.MethodGet, payloadAddress, nil, nil, nil) if err != nil { return nil, err } diff --git a/pkg/payloadmanager/setup_test.go b/pkg/payloadmanager/setup_test.go index 2fea0e40..ee362cfb 100644 --- a/pkg/payloadmanager/setup_test.go +++ b/pkg/payloadmanager/setup_test.go @@ -11,14 +11,13 @@ import ( "testing" "github.com/LambdaTest/test-at-scale/config" + "github.com/LambdaTest/test-at-scale/mocks" "github.com/LambdaTest/test-at-scale/pkg/core" "github.com/LambdaTest/test-at-scale/pkg/global" "github.com/LambdaTest/test-at-scale/pkg/lumber" "github.com/LambdaTest/test-at-scale/pkg/requestutils" "github.com/LambdaTest/test-at-scale/testutils" - "github.com/LambdaTest/test-at-scale/testutils/mocks" "github.com/cenkalti/backoff/v4" - "github.com/stretchr/testify/mock" ) type validatePayloadArgs struct { @@ -66,16 +65,7 @@ func Test_payloadManager_FetchPayload(t *testing.T) { t.Errorf("Couldn't get config, received: %s", err) } - ct := core.PayloadContainer azureClient := new(mocks.AzureClient) - azureClient.On("GetSASURL", mock.AnythingOfType("*context.emptyCtx"), "/index.txt", ct).Return( - func(ctc context.Context, blobPath string, containerType core.ContainerType) string { - return server.URL + "/index.txt" - }, - func(ctc context.Context, blobPath string, containerType core.ContainerType) error { - return nil - }, - ) wantResp, err := os.ReadFile("../../testutils/testdata/index.json") if err != nil { diff --git a/pkg/requestutils/request.go b/pkg/requestutils/request.go index 430d6246..895a2f00 100644 --- a/pkg/requestutils/request.go +++ b/pkg/requestutils/request.go @@ -8,6 +8,7 @@ import ( "io" "net/http" "net/url" + "reflect" "time" "github.com/LambdaTest/test-at-scale/pkg/core" @@ -33,7 +34,8 @@ func (r *requests) MakeAPIRequest( ctx context.Context, httpMethod, endpoint string, body []byte, - params, headers map[string]string, + query map[string]interface{}, + headers map[string]string, ) (respBody []byte, statusCode int, err error) { u, err := url.Parse(endpoint) if err != nil { @@ -41,8 +43,18 @@ func (r *requests) MakeAPIRequest( return nil, 0, err } q := u.Query() - for id, val := range params { - q.Set(id, val) + for id, val := range query { + v := reflect.ValueOf(val) + // nolint:exhaustive + switch v.Kind() { + case reflect.Array: + case reflect.Slice: + for i := 0; i < v.Len(); i += 1 { + q.Add(id, v.Index(i).String()) + } + default: + q.Set(id, fmt.Sprintf("%v", val)) + } } u.RawQuery = q.Encode() req, err := http.NewRequestWithContext(ctx, httpMethod, u.String(), bytes.NewBuffer(body)) diff --git a/pkg/runner/docker/config.go b/pkg/runner/docker/config.go index ea333446..ac0bb73c 100644 --- a/pkg/runner/docker/config.go +++ b/pkg/runner/docker/config.go @@ -15,18 +15,16 @@ import ( "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/network" + "github.com/docker/go-units" ) const ( defaultVaultPath = "/vault/secrets" repoSourcePath = "/tmp/synapse/%s/nucleus" nanoCPUUnit = 1e9 - // GB defines number of bytes in 1 GB - GB int64 = 1e+9 ) func (d *docker) getContainerConfiguration(r *core.RunnerOptions) *container.Config { - return &container.Config{ Image: r.DockerImage, Env: r.Env, @@ -37,7 +35,7 @@ func (d *docker) getContainerConfiguration(r *core.RunnerOptions) *container.Con } func (d *docker) getContainerHostConfiguration(r *core.RunnerOptions) *container.HostConfig { - specs := getSpces(r.Tier) + specs := getSpecs(r.Tier) /* https://pkg.go.dev/github.com/docker/docker@v20.10.12+incompatible/api/types/container#Resources AS per documentation , 1 core = 1e9 NanoCPUs @@ -66,14 +64,13 @@ func (d *docker) getContainerHostConfiguration(r *core.RunnerOptions) *container Mounts: mounts, AutoRemove: true, SecurityOpt: []string{"seccomp=unconfined"}, - Resources: container.Resources{Memory: specs.RAM * GB, NanoCPUs: nanoCPU}, + Resources: container.Resources{Memory: specs.RAM * units.MiB, NanoCPUs: nanoCPU}, } autoRemove, err := strconv.ParseBool(os.Getenv(global.AutoRemoveEnv)) if err != nil { d.logger.Errorf("Error reading os env AutoRemove with error: %v \n returning default host config", err) return &hostConfig - } hostConfig.AutoRemove = autoRemove return &hostConfig @@ -88,9 +85,9 @@ func (d *docker) getContainerNetworkConfiguration() (*network.NetworkingConfig, if err != nil { return nil, err } - for _, network := range networkList { - if network.Name == networkName { - networkResource = network + for idx := 0; idx < len(networkList); idx += 1 { + if networkList[idx].Name == networkName { + networkResource = networkList[idx] } } @@ -105,7 +102,7 @@ func (d *docker) getContainerNetworkConfiguration() (*network.NetworkingConfig, return &networkConfig, nil } -func getSpces(tier core.Tier) core.Specs { +func getSpecs(tier core.Tier) core.Specs { if val, ok := core.TierOpts[tier]; ok { return core.Specs{CPU: val.CPU, RAM: val.RAM} } diff --git a/pkg/runner/docker/docker.go b/pkg/runner/docker/docker.go index 2f65e2b6..4380a2cb 100644 --- a/pkg/runner/docker/docker.go +++ b/pkg/runner/docker/docker.go @@ -20,10 +20,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" "github.com/docker/docker/pkg/stdcopy" -) - -const ( - mb = 1048576 + "github.com/docker/go-units" ) var gracefulyContainerStopDuration = time.Second * 10 @@ -55,7 +52,7 @@ func newDockerClient(secretsManager core.SecretsManager) (*docker, error) { return &docker{ client: client, cpu: float32(dockerInfo.NCPU), - ram: dockerInfo.MemTotal / mb, + ram: dockerInfo.MemTotal / units.MiB, secretsManager: secretsManager, }, nil } @@ -87,17 +84,17 @@ func (d *docker) Create(ctx context.Context, r *core.RunnerOptions) core.Contain return containerStatus } - if err := d.PullImage(&containerImageConfig, r); err != nil { - d.logger.Errorf("Something went wrong while pulling container image %+v", err) + if errP := d.PullImage(&containerImageConfig, r); errP != nil { + d.logger.Errorf("Something went wrong while pulling container image %+v", errP) containerStatus.Done = false - containerStatus.Error = errs.ERR_DOCKER_CRT(err.Error()) + containerStatus.Error = errs.ERR_DOCKER_CRT(errP.Error()) return containerStatus } container := d.getContainerConfiguration(r) hostConfig := d.getContainerHostConfiguration(r) networkConfig, err := d.getContainerNetworkConfiguration() if err != nil { - d.logger.Errorf("error retriving network: %v", err) + d.logger.Errorf("error retreiving network: %v", err) containerStatus.Done = false containerStatus.Error = errs.ERR_DOCKER_CRT(err.Error()) return containerStatus @@ -124,7 +121,7 @@ func (d *docker) Destroy(ctx context.Context, r *core.RunnerOptions) error { autoRemove, err := strconv.ParseBool(os.Getenv(global.AutoRemoveEnv)) if err != nil { d.logger.Errorf("Error reading AutoRemove os env error: %v", err) - return errors.New("Error reading AutoRemove os env error") + return errors.New("error reading AutoRemove os env error") } if autoRemove { // if autoRemove is set then it docker container will be removed once it stopped or exited @@ -196,21 +193,19 @@ func (d *docker) WaitForCompletion(ctx context.Context, r *core.RunnerOptions) e if status.StatusCode != 0 { msg := fmt.Sprintf("Received non zero status code %v", status.StatusCode) return errs.ERR_DOCKER_RUN(msg) - } return nil } return nil } -func (d *docker) GetInfo(ctx context.Context) (float32, int64) { +func (d *docker) GetInfo(ctx context.Context) (cpu float32, ram int64) { return d.cpu, d.ram } func (d *docker) Initiate(ctx context.Context, r *core.RunnerOptions, statusChan chan core.ContainerStatus) { // creating the docker contaienr - r.ContainerArgs = append(r.ContainerArgs, "--local", os.Getenv(global.LocalEnv)) - r.ContainerArgs = append(r.ContainerArgs, "--synapsehost", os.Getenv(global.SynapseHostEnv)) + r.ContainerArgs = append(r.ContainerArgs, "--local", os.Getenv(global.LocalEnv), "--synapsehost", os.Getenv(global.SynapseHostEnv)) if status := d.Create(ctx, r); !status.Done { d.logger.Errorf("error creating container: %v", status.Error) d.logger.Infof("Update error status after creation") @@ -265,8 +260,8 @@ func (d *docker) PullImage(containerImageConfig *core.ContainerImageConfig, r *c d.logger.Errorf("Reader returned by docker pull is null") return } - if err := reader.Close(); err != nil { - d.logger.Errorf(err.Error()) + if errC := reader.Close(); errC != nil { + d.logger.Errorf(errC.Error()) } }() diff --git a/pkg/service/coverage/coverage_test.go b/pkg/service/coverage/coverage_test.go index 1b70a8c0..a960fe47 100644 --- a/pkg/service/coverage/coverage_test.go +++ b/pkg/service/coverage/coverage_test.go @@ -12,11 +12,11 @@ import ( "reflect" "testing" + "github.com/LambdaTest/test-at-scale/mocks" "github.com/LambdaTest/test-at-scale/pkg/core" "github.com/LambdaTest/test-at-scale/pkg/global" "github.com/LambdaTest/test-at-scale/pkg/lumber" "github.com/LambdaTest/test-at-scale/testutils" - "github.com/LambdaTest/test-at-scale/testutils/mocks" "github.com/stretchr/testify/mock" ) diff --git a/pkg/tasconfigmanager/setup.go b/pkg/tasconfigmanager/setup.go index 1b357877..fe309842 100644 --- a/pkg/tasconfigmanager/setup.go +++ b/pkg/tasconfigmanager/setup.go @@ -100,9 +100,8 @@ func (tc *tasConfigManager) validateYMLV1(ctx context.Context, return nil, err } tasConfig.Cache = &core.Cache{ - Key: checksum, - Paths: []string{}, - Version: global.CacheVersion, + Key: checksum, + Paths: []string{}, } } return tasConfig, nil diff --git a/pkg/task/task.go b/pkg/task/task.go index a8020b34..e66502f5 100644 --- a/pkg/task/task.go +++ b/pkg/task/task.go @@ -3,9 +3,7 @@ package task import ( "context" "encoding/json" - "fmt" "net/http" - "os" "github.com/LambdaTest/test-at-scale/pkg/core" "github.com/LambdaTest/test-at-scale/pkg/global" @@ -36,11 +34,8 @@ func (t *task) UpdateStatus(ctx context.Context, payload *core.TaskPayload) erro t.logger.Errorf("error while json marshal %v", err) return err } - params := utils.FetchQueryParams() - headers := map[string]string{ - "Authorization": fmt.Sprintf("%s %s", "Bearer", os.Getenv("TOKEN")), - } - if _, _, err := t.requests.MakeAPIRequest(ctx, http.MethodPut, t.endpoint, reqBody, params, headers); err != nil { + query, headers := utils.GetDefaultQueryAndHeaders() + if _, _, err := t.requests.MakeAPIRequest(ctx, http.MethodPut, t.endpoint, reqBody, query, headers); err != nil { return err } diff --git a/pkg/testdiscoveryservice/testdiscovery.go b/pkg/testdiscoveryservice/testdiscovery.go index b3ace728..b51660bf 100644 --- a/pkg/testdiscoveryservice/testdiscovery.go +++ b/pkg/testdiscoveryservice/testdiscovery.go @@ -4,9 +4,7 @@ package testdiscoveryservice import ( "context" "encoding/json" - "fmt" "net/http" - "os" "os/exec" "strings" @@ -109,11 +107,8 @@ func (tds *testDiscoveryService) SendResult(ctx context.Context, testDiscoveryRe tds.logger.Errorf("error while json marshal %v", err) return err } - params := utils.FetchQueryParams() - headers := map[string]string{ - "Authorization": fmt.Sprintf("%s %s", "Bearer", os.Getenv("TOKEN")), - } - if _, _, err := tds.requests.MakeAPIRequest(ctx, http.MethodPost, tds.discoveryEndpoint, reqBody, params, headers); err != nil { + query, headers := utils.GetDefaultQueryAndHeaders() + if _, _, err := tds.requests.MakeAPIRequest(ctx, http.MethodPost, tds.discoveryEndpoint, reqBody, query, headers); err != nil { return err } diff --git a/pkg/testdiscoveryservice/testdiscovery_test.go b/pkg/testdiscoveryservice/testdiscovery_test.go index d6f581b8..3ffec2a2 100644 --- a/pkg/testdiscoveryservice/testdiscovery_test.go +++ b/pkg/testdiscoveryservice/testdiscovery_test.go @@ -6,11 +6,11 @@ import ( "reflect" "testing" + "github.com/LambdaTest/test-at-scale/mocks" "github.com/LambdaTest/test-at-scale/pkg/core" "github.com/LambdaTest/test-at-scale/pkg/global" "github.com/LambdaTest/test-at-scale/pkg/requestutils" "github.com/LambdaTest/test-at-scale/testutils" - "github.com/LambdaTest/test-at-scale/testutils/mocks" "github.com/cenkalti/backoff/v4" "github.com/stretchr/testify/mock" ) diff --git a/pkg/testexecutionservice/testexecution.go b/pkg/testexecutionservice/testexecution.go index ec03e6d9..d31c74ad 100644 --- a/pkg/testexecutionservice/testexecution.go +++ b/pkg/testexecutionservice/testexecution.go @@ -5,14 +5,11 @@ import ( "context" "encoding/json" "errors" - "fmt" "io" "net/http" - "net/url" "os" "os/exec" "path/filepath" - "strings" "github.com/LambdaTest/test-at-scale/config" "github.com/LambdaTest/test-at-scale/pkg/core" @@ -151,11 +148,8 @@ func (tes *testExecutionService) SendResults(ctx context.Context, tes.logger.Errorf("failed to marshal request body %v", err) return nil, err } - params := utils.FetchQueryParams() - headers := map[string]string{ - "Authorization": fmt.Sprintf("%s %s", "Bearer", os.Getenv("TOKEN")), - } - respBody, _, err := tes.requests.MakeAPIRequest(ctx, http.MethodPost, tes.serverEndpoint, reqBody, params, headers) + query, headers := utils.GetDefaultQueryAndHeaders() + respBody, _, err := tes.requests.MakeAPIRequest(ctx, http.MethodPost, tes.serverEndpoint, reqBody, query, headers) if err != nil { tes.logger.Errorf("error while sending reports %v", err) return nil, err @@ -172,20 +166,9 @@ func (tes *testExecutionService) SendResults(ctx context.Context, } func (tes *testExecutionService) getLocatorsFile(ctx context.Context, locatorAddress string) (string, error) { - u, err := url.Parse(locatorAddress) - if err != nil { - return "", err - } - // string the container name to get blob path - blobPath := strings.Replace(u.Path, fmt.Sprintf("/%s/", core.PayloadContainer), "", -1) - - sasURL, err := tes.azureClient.GetSASURL(ctx, blobPath, core.PayloadContainer) - if err != nil { - return "", err - } - resp, err := tes.azureClient.FindUsingSASUrl(ctx, sasURL) + resp, err := tes.azureClient.FindUsingSASUrl(ctx, locatorAddress) if err != nil { - tes.logger.Errorf("Error while downloading cache for key: %s, error %v", u.Path, err) + tes.logger.Errorf("Error while downloading locatorFile, error %v", err) return "", err } defer resp.Close() diff --git a/pkg/testexecutionservice/testexecution_test.go b/pkg/testexecutionservice/testexecution_test.go index 1e607118..a9915814 100644 --- a/pkg/testexecutionservice/testexecution_test.go +++ b/pkg/testexecutionservice/testexecution_test.go @@ -10,13 +10,13 @@ import ( "testing" "github.com/LambdaTest/test-at-scale/config" + "github.com/LambdaTest/test-at-scale/mocks" "github.com/LambdaTest/test-at-scale/pkg/core" "github.com/LambdaTest/test-at-scale/pkg/global" "github.com/LambdaTest/test-at-scale/pkg/lumber" "github.com/LambdaTest/test-at-scale/pkg/requestutils" "github.com/LambdaTest/test-at-scale/pkg/service/teststats" "github.com/LambdaTest/test-at-scale/testutils" - "github.com/LambdaTest/test-at-scale/testutils/mocks" "github.com/cenkalti/backoff/v4" "github.com/stretchr/testify/mock" ) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 704cbaeb..fa13e390 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -231,14 +231,18 @@ func ValidateSubModule(module *core.SubModule) error { return nil } -// FetchQueryParams returns the params which are required in API -func FetchQueryParams() (params map[string]string) { - params = map[string]string{ +// GetDefaultQueryAndHeaders returns the query and headers that should be supplied with each request made to TAS Server +func GetDefaultQueryAndHeaders() (query map[string]interface{}, headers map[string]string) { + query = map[string]interface{}{ "repoID": os.Getenv("REPO_ID"), "buildID": os.Getenv("BUILD_ID"), "orgID": os.Getenv("ORG_ID"), + "taskID": os.Getenv("TASK_ID"), } - return params + headers = map[string]string{ + "Authorization": fmt.Sprintf("Bearer %s", os.Getenv("TOKEN")), + } + return query, headers } func GetArgs(command string, frameWork string, frameworkVersion int, diff --git a/pkg/zstd/zstd_test.go b/pkg/zstd/zstd_test.go index 89a6680f..a8dc0153 100644 --- a/pkg/zstd/zstd_test.go +++ b/pkg/zstd/zstd_test.go @@ -8,11 +8,11 @@ import ( "reflect" "testing" + "github.com/LambdaTest/test-at-scale/mocks" "github.com/LambdaTest/test-at-scale/pkg/core" "github.com/LambdaTest/test-at-scale/pkg/errs" "github.com/LambdaTest/test-at-scale/pkg/lumber" "github.com/LambdaTest/test-at-scale/testutils" - "github.com/LambdaTest/test-at-scale/testutils/mocks" "github.com/stretchr/testify/mock" ) diff --git a/testutils/mocks/Reader.go b/testutils/mocks/Reader.go deleted file mode 100644 index 98ec246f..00000000 --- a/testutils/mocks/Reader.go +++ /dev/null @@ -1,31 +0,0 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. - -package mocks - -import mock "github.com/stretchr/testify/mock" - -// Reader is an autogenerated mock type for the Reader type -type Reader struct { - mock.Mock -} - -// Read provides a mock function with given fields: p -func (_m *Reader) Read(p []byte) (int, error) { - ret := _m.Called(p) - - var r0 int - if rf, ok := ret.Get(0).(func([]byte) int); ok { - r0 = rf(p) - } else { - r0 = ret.Get(0).(int) - } - - var r1 error - if rf, ok := ret.Get(1).(func([]byte) error); ok { - r1 = rf(p) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -}