From 251a8dab4f7a352c7a0b0a0b4a903a3582511391 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Thu, 25 Jul 2024 19:40:43 +0300 Subject: [PATCH] fix: new cloud methods Signed-off-by: Vladislav Sukhin --- pkg/cloud/data/testresult/commands.go | 1 + pkg/cloud/data/testresult/testresult.go | 13 +++++++++-- .../data/testresult/testresult_models.go | 8 +++++++ pkg/cloud/data/testresult/testresult_test.go | 23 +++++++++++++++++++ pkg/cloud/data/testworkflow/commands.go | 3 +++ pkg/cloud/data/testworkflow/execution.go | 13 +++++++++-- .../data/testworkflow/execution_models.go | 8 +++++++ 7 files changed, 65 insertions(+), 4 deletions(-) diff --git a/pkg/cloud/data/testresult/commands.go b/pkg/cloud/data/testresult/commands.go index 1133385049a..4b2d1a87607 100644 --- a/pkg/cloud/data/testresult/commands.go +++ b/pkg/cloud/data/testresult/commands.go @@ -18,4 +18,5 @@ const ( CmdTestResultDeleteAll executor.Command = "test_result_delete_all" CmdTestResultDeleteByTestSuites executor.Command = "test_result_delete_by_test_suites" CmdTestResultGetTestSuiteMetrics executor.Command = "test_result_get_test_suite_metrics" + CmdTestResultGetNextExecutionNumber executor.Command = "test_result_get_next_execution_number" ) diff --git a/pkg/cloud/data/testresult/testresult.go b/pkg/cloud/data/testresult/testresult.go index 71e79908530..9f5c5cd4ba5 100644 --- a/pkg/cloud/data/testresult/testresult.go +++ b/pkg/cloud/data/testresult/testresult.go @@ -253,6 +253,15 @@ func (r *CloudRepository) GetPreviousFinishedState(ctx context.Context, testSuit return commandResponse.Result, nil } -func (r *CloudRepository) GetNextExecutionNumber(ctx context.Context, name string) (number int32, err error) { - return 0, nil +func (r *CloudRepository) GetNextExecutionNumber(ctx context.Context, testSuiteName string) (number int32, err error) { + req := NextExecutionNumberRequest{TestSuiteName: testSuiteName} + response, err := r.executor.Execute(ctx, CmdTestResultGetNextExecutionNumber, req) + if err != nil { + return 0, err + } + var commandResponse NextExecutionNumberResponse + if err := json.Unmarshal(response, &commandResponse); err != nil { + return 0, err + } + return commandResponse.TestSuiteNumber, nil } diff --git a/pkg/cloud/data/testresult/testresult_models.go b/pkg/cloud/data/testresult/testresult_models.go index 5f3379f52d9..5c87e25ce4c 100644 --- a/pkg/cloud/data/testresult/testresult_models.go +++ b/pkg/cloud/data/testresult/testresult_models.go @@ -118,3 +118,11 @@ type GetTestSuiteMetricsRequest struct { type GetTestSuiteMetricsResponse struct { Metrics testkube.ExecutionsMetrics `json:"metrics"` } + +type NextExecutionNumberRequest struct { + TestSuiteName string `json:"testSuiteName"` +} + +type NextExecutionNumberResponse struct { + TestSuiteNumber int32 `json:"testSuiteNumber"` +} diff --git a/pkg/cloud/data/testresult/testresult_test.go b/pkg/cloud/data/testresult/testresult_test.go index 8eedd613dce..8ad878b3b25 100644 --- a/pkg/cloud/data/testresult/testresult_test.go +++ b/pkg/cloud/data/testresult/testresult_test.go @@ -124,3 +124,26 @@ func TestCloudResultRepository_GetPreviousFinishedState(t *testing.T) { assert.NoError(t, err) assert.Equal(t, *expectedStatus, status) } + +func TestCloudResultRepository_GetNextExecutionNumber(t *testing.T) { + t.Parallel() + + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + mockExecutor := executor.NewMockExecutor(ctrl) + + testSuiteName := "testsuite-1" + var testSuiteNumber int32 = 3 + + // Setup expectations for the mockedExecutor.Execute method + expectedReq := NextExecutionNumberRequest{TestSuiteName: testSuiteName} + expectedResponse, _ := json.Marshal(&NextExecutionNumberResponse{TestSuiteNumber: testSuiteNumber}) + mockExecutor.EXPECT().Execute(gomock.Any(), CmdTestResultGetNextExecutionNumber, expectedReq).Return(expectedResponse, nil) + + r := &CloudRepository{executor: mockExecutor} + + result, err := r.GetNextExecutionNumber(ctx, testSuiteName) + assert.NoError(t, err) + assert.Equal(t, testSuiteNumber, result) +} diff --git a/pkg/cloud/data/testworkflow/commands.go b/pkg/cloud/data/testworkflow/commands.go index 73d5c8c7beb..fa2291483bc 100644 --- a/pkg/cloud/data/testworkflow/commands.go +++ b/pkg/cloud/data/testworkflow/commands.go @@ -21,6 +21,7 @@ const ( CmdTestWorkflowExecutionDeleteAll executor.Command = "workflow_execution_delete_all" CmdTestWorkflowExecutionDeleteByWorkflows executor.Command = "workflow_execution_delete_by_workflows" CmdTestWorkflowExecutionGetWorkflowMetrics executor.Command = "workflow_execution_get_workflow_metrics" + CmdTestWorkflowExecutionGetNextExecutionNumber executor.Command = "workflow_execution_get_next_execution_number" CmdTestWorkflowOutputPresignSaveLog executor.Command = "workflow_output_presign_save_log" CmdTestWorkflowOutputPresignReadLog executor.Command = "workflow_output_presign_read_log" @@ -65,6 +66,8 @@ func command(v interface{}) executor.Command { return CmdTestWorkflowExecutionDeleteByWorkflows case ExecutionGetWorkflowMetricsRequest: return CmdTestWorkflowExecutionGetWorkflowMetrics + case ExecutionGetNextExecutionNumberRequest: + return CmdTestWorkflowExecutionGetNextExecutionNumber case OutputPresignSaveLogRequest: return CmdTestWorkflowOutputPresignSaveLog diff --git a/pkg/cloud/data/testworkflow/execution.go b/pkg/cloud/data/testworkflow/execution.go index 69a0eba3762..a0dd8b69d0b 100644 --- a/pkg/cloud/data/testworkflow/execution.go +++ b/pkg/cloud/data/testworkflow/execution.go @@ -157,6 +157,15 @@ func (r *CloudRepository) GetPreviousFinishedState(ctx context.Context, workflow return commandResponse.Result, nil } -func (r *CloudRepository) GetNextExecutionNumber(ctx context.Context, name string) (number int32, err error) { - return 0, nil +func (r *CloudRepository) GetNextExecutionNumber(ctx context.Context, testWorkflowName string) (number int32, err error) { + req := ExecutionGetNextExecutionNumberRequest{TestWorkflowName: testWorkflowName} + response, err := r.executor.Execute(ctx, CmdTestWorkflowExecutionGetNextExecutionNumber, req) + if err != nil { + return 0, err + } + var commandResponse ExecutionGetNextExecutionNumberResponse + if err := json.Unmarshal(response, &commandResponse); err != nil { + return 0, err + } + return commandResponse.TestWorkflowNumber, nil } diff --git a/pkg/cloud/data/testworkflow/execution_models.go b/pkg/cloud/data/testworkflow/execution_models.go index 01eea60feb9..25834ad6de8 100644 --- a/pkg/cloud/data/testworkflow/execution_models.go +++ b/pkg/cloud/data/testworkflow/execution_models.go @@ -170,3 +170,11 @@ type ExecutionsAddReportRequest struct { } type ExecutionsAddReportResponse struct{} + +type ExecutionGetNextExecutionNumberRequest struct { + TestWorkflowName string `json:"testWorkflowName"` +} + +type ExecutionGetNextExecutionNumberResponse struct { + TestWorkflowNumber int32 `json:"testWorkflowNumber"` +}