Skip to content

Commit

Permalink
fix: dep update
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Oct 8, 2024
1 parent b5052ef commit f459b3b
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 95 deletions.
3 changes: 3 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8086,6 +8086,7 @@ components:
tags:
$ref: "#/components/schemas/TestWorkflowTagValue"
runningContext:
description: running context for the test workflow execution (Pro edition only)
$ref: "#/components/schemas/TestWorkflowRunningContext"
parentExecutionIds:
type: array
Expand Down Expand Up @@ -8186,6 +8187,7 @@ components:
tags:
$ref: "#/components/schemas/TestWorkflowTagValue"
runningContext:
description: running context for the test workflow execution (Pro edition only)
$ref: "#/components/schemas/TestWorkflowRunningContext"
required:
- id
Expand Down Expand Up @@ -8222,6 +8224,7 @@ components:
tags:
$ref: "#/components/schemas/TestWorkflowTagValue"
runningContext:
description: running context for the test workflow execution (Pro edition only)
$ref: "#/components/schemas/TestWorkflowRunningContext"
required:
- id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,14 @@ func printPrettyOutput(ui *ui.UI, execution testkube.TestWorkflowExecution) {
ui.NL()
ui.Warn("Tags: ", testkube.MapToString(execution.Tags))
}
for _, ctx := range execution.RunningContext {
if execution.RunningContext != nil {
ui.Warn("Running context: ")
ctx := execution.RunningContext
if ctx.Interface_ != nil {
ui.Warn("Interface: ", string(*ctx.Interface_))
ui.Warn("Interface: ", string(*ctx.Interface_.Type_))
}
if ctx.Actor != nil {
ui.Warn("Actor: ", string(*ctx.Actor))
}
if ctx.Caller != nil {
ui.Warn("Caller: ")
if ctx.Caller.CallerResourceType != nil {
ui.Warn("Resource type: ", string(*ctx.Caller.CallerResourceType))
}
ui.Warn("Resource name: ", ctx.Caller.CallerResourceName)
if ctx.Caller.CallerResourceExecutionID != "" {
ui.Warn("Execution ID: ", ctx.Caller.CallerResourceExecutionID)
}
if ctx.Caller.FullExecutionPath != "" {
ui.Warn("Full execution path: ", ctx.Caller.FullExecutionPath)
}
ui.Warn("Actor: ", string(*ctx.Actor.Type_))
}
}
if execution.Result != nil && execution.Result.Status != nil {
Expand Down
10 changes: 6 additions & 4 deletions cmd/kubectl-testkube/commands/testworkflows/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ func NewRunTestWorkflowCmd() *cobra.Command {
Config: config,
DisableWebhooks: disableWebhooks,
Tags: tags,
RunningContext: []testkube.TestWorkflowRunningContext{
{
Interface_: intcommon.Ptr(testkube.CLI_TestWorkflowRunningContextInterface),
Actor: intcommon.Ptr(testkube.USER_TestWorkflowRunningContextActor),
RunningContext: &testkube.TestWorkflowRunningContext{
Interface_: &testkube.TestWorkflowRunningContextInterface{
Type_: intcommon.Ptr(testkube.CLI_TestWorkflowRunningContextInterfaceType),
},
Actor: &testkube.TestWorkflowRunningContextActor{
Type_: intcommon.Ptr(testkube.USER_TestWorkflowRunningContextActorType),
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/kelseyhightower/envconfig v1.4.0
github.com/kubepug/kubepug v1.7.1
github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20241004144749-280aeba10b40
github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20241008095446-1943acbe384c
github.com/minio/minio-go/v7 v7.0.47
github.com/montanaflynn/stats v0.6.6
github.com/moogar0880/problems v0.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubepug/kubepug v1.7.1 h1:LKhfSxS8Y5mXs50v+3Lpyec+cogErDLcV7CMUuiaisw=
github.com/kubepug/kubepug v1.7.1/go.mod h1:lv+HxD0oTFL7ZWjj0u6HKhMbbTIId3eG7aWIW0gyF8g=
github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20241004144749-280aeba10b40 h1:8FrH3op0KpQHBKVHMq7FmSTOiIH49S/5+LnDLKm3/bQ=
github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20241004144749-280aeba10b40/go.mod h1:P47tw1nKQFufdsZndyq2HG2MSa0zK/lU0XpRfZtEmIk=
github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20241008095446-1943acbe384c h1:gBWVDIYWFdjDM7kH6jczx0CyDIekhBZn5uOzTjJXtf0=
github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20241008095446-1943acbe384c/go.mod h1:P47tw1nKQFufdsZndyq2HG2MSa0zK/lU0XpRfZtEmIk=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4=
Expand Down
40 changes: 17 additions & 23 deletions pkg/mapper/cdevents/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,14 @@ func MapTestkubeRunningContextTypeToCDEventTiggerType(contextType string) string
}

// MapTestkubeTestWorkflowRunningContextActorToCDEventTiggerType maps OpenAPI spec Test Workflow Running Context Actor to CDEvent Trigger Type
func MapTestkubeTestWorkflowRunningContextActorToCDEventTiggerType(actor testkube.TestWorkflowRunningContextActor) string {
func MapTestkubeTestWorkflowRunningContextActorToCDEventTiggerType(actor testkube.TestWorkflowRunningContextActorType) string {
switch actor {
case testkube.USER_TestWorkflowRunningContextActor:
case testkube.USER_TestWorkflowRunningContextActorType:
return "manual"
case testkube.TESTWORKFLOW_TestWorkflowRunningContextActor, testkube.TESTWORKFLOWEXECUTION_TestWorkflowRunningContextActor,
testkube.TESTRIGGER_TestWorkflowRunningContextActor:
case testkube.TESTWORKFLOW_TestWorkflowRunningContextActorType, testkube.TESTWORKFLOWEXECUTION_TestWorkflowRunningContextActorType,
testkube.TESTRIGGER_TestWorkflowRunningContextActorType:
return "event"
case testkube.CRON_TestWorkflowRunningContextActor:
case testkube.CRON_TestWorkflowRunningContextActorType:
return "schedule"
}

Expand Down Expand Up @@ -502,16 +502,6 @@ func MapMimeTypeToCDEventOutputType(mimeType string) string {
return "other"
}

func getActor(runningContext []testkube.TestWorkflowRunningContext) *testkube.TestWorkflowRunningContextActor {
for _, ctx := range runningContext {
if ctx.Actor != nil {
return ctx.Actor
}
}

return nil
}

// MapTestkubeEventQueuedTestWorkflowTestToCDEvent maps OpenAPI spec Queued Test Workflow Test Event to CDEvent CDEventReader
func MapTestkubeEventQueuedTestWorkflowTestToCDEvent(event testkube.Event, clusterID, defaultNamespace, dashboardURI string) (cdevents.CDEventReader, error) {
// Create the base event
Expand Down Expand Up @@ -548,9 +538,10 @@ func MapTestkubeEventQueuedTestWorkflowTestToCDEvent(event testkube.Event, clust
Source: clusterID,
})

if actor := getActor(event.TestWorkflowExecution.RunningContext); actor != nil {
if event.TestWorkflowExecution.RunningContext != nil && event.TestWorkflowExecution.RunningContext.Actor != nil &&
event.TestWorkflowExecution.RunningContext.Actor.Type_ != nil {
ev.SetSubjectTrigger(&cdevents.TestCaseRunQueuedSubjectContentTrigger{
Type: MapTestkubeTestWorkflowRunningContextActorToCDEventTiggerType(*actor),
Type: MapTestkubeTestWorkflowRunningContextActorToCDEventTiggerType(*event.TestWorkflowExecution.RunningContext.Actor.Type_),
})
}
}
Expand Down Expand Up @@ -593,9 +584,10 @@ func MapTestkubeEventQueuedTestWorkflowTestSuiteToCDEvent(event testkube.Event,
Source: clusterID,
})

if actor := getActor(event.TestWorkflowExecution.RunningContext); actor != nil {
if event.TestWorkflowExecution.RunningContext != nil && event.TestWorkflowExecution.RunningContext.Actor != nil &&
event.TestWorkflowExecution.RunningContext.Actor.Type_ != nil {
ev.SetSubjectTrigger(&cdevents.TestSuiteRunQueuedSubjectContentTrigger{
Type: MapTestkubeTestWorkflowRunningContextActorToCDEventTiggerType(*actor),
Type: MapTestkubeTestWorkflowRunningContextActorToCDEventTiggerType(*event.TestWorkflowExecution.RunningContext.Actor.Type_),
})
}
}
Expand Down Expand Up @@ -639,9 +631,10 @@ func MapTestkubeEventStartTestWorkflowTestToCDEvent(event testkube.Event, cluste
Source: clusterID,
})

if actor := getActor(event.TestWorkflowExecution.RunningContext); actor != nil {
if event.TestWorkflowExecution.RunningContext != nil && event.TestWorkflowExecution.RunningContext.Actor != nil &&
event.TestWorkflowExecution.RunningContext.Actor.Type_ != nil {
ev.SetSubjectTrigger(&cdevents.TestCaseRunStartedSubjectContentTrigger{
Type: MapTestkubeTestWorkflowRunningContextActorToCDEventTiggerType(*actor),
Type: MapTestkubeTestWorkflowRunningContextActorToCDEventTiggerType(*event.TestWorkflowExecution.RunningContext.Actor.Type_),
})
}
}
Expand Down Expand Up @@ -684,9 +677,10 @@ func MapTestkubeEventStartTestWorkflowTestSuiteToCDEvent(event testkube.Event, c
Source: clusterID,
})

if actor := getActor(event.TestWorkflowExecution.RunningContext); actor != nil {
if event.TestWorkflowExecution.RunningContext != nil && event.TestWorkflowExecution.RunningContext.Actor != nil &&
event.TestWorkflowExecution.RunningContext.Actor.Type_ != nil {
ev.SetSubjectTrigger(&cdevents.TestSuiteRunStartedSubjectContentTrigger{
Type: MapTestkubeTestWorkflowRunningContextActorToCDEventTiggerType(*actor),
Type: MapTestkubeTestWorkflowRunningContextActorToCDEventTiggerType(*event.TestWorkflowExecution.RunningContext.Actor.Type_),
})
}
}
Expand Down
36 changes: 18 additions & 18 deletions pkg/mapper/cdevents/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ func TestMapTestkubeEventQueuedTestWorkflowTestToCDEvent(t *testing.T) {
},
},
},
RunningContext: []testkube.TestWorkflowRunningContext{
{
Actor: common.Ptr(testkube.CRON_TestWorkflowRunningContextActor),
RunningContext: &testkube.TestWorkflowRunningContext{
Actor: &testkube.TestWorkflowRunningContextActor{
Type_: common.Ptr(testkube.CRON_TestWorkflowRunningContextActorType),
},
},
},
Expand Down Expand Up @@ -598,9 +598,9 @@ func TestMapTestkubeEventQueuedTestWorkflowTestSuiteToCDEvent(t *testing.T) {
},
},
},
RunningContext: []testkube.TestWorkflowRunningContext{
{
Actor: common.Ptr(testkube.CRON_TestWorkflowRunningContextActor),
RunningContext: &testkube.TestWorkflowRunningContext{
Actor: &testkube.TestWorkflowRunningContextActor{
Type_: common.Ptr(testkube.CRON_TestWorkflowRunningContextActorType),
},
},
},
Expand Down Expand Up @@ -675,9 +675,9 @@ func TestMapTestkubeEventStartTestWorkflowTestToCDEvent(t *testing.T) {
},
},
},
RunningContext: []testkube.TestWorkflowRunningContext{
{
Actor: common.Ptr(testkube.CRON_TestWorkflowRunningContextActor),
RunningContext: &testkube.TestWorkflowRunningContext{
Actor: &testkube.TestWorkflowRunningContextActor{
Type_: common.Ptr(testkube.CRON_TestWorkflowRunningContextActorType),
},
},
},
Expand Down Expand Up @@ -762,9 +762,9 @@ func TestMapTestkubeEventStartTestWorkflowTestSuiteToCDEvent(t *testing.T) {
},
},
},
RunningContext: []testkube.TestWorkflowRunningContext{
{
Actor: common.Ptr(testkube.CRON_TestWorkflowRunningContextActor),
RunningContext: &testkube.TestWorkflowRunningContext{
Actor: &testkube.TestWorkflowRunningContextActor{
Type_: common.Ptr(testkube.CRON_TestWorkflowRunningContextActorType),
},
},
},
Expand Down Expand Up @@ -848,9 +848,9 @@ func TestMapTestkubeEventFinishTestWorkflowTestToCDEvent(t *testing.T) {
},
},
},
RunningContext: []testkube.TestWorkflowRunningContext{
{
Actor: common.Ptr(testkube.CRON_TestWorkflowRunningContextActor),
RunningContext: &testkube.TestWorkflowRunningContext{
Actor: &testkube.TestWorkflowRunningContextActor{
Type_: common.Ptr(testkube.CRON_TestWorkflowRunningContextActorType),
},
},
},
Expand Down Expand Up @@ -953,9 +953,9 @@ func TestMapTestkubeEventFinishTestWorkflowTestSuiteToCDEvent(t *testing.T) {
},
},
},
RunningContext: []testkube.TestWorkflowRunningContext{
{
Actor: common.Ptr(testkube.CRON_TestWorkflowRunningContextActor),
RunningContext: &testkube.TestWorkflowRunningContext{
Actor: &testkube.TestWorkflowRunningContextActor{
Type_: common.Ptr(testkube.CRON_TestWorkflowRunningContextActorType),
},
},
},
Expand Down
34 changes: 19 additions & 15 deletions pkg/mapper/testworkflows/openapi_kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -1380,32 +1380,36 @@ func MapTestWorkflowSignatureAPIToKube(v testkube.TestWorkflowSignature) testwor
}
}

