Skip to content

Commit

Permalink
add according testcase for adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusheine committed Dec 11, 2023
1 parent 8c61b47 commit 2192c6b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 5 deletions.
14 changes: 13 additions & 1 deletion adapters/couchdb_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/go-kivik/kivik/v4"
)

func TestCouchDB(t *testing.T) {
func prepareCouchDB(t *testing.T) (context.Context, adapters.DatabaseAdapter, ClientConnectTest) {
databaseHost := "localhost"
databasePort := "5984"

Expand All @@ -32,5 +32,17 @@ func TestCouchDB(t *testing.T) {
return err
}

return ctx, adapter, clientConnectTest
}

func TestCouchDB(t *testing.T) {
ctx, adapter, clientConnectTest := prepareCouchDB(t)

testHelper(t, ctx, adapter, clientConnectTest)
}

func TestCouchDBCleanup(t *testing.T) {
ctx, adapter, _ := prepareCouchDB(t)

cleanupTestHelper(t, ctx, adapter)
}
14 changes: 13 additions & 1 deletion adapters/mongo_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"go.mongodb.org/mongo-driver/mongo/options"
)

func TestMongoDB(t *testing.T) {
func prepareMongoDB(t *testing.T) (context.Context, adapters.DatabaseAdapter, ClientConnectTest) {
databaseHost := "localhost"
databasePort := "27017"

Expand All @@ -34,5 +34,17 @@ func TestMongoDB(t *testing.T) {
return err
}

return ctx, adapter, clientConnectTest
}

func TestMongoDB(t *testing.T) {
ctx, adapter, clientConnectTest := prepareMongoDB(t)

testHelper(t, ctx, adapter, clientConnectTest)
}

func TestMongoDBCleanup(t *testing.T) {
ctx, adapter, _ := prepareMongoDB(t)

cleanupTestHelper(t, ctx, adapter)
}
14 changes: 13 additions & 1 deletion adapters/mssql_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/anbraten/k8s-external-database-operator/adapters"
)

func TestMsSqlDB(t *testing.T) {
func prepareMsSqlDB(t *testing.T) (context.Context, adapters.DatabaseAdapter, ClientConnectTest) {
databaseHost := "localhost"
databasePort := "1433"

Expand All @@ -32,5 +32,17 @@ func TestMsSqlDB(t *testing.T) {
return err
}

return ctx, adapter, clientConnectTest
}

func TestMsSqlDB(t *testing.T) {
ctx, adapter, clientConnectTest := prepareMsSqlDB(t)

testHelper(t, ctx, adapter, clientConnectTest)
}

func TestMsSqlDBCleanup(t *testing.T) {
ctx, adapter, _ := prepareMsSqlDB(t)

cleanupTestHelper(t, ctx, adapter)
}
14 changes: 13 additions & 1 deletion adapters/mysql_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/anbraten/k8s-external-database-operator/adapters"
)

func TestMySqlDB(t *testing.T) {
func prepareMySqlDB(t *testing.T) (context.Context, adapters.DatabaseAdapter, ClientConnectTest) {
databaseHost := "localhost"
databasePort := "3306"

Expand All @@ -32,5 +32,17 @@ func TestMySqlDB(t *testing.T) {
return err
}

return ctx, adapter, clientConnectTest
}

func TestMySqlDB(t *testing.T) {
ctx, adapter, clientConnectTest := prepareMySqlDB(t)

testHelper(t, ctx, adapter, clientConnectTest)
}

func TestMySqlDBCleanup(t *testing.T) {
ctx, adapter, _ := prepareMySqlDB(t)

cleanupTestHelper(t, ctx, adapter)
}
14 changes: 13 additions & 1 deletion adapters/postgres_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/jackc/pgx/v4"
)

func TestPostgresDB(t *testing.T) {
func preparePostgresDB(t *testing.T) (context.Context, adapters.DatabaseAdapter, ClientConnectTest) {
databaseHost := "localhost"
databasePort := "5432"

Expand All @@ -32,5 +32,17 @@ func TestPostgresDB(t *testing.T) {
return err
}

return ctx, adapter, clientConnectTest
}

func TestPostgresDB(t *testing.T) {
ctx, adapter, clientConnectTest := preparePostgresDB(t)

testHelper(t, ctx, adapter, clientConnectTest)
}

func TestPostgresDBCleanup(t *testing.T) {
ctx, adapter, _ := preparePostgresDB(t)

cleanupTestHelper(t, ctx, adapter)
}
10 changes: 10 additions & 0 deletions adapters/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ func testHelper(t *testing.T, ctx context.Context, adapter adapters.DatabaseAdap
t.Fatalf("Database user does not exists")
}
}

func cleanupTestHelper(t *testing.T, ctx context.Context, adapter adapters.DatabaseAdapter) {
result, err := adapter.HasDatabaseUserWithAccess(ctx, "non-existing-db", "non-existing-user")
if err != nil {
t.Fatalf("Checking for existing database user failed: %s", err)
}
if result {
t.Fatalf("database and user existing but expecting to be non-existing")
}
}

0 comments on commit 2192c6b

Please sign in to comment.