@@ -11,7 +11,9 @@ import (
1111 "github.com/stretchr/testify/assert"
1212 "github.com/stretchr/testify/require"
1313
14+ "github.com/testcontainers/testcontainers-go"
1415 "github.com/testcontainers/testcontainers-go/modules/clickhouse"
16+ "github.com/testcontainers/testcontainers-go/wait"
1517)
1618
1719const (
@@ -21,6 +23,8 @@ const (
2123 clickhouseUser string = "default"
2224 clickhousePass string = "password"
2325 clickhouseDB string = "fiber"
26+ clickhouseHttpPort = "8123/tcp"
27+ clickhouseSuccessCode = 200
2428)
2529
2630func getTestConnection (t testing.TB , cfg Config ) (* Storage , error ) {
@@ -38,7 +42,16 @@ func getTestConnection(t testing.TB, cfg Config) (*Storage, error) {
3842 clickhouse .WithUsername (clickhouseUser ),
3943 clickhouse .WithPassword (clickhousePass ),
4044 clickhouse .WithDatabase (clickhouseDB ),
45+ testcontainers .WithWaitStrategy (
46+ wait .ForAll (
47+ wait .ForListeningPort (clickhouseHttpPort ),
48+ wait .NewHTTPStrategy ("/" ).WithPort (clickhouseHttpPort ).WithStatusCodeMatcher (func (status int ) bool {
49+ return status == clickhouseSuccessCode
50+ }),
51+ ),
52+ ),
4153 )
54+ testcontainers .CleanupContainer (t , c )
4255 if err != nil {
4356 return nil , err
4457 }
@@ -67,13 +80,14 @@ func getTestConnection(t testing.TB, cfg Config) (*Storage, error) {
6780}
6881
6982func Test_Connection (t * testing.T ) {
70- _ , err := getTestConnection (t , Config {
83+ client , err := getTestConnection (t , Config {
7184 Engine : Memory ,
7285 Table : "test_table" ,
7386 Clean : true ,
7487 })
75-
7688 require .NoError (t , err )
89+
90+ defer client .Close ()
7791}
7892
7993func Test_Set (t * testing.T ) {
@@ -191,6 +205,17 @@ func Test_Reset(t *testing.T) {
191205 assert .Equal (t , []byte {}, value )
192206}
193207
208+ func TestClose_ShouldReturn_NoError (t * testing.T ) {
209+ client , err := getTestConnection (t , Config {
210+ Engine : Memory ,
211+ Table : "test_table" ,
212+ Clean : true ,
213+ })
214+ require .NoError (t , err )
215+
216+ require .NoError (t , client .Close ())
217+ }
218+
194219func Benchmark_Clickhouse_Set (b * testing.B ) {
195220 b .ReportAllocs ()
196221 b .ResetTimer ()
0 commit comments