-
-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathcassandra_test.go
More file actions
55 lines (46 loc) · 1.14 KB
/
cassandra_test.go
File metadata and controls
55 lines (46 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright © 2026 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package examples_test
import (
"strconv"
"testing"
"time"
"github.com/gocql/gocql"
"github.com/ory/dockertest/v4"
)
func TestCassandra(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
pool := dockertest.NewPoolT(t, "")
cassandra := pool.RunT(t, "cassandra",
dockertest.WithTag("4"),
dockertest.WithEnv([]string{
"CASSANDRA_AUTHENTICATOR=PasswordAuthenticator",
}),
)
host := cassandra.GetBoundIP("9042/tcp")
port, err := strconv.Atoi(cassandra.GetPort("9042/tcp"))
if err != nil {
t.Fatalf("failed to parse port: %v", err)
}
err = pool.Retry(t.Context(), 120*time.Second, func() error {
cluster := gocql.NewCluster(host)
cluster.Port = port
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: "cassandra",
Password: "cassandra",
}
cluster.ProtoVersion = 4
session, err := cluster.CreateSession()
if err != nil {
return err
}
session.Close()
return nil
})
if err != nil {
t.Fatalf("Could not connect to Cassandra: %v", err)
}
t.Logf("Cassandra available at %s:%d", host, port)
}