github.com/kubeshop/testkube@v1.17.23/pkg/mapper/testsuiteexecutions/summary.go (about) 1 package testsuiteexecutions 2 3 import "github.com/kubeshop/testkube/pkg/api/v1/testkube" 4 5 // MapToSummary maps testkube.TestSuiteExecution to testkube.TestSuiteExecutionSummary for lists without so many details. 6 func MapToSummary(execution *testkube.TestSuiteExecution) *testkube.TestSuiteExecutionSummary { 7 var testSuiteName string 8 if execution.TestSuite != nil { 9 testSuiteName = execution.TestSuite.Name 10 } 11 12 var summary []testkube.TestSuiteBatchStepExecutionSummary 13 14 if len(execution.StepResults) != 0 { 15 summary = make([]testkube.TestSuiteBatchStepExecutionSummary, len(execution.StepResults)) 16 for i, step := range execution.StepResults { 17 summary[i] = testkube.TestSuiteBatchStepExecutionSummary{ 18 Execute: []testkube.TestSuiteStepExecutionSummary{ 19 mapStepExecutionResultV2ToExecutionSummary(step), 20 }, 21 } 22 } 23 } 24 25 if len(execution.ExecuteStepResults) != 0 { 26 summary = make([]testkube.TestSuiteBatchStepExecutionSummary, len(execution.ExecuteStepResults)) 27 for i, step := range execution.ExecuteStepResults { 28 summary[i] = mapBatchStepExecutionResultToExecutionSummary(step) 29 } 30 } 31 32 return &testkube.TestSuiteExecutionSummary{ 33 Id: execution.Id, 34 Name: execution.Name, 35 TestSuiteName: testSuiteName, 36 Status: execution.Status, 37 StartTime: execution.StartTime, 38 EndTime: execution.EndTime, 39 Duration: execution.Duration, 40 DurationMs: execution.DurationMs, 41 Execution: summary, 42 Labels: execution.Labels, 43 } 44 } 45 46 func mapStepExecutionResultV2ToExecutionSummary(step testkube.TestSuiteStepExecutionResultV2) testkube.TestSuiteStepExecutionSummary { 47 var id, name, testName string 48 var status *testkube.ExecutionStatus 49 var tp *testkube.TestSuiteStepType 50 if step.Execution != nil { 51 id = step.Execution.Id 52 name = step.Execution.Name 53 testName = step.Execution.TestName 54 55 if step.Execution.ExecutionResult != nil { 56 status = step.Execution.ExecutionResult.Status 57 } 58 } 59 60 if step.Step != nil { 61 if step.Step.Execute != nil { 62 tp = testkube.TestSuiteStepTypeExecuteTest 63 } 64 65 if step.Step.Delay != nil { 66 tp = testkube.TestSuiteStepTypeDelay 67 } 68 } 69 70 return testkube.TestSuiteStepExecutionSummary{ 71 Id: id, 72 Name: name, 73 TestName: testName, 74 Status: status, 75 Type_: tp, 76 } 77 } 78 79 func mapBatchStepExecutionResultToExecutionSummary(step testkube.TestSuiteBatchStepExecutionResult) testkube.TestSuiteBatchStepExecutionSummary { 80 batch := make([]testkube.TestSuiteStepExecutionSummary, len(step.Execute)) 81 for i, step := range step.Execute { 82 batch[i] = mapStepExecutionResultToExecutionSummary(step) 83 } 84 85 return testkube.TestSuiteBatchStepExecutionSummary{ 86 Execute: batch, 87 } 88 } 89 90 func mapStepExecutionResultToExecutionSummary(step testkube.TestSuiteStepExecutionResult) testkube.TestSuiteStepExecutionSummary { 91 var id, name, testName string 92 var status *testkube.ExecutionStatus 93 var tp *testkube.TestSuiteStepType 94 if step.Execution != nil { 95 id = step.Execution.Id 96 name = step.Execution.Name 97 testName = step.Execution.TestName 98 99 if step.Execution.ExecutionResult != nil { 100 status = step.Execution.ExecutionResult.Status 101 } 102 } 103 104 if step.Step != nil { 105 if step.Step.Test != "" { 106 tp = testkube.TestSuiteStepTypeExecuteTest 107 } 108 109 if step.Step.Delay != "" { 110 tp = testkube.TestSuiteStepTypeDelay 111 } 112 } 113 114 return testkube.TestSuiteStepExecutionSummary{ 115 Id: id, 116 Name: name, 117 TestName: testName, 118 Status: status, 119 Type_: tp, 120 } 121 }