Skip to content

Commit

Permalink
fix: check for required parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Feb 14, 2025
1 parent b6cd285 commit c076965
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
23 changes: 10 additions & 13 deletions internal/app/api/v1/testworkflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,19 +481,10 @@ func (s *TestkubeAPI) ReRunTestWorkflowExecutionHandler() fiber.Handler {
return s.ClientError(c, errPrefix, err)
}

if execution.Workflow != nil && execution.Workflow.Spec != nil && workflow.Spec != nil {
oldHash, err := execution.Workflow.Spec.GetConfigHash()
if err != nil {
return s.ClientError(c, errPrefix, err)
}

newHash, err := workflow.Spec.GetConfigHash()
if err != nil {
return s.ClientError(c, errPrefix, err)
}

if oldHash != newHash {
return s.ClientError(c, errPrefix, errors.New("current test workflow config spec doesn't match the execution one"))
requiredParameters := make(map[string]struct{})
if workflow.Spec != nil {
for _, parameter := range workflow.Spec.GetRequiredParameters() {
requiredParameters[parameter] = struct{}{}
}
}

Expand All @@ -520,6 +511,12 @@ func (s *TestkubeAPI) ReRunTestWorkflowExecutionHandler() fiber.Handler {
}
}

for key := range requiredParameters {
if _, ok := request.Config[key]; !ok {
return s.ClientError(c, errPrefix, errors.New("can't rerun test workflow execution without required parameters"))
}
}

runningContext, user := testworkflowexecutor.GetNewRunningContext(request.RunningContext, nil)

var scheduleExecution cloud.ScheduleExecution
Expand Down
19 changes: 7 additions & 12 deletions pkg/api/v1/testkube/model_test+workflow_spec_extended.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package testkube

import (
"encoding/json"
"hash/fnv"
)
func (t TestWorkflowSpec) GetRequiredParameters() []string {
keys := make([]string, 0)

func (t TestWorkflowSpec) GetConfigHash() (uint64, error) {
data, err := json.Marshal(t.Config)
if err != nil {
return 0, err
for key, value := range t.Config {
if value.Default_ == nil {
keys = append(keys, key)
}
}

configHash := fnv.New64a()
configHash.Write(data)

return configHash.Sum64(), nil
return keys
}

0 comments on commit c076965

Please sign in to comment.