Skip to content

Commit

Permalink
Added TestWithInstanceWithoutClient
Browse files Browse the repository at this point in the history
  • Loading branch information
mbobrovskyi committed Feb 12, 2023
1 parent 2d91750 commit e764e1d
Showing 1 changed file with 63 additions and 12 deletions.
75 changes: 63 additions & 12 deletions database/bigquery/bigquery_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package bigquery

import (
"context"
"errors"
"github.com/golang-migrate/migrate/v4/database"
"strings"
"testing"
Expand All @@ -22,14 +24,35 @@ func openConnection() (database.Driver, error) {
return driver, nil
}

func TestWithInstanceWithoutClient(t *testing.T) {
driver, err := WithInstance(context.Background(), nil, &Config{})
if err == nil {
t.Errorf("expected `no client`, got nil")
return
}
if !errors.Is(err, ErrNoClient) {
t.Errorf("expected `no client`, got %s", err.Error())
return
}
if driver != nil {
t.Errorf("driver should be nil")
return
}
}

func TestOpen(t *testing.T) {
driver, err := openConnection()
if err != nil {
t.Error(err)
return
}

defer driver.Close()
defer func() {
err := driver.Close()
if err != nil {
t.Error(err)
}
}()
}

func TestClose(t *testing.T) {
Expand All @@ -39,7 +62,12 @@ func TestClose(t *testing.T) {
return
}

defer driver.Close()
defer func() {
err := driver.Close()
if err != nil {
t.Error(err)
}
}()

err = driver.Close()
if err != nil {
Expand All @@ -55,7 +83,12 @@ func TestVersion(t *testing.T) {
return
}

defer driver.Close()
defer func() {
err := driver.Close()
if err != nil {
t.Error(err)
}
}()

version, dirty, err := driver.Version()
if err != nil {
Expand All @@ -73,7 +106,12 @@ func TestSetVersion(t *testing.T) {
return
}

defer driver.Close()
defer func() {
err := driver.Close()
if err != nil {
t.Error(err)
}
}()

err = driver.SetVersion(-1, false)
if err != nil {
Expand All @@ -89,7 +127,12 @@ func TestDrop(t *testing.T) {
return
}

defer driver.Close()
defer func() {
err := driver.Close()
if err != nil {
t.Error(err)
}
}()

err = driver.Drop()
if err != nil {
Expand All @@ -105,7 +148,12 @@ func TestRun(t *testing.T) {
return
}

defer driver.Close()
defer func() {
err := driver.Close()
if err != nil {
t.Error(err)
}
}()

err = driver.Run(strings.NewReader(`
CREATE TABLE IF NOT EXISTS users (
Expand All @@ -125,18 +173,21 @@ func TestRunWithError(t *testing.T) {
return
}

defer driver.Close()
defer func() {
err := driver.Close()
if err != nil {
t.Error(err)
}
}()

err = driver.Run(strings.NewReader(`
CREATE TABLE IF NOT EXISTS users (
first_name STRINGa,
last_name STRING
)`))
if err != nil {
t.Log(err)
return
if err == nil {
t.Error("expected 'googleapi: Error 400: Query error: Type not found: STRINGa at [4:36], invalidQuery' got nil")
}

t.Error("error is nil, should be 'googleapi: Error 400: Query error: Type not found: STRINGa at [4:36], invalidQuery'")
return
t.Log(err)
}

0 comments on commit e764e1d

Please sign in to comment.