Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [TKC-3016] fix defaultConfigs for TestWorkflow executions #6093

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading