Skip to content

Commit b0747c0

Browse files
fix: add suspend column alias and improve test coverage for review feedback
Signed-off-by: Mario Apostolov <mario.apostolov@mariadb.com>
1 parent 7007a62 commit b0747c0

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

persist/sqldb/workflow_archive.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ func (r *workflowArchive) ListWorkflows(ctx context.Context, options sutils.List
187187
db.Raw("coalesce(JSON_EXTRACT(workflow, '$.metadata.labels'), '{}') as labels"),
188188
db.Raw("coalesce(JSON_EXTRACT(workflow, '$.metadata.annotations'), '{}') as annotations"),
189189
db.Raw("coalesce(JSON_UNQUOTE(JSON_EXTRACT(workflow, '$.status.progress')), '') as progress"),
190-
db.Raw("JSON_UNQUOTE(JSON_EXTRACT(workflow, '$.spec.suspend'))"),
191-
db.Raw("coalesce(JSON_UNQUOTE(JSON_EXTRACT(workflow, '$.spec.arguments')), '{}') as arguments"),
190+
db.Raw("JSON_UNQUOTE(JSON_EXTRACT(workflow, '$.spec.suspend')) as suspend"),
191+
db.Raw("coalesce(JSON_EXTRACT(workflow, '$.spec.arguments'), '{}') as arguments"),
192192
db.Raw("coalesce(JSON_UNQUOTE(JSON_EXTRACT(workflow, '$.status.message')), '') as message"),
193193
db.Raw("coalesce(JSON_UNQUOTE(JSON_EXTRACT(workflow, '$.status.estimatedDuration')), '0') as estimatedduration"),
194194
db.Raw("coalesce(JSON_EXTRACT(workflow, '$.status.resourcesDuration'), '{}') as resourcesduration"),

persist/sqldb/workflow_archive_mysql_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/testcontainers/testcontainers-go/wait"
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1616
"k8s.io/apimachinery/pkg/types"
17+
"k8s.io/utils/ptr"
1718

1819
"github.com/argoproj/argo-workflows/v4/config"
1920
wfv1 "github.com/argoproj/argo-workflows/v4/pkg/apis/workflow/v1alpha1"
@@ -33,7 +34,8 @@ var mysqlVariants = map[string]mysqlVariant{
3334
"MariaDB": {image: "mariadb:11.4", waitMessage: "mariadbd: ready for connections"},
3435
}
3536

36-
func setupMySQLArchiveTest(ctx context.Context, t *testing.T, v mysqlVariant) (WorkflowArchive, func()) {
37+
// setupMySQLArchiveTest starts a MySQL or MariaDB container, runs migrations, and returns a WorkflowArchive.
38+
func setupMySQLArchiveTest(ctx context.Context, t *testing.T, v mysqlVariant) WorkflowArchive {
3739
t.Helper()
3840

3941
c, err := testmysql.Run(ctx,
@@ -48,6 +50,7 @@ func setupMySQLArchiveTest(ctx context.Context, t *testing.T, v mysqlVariant) (W
4850
)),
4951
)
5052
require.NoError(t, err)
53+
t.Cleanup(func() { testcontainers.TerminateContainer(c) }) //nolint:errcheck
5154

5255
host, err := c.Host(ctx)
5356
require.NoError(t, err)
@@ -74,10 +77,9 @@ func setupMySQLArchiveTest(ctx context.Context, t *testing.T, v mysqlVariant) (W
7477
err = Migrate(ctx, proxy.Session(), "test", "argo_workflows", proxy.DBType())
7578
require.NoError(t, err)
7679

77-
return NewWorkflowArchive(proxy, "test", "", instanceid.NewService("")), func() {
78-
proxy.Close()
79-
testcontainers.TerminateContainer(c) //nolint:errcheck
80-
}
80+
t.Cleanup(func() { proxy.Close() })
81+
82+
return NewWorkflowArchive(proxy, "test", "", instanceid.NewService(""))
8183
}
8284

8385
// TestMySQLListWorkflows verifies that JSON_EXTRACT/JSON_UNQUOTE queries in
@@ -90,8 +92,7 @@ func TestMySQLListWorkflows(t *testing.T) {
9092
for name, variant := range mysqlVariants {
9193
t.Run(name, func(t *testing.T) {
9294
ctx := logging.TestContext(t.Context())
93-
archive, cleanup := setupMySQLArchiveTest(ctx, t, variant)
94-
defer cleanup()
95+
archive := setupMySQLArchiveTest(ctx, t, variant)
9596

9697
now := metav1.Now()
9798
err := archive.ArchiveWorkflow(ctx, &wfv1.Workflow{
@@ -106,6 +107,7 @@ func TestMySQLListWorkflows(t *testing.T) {
106107
},
107108
},
108109
Spec: wfv1.WorkflowSpec{
110+
Suspend: ptr.To(true),
109111
Arguments: wfv1.Arguments{
110112
Parameters: []wfv1.Parameter{
111113
{Name: "msg", Value: wfv1.AnyStringPtr("hello")},
@@ -132,6 +134,7 @@ func TestMySQLListWorkflows(t *testing.T) {
132134
assert.Equal(t, wfv1.Progress("1/1"), wf.Status.Progress)
133135
assert.Equal(t, "completed", wf.Status.Message)
134136
assert.Equal(t, "test", wf.GetLabels()["env"])
137+
assert.Equal(t, ptr.To(true), wf.Spec.Suspend)
135138
})
136139
}
137140
}

util/sqldb/sqldb_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ var mysqlVariants = map[string]mysqlVariant{
2626
"MariaDB": {image: "mariadb:11.4", waitMessage: "mariadbd: ready for connections"},
2727
}
2828

29-
func setupMySQLContainer(ctx context.Context, t *testing.T, v mysqlVariant) (config.DBConfig, func()) {
29+
// setupMySQLContainer starts a MySQL or MariaDB container and returns the corresponding DBConfig.
30+
func setupMySQLContainer(ctx context.Context, t *testing.T, v mysqlVariant) config.DBConfig {
3031
t.Helper()
3132

3233
c, err := testmysql.Run(ctx,
@@ -41,6 +42,7 @@ func setupMySQLContainer(ctx context.Context, t *testing.T, v mysqlVariant) (con
4142
)),
4243
)
4344
require.NoError(t, err)
45+
t.Cleanup(func() { testcontainers.TerminateContainer(c) }) //nolint:errcheck
4446

4547
host, err := c.Host(ctx)
4648
require.NoError(t, err)
@@ -57,7 +59,7 @@ func setupMySQLContainer(ctx context.Context, t *testing.T, v mysqlVariant) (con
5759
Port: port,
5860
},
5961
},
60-
}, func() { testcontainers.TerminateContainer(c) } //nolint:errcheck
62+
}
6163
}
6264

6365
// TestMySQLSessionConnect verifies that CreateDBSessionWithCreds can connect
@@ -70,8 +72,7 @@ func TestMySQLSessionConnect(t *testing.T) {
7072
for name, variant := range mysqlVariants {
7173
t.Run(name, func(t *testing.T) {
7274
ctx := logging.TestContext(t.Context())
73-
dbConfig, cleanup := setupMySQLContainer(ctx, t, variant)
74-
defer cleanup()
75+
dbConfig := setupMySQLContainer(ctx, t, variant)
7576

7677
sess, dbType, err := CreateDBSessionWithCreds(dbConfig, "argo", "argo")
7778
require.NoError(t, err)

0 commit comments

Comments
 (0)