func MapTestWorkflowRunningContextInterfaceAPIToKube(v testkube.TestWorkflowRunningContextInterface) testworkflowsv1.TestWorkflowRunningContextInterface {
return testworkflowsv1.TestWorkflowRunningContextInterface(v)
func MapTestWorkflowRunningContextInterfaceTypeAPIToKube(v testkube.TestWorkflowRunningContextInterfaceType) testworkflowsv1.TestWorkflowRunningContextInterfaceType {
return testworkflowsv1.TestWorkflowRunningContextInterfaceType(v)
}

func MapTestWorkflowRunningContextActorAPIToKube(v testkube.TestWorkflowRunningContextActor) testworkflowsv1.TestWorkflowRunningContextActor {
return testworkflowsv1.TestWorkflowRunningContextActor(v)
func MapTestWorkflowRunningContextInterfaceAPIToKube(v testkube.TestWorkflowRunningContextInterface) testworkflowsv1.TestWorkflowRunningContextInterface {
return testworkflowsv1.TestWorkflowRunningContextInterface{
Name: v.Name,
Type_: common.MapPtr(v.Type_, MapTestWorkflowRunningContextInterfaceTypeAPIToKube),
}
}

func MapTestWorkflowRunningContextCallerResourceTypeAPIToKube(v testkube.TestWorkflowRunningContextCallerResourceType) testworkflowsv1.TestWorkflowRunningContextCallerResourceType {
return testworkflowsv1.TestWorkflowRunningContextCallerResourceType(v)
func MapTestWorkflowRunningContextActorTypeAPIToKube(v testkube.TestWorkflowRunningContextActorType) testworkflowsv1.TestWorkflowRunningContextActorType {
return testworkflowsv1.TestWorkflowRunningContextActorType(v)
}

func MapTestWorkflowRunningContextCallerAPIToKube(v testkube.TestWorkflowRunningContextCaller) testworkflowsv1.TestWorkflowRunningContextCaller {
return testworkflowsv1.TestWorkflowRunningContextCaller{
CallerResourceType: common.MapPtr(v.CallerResourceType, MapTestWorkflowRunningContextCallerResourceTypeAPIToKube),
CallerResourceName: v.CallerResourceName,
CallerResourceExecutionID: v.CallerResourceExecutionID,
FullExecutionPath: v.FullExecutionPath,
func MapTestWorkflowRunningContextActorAPIToKube(v testkube.TestWorkflowRunningContextActor) testworkflowsv1.TestWorkflowRunningContextActor {
return testworkflowsv1.TestWorkflowRunningContextActor{
Name: v.Name,
Username: v.Username,
Email: v.Email,
ExecutionId: v.ExecutionId,
ExecutionPath: v.ExecutionPath,
Type_: common.MapPtr(v.Type_, MapTestWorkflowRunningContextActorTypeAPIToKube),
}
}

func MapTestWorkflowRunningContextAPIToKube(v testkube.TestWorkflowRunningContext) testworkflowsv1.TestWorkflowRunningContext {
return testworkflowsv1.TestWorkflowRunningContext{
Interface_: common.MapPtr(v.Interface_, MapTestWorkflowRunningContextInterfaceAPIToKube),
Actor: common.MapPtr(v.Actor, MapTestWorkflowRunningContextActorAPIToKube),
Caller: common.MapPtr(v.Caller, MapTestWorkflowRunningContextCallerAPIToKube),
}
}

Expand All @@ -1426,7 +1430,7 @@ func MapTestWorkflowExecutionAPIToKube(v *testkube.TestWorkflowExecution) *testw
TestWorkflowExecutionName: v.TestWorkflowExecutionName,
DisableWebhooks: v.DisableWebhooks,
Tags: v.Tags,
RunningContext: common.MapSlice(v.RunningContext, MapTestWorkflowRunningContextAPIToKube),
RunningContext: common.MapPtr(v.RunningContext, MapTestWorkflowRunningContextAPIToKube),
}
}

Expand All @@ -1448,7 +1452,7 @@ func MapTestWorkflowExecutionAPIToKubeTestWorkflowStatusSummary(v *testkube.Test
Result: common.MapPtr(v.Result, MapTestWorkflowResultAPIToKubeTestWorkflowResultSummary),
Workflow: common.MapPtr(v.Workflow, MapTestWorkflowAPIToKubeTestWorkflowSummary),
Tags: v.Tags,
RunningContext: common.MapSlice(v.RunningContext, MapTestWorkflowRunningContextAPIToKube),
RunningContext: common.MapPtr(v.RunningContext, MapTestWorkflowRunningContextAPIToKube),
},
}
}
Expand Down
15 changes: 7 additions & 8 deletions pkg/triggers/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,13 @@ func (s *Service) execute(ctx context.Context, e *watcherEvent, t *testtriggersv

request := testkube.TestWorkflowExecutionRequest{
Config: make(map[string]string, len(variables)),
RunningContext: []testkube.TestWorkflowRunningContext{
{
Interface_: common.Ptr(testkube.INTERNAL_TestWorkflowRunningContextInterface),
Actor: common.Ptr(testkube.TESTRIGGER_TestWorkflowRunningContextActor),
Caller: &testkube.TestWorkflowRunningContextCaller{
CallerResourceType: common.Ptr(testkube.TESTTRIGGER_TestWorkflowRunningContextCallerResourceType),
CallerResourceName: t.Name,
},
RunningContext: &testkube.TestWorkflowRunningContext{
Interface_: &testkube.TestWorkflowRunningContextInterface{
Type_: common.Ptr(testkube.INTERNAL_TestWorkflowRunningContextInterfaceType),
},
Actor: &testkube.TestWorkflowRunningContextActor{
Name: t.Name,
Type_: common.Ptr(testkube.TESTRIGGER_TestWorkflowRunningContextActorType),
},
},
}
Expand Down
15 changes: 7 additions & 8 deletions pkg/triggers/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,13 @@ func TestWorkflowExecute(t *testing.T) {
"WATCHER_EVENT_NAMESPACE": "",
"WATCHER_EVENT_RESOURCE": "",
},
RunningContext: []testkube.TestWorkflowRunningContext{
{
Interface_: common.Ptr(testkube.INTERNAL_TestWorkflowRunningContextInterface),
Actor: common.Ptr(testkube.TESTRIGGER_TestWorkflowRunningContextActor),
Caller: &testkube.TestWorkflowRunningContextCaller{
CallerResourceType: common.Ptr(testkube.TESTTRIGGER_TestWorkflowRunningContextCallerResourceType),
CallerResourceName: "test-trigger-1",
},
RunningContext: &testkube.TestWorkflowRunningContext{
Interface_: &testkube.TestWorkflowRunningContextInterface{
Type_: common.Ptr(testkube.INTERNAL_TestWorkflowRunningContextInterfaceType),
},
Actor: &testkube.TestWorkflowRunningContextActor{
Name: "test-trigger-1",
Type_: common.Ptr(testkube.TESTRIGGER_TestWorkflowRunningContextActorType),
},
},
}
Expand Down

0 comments on commit f459b3b

Please sign in to comment.