Skip to content

Commit

Permalink
feat: start event for test workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io>
  • Loading branch information
vsukhin committed Jul 3, 2024
1 parent 04002dd commit cc14918
Showing 1 changed file with 111 additions and 1 deletion.
112 changes: 111 additions & 1 deletion pkg/mapper/cdevents/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ func MapTestkubeEventToCDEvent(tkEvent testkube.Event, clusterID, defaultNamespa

return MapTestkubeEventQueuedTestWorkflowTestToCDEvent(tkEvent, clusterID, defaultNamespace, dashboardURI)
case *testkube.EventStartTestWorkflow:
containsExuctionAction := false
if tkEvent.TestWorkflowExecution != nil {
containsExuctionAction = tkEvent.TestWorkflowExecution.ContainsExecuteAction()
}

if containsExuctionAction {
return MapTestkubeEventStartTestWorkflowTestSuiteToCDEvent(tkEvent, clusterID, defaultNamespace, dashboardURI)
}

return MapTestkubeEventStartTestWorkflowTestToCDEvent(tkEvent, clusterID, defaultNamespace, dashboardURI)
case *testkube.EventEndTestWorkflowAborted, *testkube.EventEndTestWorkflowFailed, *testkube.EventEndTestWorkflowSuccess:
}

Expand Down Expand Up @@ -504,7 +514,7 @@ func MapTestkubeEventQueuedTestWorkflowTestToCDEvent(event testkube.Event, clust

ev.SetSubjectTestCase(&cdevents.TestCaseRunQueuedSubjectContentTestCase{
Id: workflowName,
// Type: MapTestkubeTestTypeToCDEventTestCaseType(event.TestExecution.TestType),
// Type: MapTestkubeTestTypeToCDEventTestCaseType(event.TestWorkflowExecution.TestType),
Uri: fmt.Sprintf("%s/test-workflows/%s", dashboardURI, workflowName),
})

Expand Down Expand Up @@ -581,3 +591,103 @@ func MapTestkubeEventQueuedTestWorkflowTestSuiteToCDEvent(event testkube.Event,

return ev, nil
}

// MapTestkubeEventStartTestWorkflowTestToCDEvent maps OpenAPI spec Start Test Workflow Test Event to CDEvent CDEventReader
func MapTestkubeEventStartTestWorkflowTestToCDEvent(event testkube.Event, clusterID, defaultNamespace, dashboardURI string) (cdevents.CDEventReader, error) {
// Create the base event
ev, err := cdevents.NewTestCaseRunStartedEvent()
if err != nil {
return nil, err
}

if event.TestWorkflowExecution != nil {
ev.SetSubjectId(event.TestWorkflowExecution.Id)
}

ev.SetSubjectSource(clusterID)
ev.SetSource(clusterID)
if event.TestExecution != nil {
workflowName := ""
if event.TestWorkflowExecution.Workflow != nil {
workflowName = event.TestWorkflowExecution.Workflow.Name
}

ev.SetSubjectTestCase(&cdevents.TestCaseRunStartedSubjectContentTestCase{
Id: workflowName,
// Type: MapTestkubeTestTypeToCDEventTestCaseType(event.TestWorkflowExecution.TestType),
Uri: fmt.Sprintf("%s/test-workflows/%s", dashboardURI, workflowName),
})

namespace := event.TestWorkflowExecution.Namespace
if namespace == "" {
namespace = defaultNamespace
}

ev.SetSubjectEnvironment(&cdevents.Reference{
Id: namespace,
Source: clusterID,
})
/*
if event.TestWorkflowExecution.RunningContext != nil {
ev.SetSubjectTrigger(&cdevents.TestCaseRunStartedSubjectContentTrigger{
Type: MapTestkubeRunningContextTypeToCDEventTiggerType(event.TestWorkflowExecution.RunningContext.Type_),
})
}
if event.TestWorkflowExecution.ParentName != "" {
ev.SetSubjectTestSuiteRun(&cdevents.Reference{
Id: event.TestWorkflowExecution.ParentName,
Source: clusterID,
})
}
*/
}

return ev, nil
}

// MapTestkubeEventStartTestWorkflowTestSuiteToCDEvent maps OpenAPI spec Start Test Workflow Test Suite Event to CDEvent CDEventReader
func MapTestkubeEventStartTestWorkflowTestSuiteToCDEvent(event testkube.Event, clusterID, defaultNamespace, dashboardURI string) (cdevents.CDEventReader, error) {
// Create the base event
ev, err := cdevents.NewTestSuiteRunStartedEvent()
if err != nil {
return nil, err
}

if event.TestWorkflowExecution != nil {
ev.SetSubjectId(event.TestWorkflowExecution.Id)
}

ev.SetSubjectSource(clusterID)
ev.SetSource(clusterID)
if event.TestWorkflowExecution != nil {
workflowName := ""
if event.TestWorkflowExecution.Workflow != nil {
workflowName = event.TestWorkflowExecution.Workflow.Name
}

ev.SetSubjectTestSuite(&cdevents.TestSuiteRunStartedSubjectContentTestSuite{
Id: workflowName,
Uri: fmt.Sprintf("%s/test-workflows/%s", dashboardURI, workflowName),
})

namespace := event.TestWorkflowExecution.Namespace
if namespace == "" {
namespace = defaultNamespace
}

ev.SetSubjectEnvironment(&cdevents.Reference{
Id: namespace,
Source: clusterID,
})
/*
if event.TestWorkflowExecution.RunningContext != nil {
ev.SetSubjectTrigger(&cdevents.TestSuiteRunStartedSubjectContentTrigger{
Type: MapTestkubeRunningContextTypeToCDEventTiggerType(event.TestWorkflowExecution.RunningContext.Type_),
})
}
*/
}

return ev, nil
}

0 comments on commit cc14918

Please sign in to comment.