Skip to content

Commit 3ad4e59

Browse files
committed
Add yugabyte-specific test file
1 parent 21dece9 commit 3ad4e59

File tree

2 files changed

+100
-3
lines changed

2 files changed

+100
-3
lines changed

.github/workflows/main.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ on:
44
push:
55
branches:
66
- master
7+
- ci-test
78
pull_request:
8-
types: [ opened, synchronize, reopened ]
9+
types: [opened, synchronize, reopened]
910

1011
env:
1112
CCM_VERSION: "6e71061146f7ae67b84ccd2b1d90d7319b640e4c"
@@ -16,7 +17,7 @@ jobs:
1617
runs-on: ubuntu-latest
1718
strategy:
1819
matrix:
19-
go: [ '1.19', '1.20' ]
20+
go: ["1.19", "1.20"]
2021
steps:
2122
- uses: actions/checkout@v3
2223
- uses: actions/setup-go@v4
@@ -32,7 +33,6 @@ jobs:
3233
name: Integration Tests
3334
runs-on: ubuntu-latest
3435
strategy:
35-
fail-fast: false
3636
matrix:
3737
go: [ '1.19', '1.20' ]
3838
cassandra_version: [ '4.0.8', '4.1.1' ]
@@ -199,3 +199,30 @@ jobs:
199199
run: |
200200
export JVM_EXTRA_OPTS="${{env.JVM_EXTRA_OPTS}}"
201201
go test -v -run=TestAuthentication -tags "${{ matrix.tags }} gocql_debug" -timeout=15s -runauth ${{ env.args }}
202+
integration-yugabyte:
203+
timeout-minutes: 10
204+
needs:
205+
- build
206+
name: Integration Tests (Yugabyte)
207+
runs-on: ubuntu-latest
208+
strategy:
209+
matrix:
210+
go: [ '1.19', '1.20' ]
211+
steps:
212+
- uses: actions/checkout@v2
213+
- uses: actions/setup-go@v2
214+
with:
215+
go-version: ${{ matrix.go }}
216+
- uses: actions/cache@v2
217+
id: gomod-cache
218+
with:
219+
path: ~/go/pkg/mod
220+
key: ${{ runner.os }}-go-${{ hashFiles('go.mod') }}
221+
restore-keys: |
222+
${{ runner.os }}-go-
223+
- name: Setup YugabyteDB cluster
224+
uses: jameshartig/yugabyte-db-action@master
225+
id: yb
226+
- name: Integration tests
227+
run: |
228+
go test -tags "yugabyte gocql_debug" -timeout=5m -race ./...

yugabyte_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//go:build yugabyte
2+
// +build yugabyte
3+
4+
package gocql
5+
6+
import (
7+
"bytes"
8+
"testing"
9+
)
10+
11+
func TestJSONB(t *testing.T) {
12+
session := createSession(t)
13+
defer session.Close()
14+
15+
defer func() {
16+
err := createTable(session, "DROP TABLE IF EXISTS gocql_test.jsonb")
17+
if err != nil {
18+
t.Logf("failed to delete jsonb table: %v", err)
19+
}
20+
}()
21+
22+
if err := createTable(session, "CREATE TABLE gocql_test.jsonb (id int, my_jsonb jsonb, PRIMARY KEY (id))"); err != nil {
23+
t.Fatalf("failed to create table with error '%v'", err)
24+
}
25+
26+
b := session.NewBatch(LoggedBatch)
27+
b.Query("INSERT INTO gocql_test.jsonb(id, my_jsonb) VALUES (?,?)", 1, []byte("true"))
28+
b.Query("INSERT INTO gocql_test.jsonb(id, my_jsonb) VALUES (?,?)", 2, []byte(`{"foo":"bar"}`))
29+
30+
if err := session.ExecuteBatch(b); err != nil {
31+
t.Fatalf("query failed. %v", err)
32+
} else {
33+
if b.Attempts() < 1 {
34+
t.Fatal("expected at least 1 attempt, but got 0")
35+
}
36+
if b.Latency() <= 0 {
37+
t.Fatalf("expected latency to be greater than 0, but got %v instead.", b.Latency())
38+
}
39+
}
40+
41+
var id int
42+
var myJSONB []byte
43+
if err := session.Query("SELECT id, my_jsonb FROM gocql_test.jsonb WHERE id = 1;").Scan(&id, &myJSONB); err != nil {
44+
t.Fatalf("Failed to select with err: %v", err)
45+
} else if id != 1 {
46+
t.Fatalf("Expected id = 1, got %v", id)
47+
} else if !bytes.Equal(myJSONB, []byte("true")) {
48+
t.Fatalf("Expected my_jsonb = true, got %v", string(myJSONB))
49+
}
50+
51+
if err := session.Query("SELECT id, my_jsonb FROM gocql_test.jsonb WHERE id = 2;").Scan(&id, &myJSONB); err != nil {
52+
t.Fatalf("Failed to select with err: %v", err)
53+
} else if id != 2 {
54+
t.Fatalf("Expected id = 2, got %v", id)
55+
} else if !bytes.Equal(myJSONB, []byte(`{"foo":"bar"}`)) {
56+
t.Fatalf(`Expected my_jsonb = {"foo":"bar"}, got %v`, string(myJSONB))
57+
}
58+
59+
if rd, err := session.Query("SELECT id, my_jsonb FROM gocql_test.jsonb;").Iter().RowData(); err != nil {
60+
t.Fatalf("Failed to select with err: %v", err)
61+
} else if len(rd.Columns) != 2 || rd.Columns[0] != "id" || rd.Columns[1] != "my_jsonb" {
62+
t.Fatalf("Expected [id, my_jsonb], got %v", rd.Columns)
63+
} else if len(rd.Values) != 2 {
64+
t.Fatalf("Expected 2 values, got %v", rd.Values)
65+
} else if _, ok := rd.Values[0].(*int); !ok {
66+
t.Fatalf("Expected values[0] = *int, got %T", rd.Values[0])
67+
} else if _, ok := rd.Values[1].(*[]byte); !ok {
68+
t.Fatalf("Expected values[1] = *[]byte, got %T", rd.Values[1])
69+
}
70+
}

0 commit comments

Comments
 (0)