-
Notifications
You must be signed in to change notification settings - Fork 76
chore: adopt testcontainers-go for Postgres, MySQL and MongoDB #1515
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
Changes from all commits
4ed3649
0e060e1
2f17493
2f5263e
689759c
ff25433
fc01fc5
4ad4b03
b53f02b
de8f798
471a6ac
c80f126
1d6c0c3
4d7a172
75c8525
1bb4d92
f962d64
1c23d53
7bbad9a
efbc89f
153c837
43a47ef
3cd89db
60be628
a4849c8
b3a2e40
db3ab9a
78da7fc
49eeb1d
1a5e6f9
cdf78c2
a7a26b8
39be258
8ee8130
bff5333
8cb7bc5
15865d5
4f1577a
478ea67
b074e83
cac4fd5
ae3a2de
c061165
af52fa3
0439f04
4e4e575
66cdbbd
8e75266
0f88b95
2cc5e2c
6742f2a
d793dc4
3a3ab81
4c2246e
c1362f1
a9bb64e
d3c0d39
0c2d884
c2e5b74
fe98837
f2ff5e7
e91a22a
0f9476e
5175998
3d82298
e0f5735
21157c2
0a12548
9b6b3c8
98ce163
64eb3d8
f1d4944
0937715
1137981
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,7 +11,9 @@ import ( | |||||||||||||||||||||||||||||||
"github.com/stretchr/testify/assert" | ||||||||||||||||||||||||||||||||
"github.com/stretchr/testify/require" | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
"github.com/testcontainers/testcontainers-go" | ||||||||||||||||||||||||||||||||
"github.com/testcontainers/testcontainers-go/modules/clickhouse" | ||||||||||||||||||||||||||||||||
"github.com/testcontainers/testcontainers-go/wait" | ||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
const ( | ||||||||||||||||||||||||||||||||
|
@@ -21,6 +23,8 @@ const ( | |||||||||||||||||||||||||||||||
clickhouseUser string = "default" | ||||||||||||||||||||||||||||||||
clickhousePass string = "password" | ||||||||||||||||||||||||||||||||
clickhouseDB string = "fiber" | ||||||||||||||||||||||||||||||||
clickhouseHttpPort = "8123/tcp" | ||||||||||||||||||||||||||||||||
clickhouseSuccessCode = 200 | ||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
func getTestConnection(t testing.TB, cfg Config) (*Storage, error) { | ||||||||||||||||||||||||||||||||
|
@@ -38,7 +42,16 @@ func getTestConnection(t testing.TB, cfg Config) (*Storage, error) { | |||||||||||||||||||||||||||||||
clickhouse.WithUsername(clickhouseUser), | ||||||||||||||||||||||||||||||||
clickhouse.WithPassword(clickhousePass), | ||||||||||||||||||||||||||||||||
clickhouse.WithDatabase(clickhouseDB), | ||||||||||||||||||||||||||||||||
testcontainers.WithWaitStrategy( | ||||||||||||||||||||||||||||||||
wait.ForAll( | ||||||||||||||||||||||||||||||||
wait.ForListeningPort(clickhouseHttpPort), | ||||||||||||||||||||||||||||||||
wait.NewHTTPStrategy("/").WithPort(clickhouseHttpPort).WithStatusCodeMatcher(func(status int) bool { | ||||||||||||||||||||||||||||||||
return status == clickhouseSuccessCode | ||||||||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||
Comment on lines
+45
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix handshake errors by adjusting wait strategy. The current wait strategy is causing handshake errors in the pipeline. The HTTP check might complete before the native protocol port is ready. testcontainers.WithWaitStrategy(
wait.ForAll(
wait.ForListeningPort(clickhouseHttpPort),
- wait.NewHTTPStrategy("/").WithPort(clickhouseHttpPort).WithStatusCodeMatcher(func(status int) bool {
- return status == clickhouseSuccessCode
- }),
+ wait.ForLog("Ready for connections").WithStartupTimeout(time.Second * 30),
+ wait.ForListeningPort("9000/tcp"),
),
), 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||
testcontainers.CleanupContainer(t, c) | ||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||
return nil, err | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
@@ -67,13 +80,14 @@ func getTestConnection(t testing.TB, cfg Config) (*Storage, error) { | |||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
func Test_Connection(t *testing.T) { | ||||||||||||||||||||||||||||||||
_, err := getTestConnection(t, Config{ | ||||||||||||||||||||||||||||||||
client, err := getTestConnection(t, Config{ | ||||||||||||||||||||||||||||||||
Engine: Memory, | ||||||||||||||||||||||||||||||||
Table: "test_table", | ||||||||||||||||||||||||||||||||
Clean: true, | ||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
require.NoError(t, err) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
defer client.Close() | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
func Test_Set(t *testing.T) { | ||||||||||||||||||||||||||||||||
|
@@ -191,6 +205,17 @@ func Test_Reset(t *testing.T) { | |||||||||||||||||||||||||||||||
assert.Equal(t, []byte{}, value) | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
func TestClose_ShouldReturn_NoError(t *testing.T) { | ||||||||||||||||||||||||||||||||
client, err := getTestConnection(t, Config{ | ||||||||||||||||||||||||||||||||
Engine: Memory, | ||||||||||||||||||||||||||||||||
Table: "test_table", | ||||||||||||||||||||||||||||||||
Clean: true, | ||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||
require.NoError(t, err) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
require.NoError(t, client.Close()) | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
func Benchmark_Clickhouse_Set(b *testing.B) { | ||||||||||||||||||||||||||||||||
b.ReportAllocs() | ||||||||||||||||||||||||||||||||
b.ResetTimer() | ||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.