Skip to content

Commit

Permalink
feat: [TKC-3016] fix defaultConfigs for TestWorkflow executions (#6093)
Browse files Browse the repository at this point in the history
  • Loading branch information
povilasv authored Dec 19, 2024
1 parent a0e4eef commit 5f4da60
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pkg/repository/testworkflow/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,22 @@ type MongoRepositoryOpt func(*MongoRepository)
func (r *MongoRepository) Get(ctx context.Context, id string) (result testkube.TestWorkflowExecution, err error) {
err = r.Coll.FindOne(ctx, bson.M{"$or": bson.A{bson.M{"id": id}, bson.M{"name": id}}}).Decode(&result)

if result.ResolvedWorkflow != nil && result.ResolvedWorkflow.Spec != nil && result.ConfigParams != nil {
r.populateConfigParams(result.ResolvedWorkflow, result.ConfigParams)
if result.ResolvedWorkflow != nil && result.ResolvedWorkflow.Spec != nil {
result.ConfigParams = populateConfigParams(result.ResolvedWorkflow, result.ConfigParams)
}

return *result.UnscapeDots(), err
}

func (r *MongoRepository) populateConfigParams(resolvedWorkflow *testkube.TestWorkflow, configParams map[string]testkube.TestWorkflowExecutionConfigValue) {
func populateConfigParams(resolvedWorkflow *testkube.TestWorkflow, configParams map[string]testkube.TestWorkflowExecutionConfigValue) map[string]testkube.TestWorkflowExecutionConfigValue {
if configParams == nil {
configParams = make(map[string]testkube.TestWorkflowExecutionConfigValue)
}

for k, v := range resolvedWorkflow.Spec.Config {
if v.Sensitive {
return nil
}
if v.Default_ != nil {
if _, ok := configParams[k]; !ok {
configParams[k] = testkube.TestWorkflowExecutionConfigValue{
Expand All @@ -93,7 +100,8 @@ func (r *MongoRepository) populateConfigParams(resolvedWorkflow *testkube.TestWo
}
}
}
return

return configParams
}

func (r *MongoRepository) GetByNameAndTestWorkflow(ctx context.Context, name, workflowName string) (result testkube.TestWorkflowExecution, err error) {
Expand Down Expand Up @@ -303,8 +311,8 @@ func (r *MongoRepository) GetExecutionsSummary(ctx context.Context, filter Filte
for i := range executions {
executions[i].UnscapeDots()

if executions[i].ResolvedWorkflow != nil && executions[i].ResolvedWorkflow.Spec != nil && executions[i].ConfigParams != nil {
r.populateConfigParams(executions[i].ResolvedWorkflow, executions[i].ConfigParams)
if executions[i].ResolvedWorkflow != nil && executions[i].ResolvedWorkflow.Spec != nil {
executions[i].ConfigParams = populateConfigParams(executions[i].ResolvedWorkflow, executions[i].ConfigParams)
}
result[i] = executions[i].TestWorkflowExecutionSummary
}
Expand Down
72 changes: 72 additions & 0 deletions pkg/repository/testworkflow/mongo_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,76 @@ func TestNewMongoRepository_Get_Integration(t *testing.T) {
assert.Equal(t, "default", result.ConfigParams["param1"].DefaultValue)
assert.Equal(t, false, result.ConfigParams["param1"].Truncated)

execution2 := testkube.TestWorkflowExecution{
Id: "test-id-2",
Name: "test-name-2",
Workflow: &testkube.TestWorkflow{
Name: "test-workflow-2",
Spec: &testkube.TestWorkflowSpec{},
},
ResolvedWorkflow: &testkube.TestWorkflow{
Name: "test-workflow-2",
Spec: &testkube.TestWorkflowSpec{
Config: map[string]testkube.TestWorkflowParameterSchema{
"param2": {
Default_: &testkube.BoxedString{
Value: "default",
},
},
"param1": {
Default_: &testkube.BoxedString{
Value: "default",
},
Sensitive: true,
},
},
},
},
}
err = repo.Insert(ctx, execution2)
assert.NoError(t, err)

result, err = repo.Get(ctx, "test-id-2")
assert.NoError(t, err)

assert.Equal(t, execution2.Id, result.Id)
assert.Equal(t, execution2.Name, result.Name)
assert.Nil(t, result.ConfigParams)

execution3 := testkube.TestWorkflowExecution{
Id: "test-id-3",
Name: "test-name-3",
Workflow: &testkube.TestWorkflow{
Name: "test-workflow-3",
Spec: &testkube.TestWorkflowSpec{},
},
ResolvedWorkflow: &testkube.TestWorkflow{
Name: "test-workflow-2",
Spec: &testkube.TestWorkflowSpec{
Config: map[string]testkube.TestWorkflowParameterSchema{
"param2": {
Default_: &testkube.BoxedString{
Value: "default",
},
},
"param1": {
Default_: &testkube.BoxedString{
Value: "default",
},
Sensitive: true,
},
},
},
},
ConfigParams: map[string]testkube.TestWorkflowExecutionConfigValue{},
}
err = repo.Insert(ctx, execution3)
assert.NoError(t, err)

result, err = repo.Get(ctx, "test-id-3")
assert.NoError(t, err)

assert.Equal(t, execution3.Id, result.Id)
assert.Equal(t, execution3.Name, result.Name)
assert.Nil(t, result.ConfigParams)
}

0 comments on commit 5f4da60

Please sign in to comment.