Skip to content

Commit

Permalink
fix: new cloud methods
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Jul 25, 2024
1 parent 16b8cb2 commit 251a8da
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/cloud/data/testresult/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
13 changes: 11 additions & 2 deletions pkg/cloud/data/testresult/testresult.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions pkg/cloud/data/testresult/testresult_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
23 changes: 23 additions & 0 deletions pkg/cloud/data/testresult/testresult_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 3 additions & 0 deletions pkg/cloud/data/testworkflow/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -65,6 +66,8 @@ func command(v interface{}) executor.Command {
return CmdTestWorkflowExecutionDeleteByWorkflows
case ExecutionGetWorkflowMetricsRequest:
return CmdTestWorkflowExecutionGetWorkflowMetrics
case ExecutionGetNextExecutionNumberRequest:
return CmdTestWorkflowExecutionGetNextExecutionNumber

case OutputPresignSaveLogRequest:
return CmdTestWorkflowOutputPresignSaveLog
Expand Down
13 changes: 11 additions & 2 deletions pkg/cloud/data/testworkflow/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions pkg/cloud/data/testworkflow/execution_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,11 @@ type ExecutionsAddReportRequest struct {
}

type ExecutionsAddReportResponse struct{}

type ExecutionGetNextExecutionNumberRequest struct {
TestWorkflowName string `json:"testWorkflowName"`
}

type ExecutionGetNextExecutionNumberResponse struct {
TestWorkflowNumber int32 `json:"testWorkflowNumber"`
}

0 comments on commit 251a8da

Please sign in to comment.