Skip to content

Commit

Permalink
add test case including Change Stream because Change Stream has been …
Browse files Browse the repository at this point in the history
…already supported in cloud-spanner-emulator
  • Loading branch information
nktks committed Feb 7, 2024
1 parent 28aed01 commit 87f2e20
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
services:
emulator:
image: gcr.io/cloud-spanner-emulator/emulator:1.5.0
image: gcr.io/cloud-spanner-emulator/emulator:1.5.14
ports:
- 9010:9010
- 9020:9020
Expand Down
48 changes: 32 additions & 16 deletions pkg/spanner/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"context"
"fmt"
"os"
"strings"
"testing"

"cloud.google.com/go/spanner"
Expand Down Expand Up @@ -59,30 +60,45 @@ const (
envSpannerInstanceID = "SPANNER_INSTANCE_ID"
envSpannerDatabaseID = "SPANNER_DATABASE_ID"
envSpannerEmulatorHost = "SPANNER_EMULATOR_HOST"
skipChangeStream = false
)

func TestLoadDDL(t *testing.T) {
t.Parallel()
ctx := context.Background()
t.Run("all", func(t *testing.T) {
ctx := context.Background()

client, done := testClientWithDatabase(t, ctx)
defer done()
client, done := testClientWithDatabase(t, ctx)
defer done()

// we can't include Change Stream schema to testdata because cloud-spanner-emulator hasn't supported it yet.
gotDDL, err := client.LoadDDL(ctx, skipChangeStream)
if err != nil {
t.Fatalf("failed to load ddl: %v", err)
}
gotDDL, err := client.LoadDDL(ctx, false)
if err != nil {
t.Fatalf("failed to load ddl: %v", err)
}

wantDDL, err := os.ReadFile("testdata/schema.sql")
if err != nil {
t.Fatalf("failed to read ddl file: %v", err)
}
wantDDL, err := os.ReadFile("testdata/schema.sql")
if err != nil {
t.Fatalf("failed to read ddl file: %v", err)
}

if want, got := string(wantDDL), string(gotDDL); want != got {
t.Errorf("want: \n%s\n but got: \n%s", want, got)
}
if want, got := string(wantDDL), string(gotDDL); want != got {
t.Errorf("want: \n%s\n but got: \n%s", want, got)
}
})
t.Run("skip change stream", func(t *testing.T) {
ctx := context.Background()

client, done := testClientWithDatabase(t, ctx)
defer done()

gotDDL, err := client.LoadDDL(ctx, true)
if err != nil {
t.Fatalf("failed to load ddl: %v", err)
}

if got := string(gotDDL); strings.Contains(got, "CREATE CHANGE STREAM") {
t.Errorf("got DDL includes Change Stream DDL. got: \n%s", got)
}
})
}

func TestApplyDDLFile(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/spanner/testdata/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ CREATE TABLE Singers (
SingerID STRING(36) NOT NULL,
FirstName STRING(1024),
) PRIMARY KEY(SingerID);

CREATE CHANGE STREAM EverythingStream FOR ALL;

0 comments on commit 87f2e20

Please sign in to comment.