Skip to content

Commit 66a5ca5

Browse files
committed
Enable e2e tests for all 3 backens
1 parent bde8639 commit 66a5ca5

File tree

3 files changed

+77
-27
lines changed

3 files changed

+77
-27
lines changed

backend/mysql/mysql_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,42 @@ func Test_MysqlBackend(t *testing.T) {
5555
}
5656
})
5757
}
58+
59+
func TestMySqlBackendE2E(t *testing.T) {
60+
if testing.Short() {
61+
t.Skip()
62+
}
63+
64+
var dbName string
65+
66+
test.EndToEndBackendTest(t, func() backend.Backend {
67+
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@/?parseTime=true&interpolateParams=true", testUser, testPassword))
68+
if err != nil {
69+
panic(err)
70+
}
71+
72+
dbName = "test_" + strings.Replace(uuid.NewString(), "-", "", -1)
73+
if _, err := db.Exec("CREATE DATABASE " + dbName); err != nil {
74+
panic(fmt.Errorf("creating database: %w", err))
75+
}
76+
77+
if err := db.Close(); err != nil {
78+
panic(err)
79+
}
80+
81+
return NewMysqlBackend("localhost", 3306, testUser, testPassword, dbName, backend.WithStickyTimeout(0))
82+
}, func(b backend.Backend) {
83+
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@/?parseTime=true&interpolateParams=true", testUser, testPassword))
84+
if err != nil {
85+
panic(err)
86+
}
87+
88+
if _, err := db.Exec("DROP DATABASE IF EXISTS " + dbName); err != nil {
89+
panic(fmt.Errorf("dropping database: %w", err))
90+
}
91+
92+
if err := db.Close(); err != nil {
93+
panic(err)
94+
}
95+
})
96+
}

backend/redis/redis_test.go

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,46 @@ import (
88
"github.com/cschleiden/go-workflows/backend"
99
"github.com/cschleiden/go-workflows/backend/test"
1010
"github.com/go-redis/redis/v8"
11-
"github.com/stretchr/testify/require"
1211
)
1312

1413
func Test_RedisBackend(t *testing.T) {
1514
if testing.Short() {
1615
t.Skip()
1716
}
1817

19-
test.BackendTest(t, func() backend.Backend {
20-
address := "localhost:6379"
21-
user := ""
22-
password := "RedisPassw0rd"
23-
24-
// Flush database
25-
client := redis.NewUniversalClient(&redis.UniversalOptions{
26-
Addrs: []string{address},
27-
Username: user,
28-
Password: password,
29-
DB: 0,
30-
})
31-
32-
if err := client.FlushDB(context.Background()).Err(); err != nil {
33-
panic(err)
34-
}
35-
36-
// Disable sticky workflow behavior for the test execution
37-
b, err := NewRedisBackend(address, user, password, 0, WithBlockTimeout(time.Millisecond*2))
38-
require.NoError(t, err)
39-
40-
return b
41-
}, nil)
18+
test.BackendTest(t, createBackend, nil)
19+
}
20+
21+
func Test_EndToEndRedisBackend(t *testing.T) {
22+
if testing.Short() {
23+
t.Skip()
24+
}
25+
26+
test.EndToEndBackendTest(t, createBackend, nil)
27+
}
28+
29+
func createBackend() backend.Backend {
30+
address := "localhost:6379"
31+
user := ""
32+
password := "RedisPassw0rd"
33+
34+
// Flush database
35+
client := redis.NewUniversalClient(&redis.UniversalOptions{
36+
Addrs: []string{address},
37+
Username: user,
38+
Password: password,
39+
DB: 0,
40+
})
41+
42+
if err := client.FlushDB(context.Background()).Err(); err != nil {
43+
panic(err)
44+
}
45+
46+
// Disable sticky workflow behavior for the test execution
47+
b, err := NewRedisBackend(address, user, password, 0, WithBlockTimeout(time.Millisecond*2))
48+
if err != nil {
49+
panic(err)
50+
}
51+
52+
return b
4253
}

backend/test/e2e.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ func EndToEndBackendTest(t *testing.T, setup func() backend.Backend, teardown fu
4444

4545
output, err := runWorkflowWithResult[string](t, ctx, c, wf, "hello")
4646

47-
require.Nil(t, output)
48-
require.Error(t, err)
47+
require.Zero(t, output)
48+
require.ErrorContains(t, err, "workflow 1 not found")
4949
},
5050
},
5151
{
@@ -55,7 +55,7 @@ func EndToEndBackendTest(t *testing.T, setup func() backend.Backend, teardown fu
5555
wf := func(ctx workflow.Context) (int, error) {
5656
return workflow.ExecuteActivity[int](ctx, workflow.DefaultActivityOptions, a).Get(ctx)
5757
}
58-
register(t, ctx, w, nil, []interface{}{wf})
58+
register(t, ctx, w, []interface{}{wf}, nil)
5959

6060
output, err := runWorkflowWithResult[int](t, ctx, c, wf)
6161

0 commit comments

Comments
 (0)