Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(test): de-duplicate the Oracle test helpers two PRs each added (#21681)

Danny Xu9f3e99e8bf14
diff --git a/backend/common/testcontainer/shared.go b/backend/common/testcontainer/shared.go
index 685e92605c..b523ba2943 100644
--- a/backend/common/testcontainer/shared.go
+++ b/backend/common/testcontainer/shared.go
@@ -109,7 +109,8 @@ func SharedTiDBContainer(t testing.TB) *Container { return shared(t, sharedTiDB)
func SharedMongoDBContainer(t testing.TB) *Container { return shared(t, sharedMongo) }
// SharedOracleContainer is SharedPgContainer for Oracle, reached through
-// OracleServiceName; tests take a schema each with NewOracleSchema.
+// OracleServiceName; tests take a schema each with NewOracleSchema. Its admin
+// user is a DBA.
func SharedOracleContainer(t testing.TB) *Container { return shared(t, sharedOracle) }
// SharedMariaDBContainer is SharedPgContainer for MariaDB 11.8; tests take a
@@ -120,28 +121,6 @@ func SharedMariaDBContainer(t testing.TB) *Container { return shared(t, sharedMa
// oldest supported release; tests take a database each with NewMariaDB107Database.
func SharedMariaDB107Container(t testing.TB) *Container { return shared(t, sharedMariaDB107) }
-// SharedOracleContainer is SharedPgContainer for Oracle; tests take a schema
-// each with NewOracleSchema. Its admin user is a DBA.
-func SharedOracleContainer(t testing.TB) *Container { return shared(t, sharedOracle) }
-
-// NewOracleSchema creates an empty schema for the test on the shared Oracle
-// container and returns the container with the schema's name. An Oracle schema
-// is a user; this one may own the tables and materialized views the admin
-// creates in it.
-func NewOracleSchema(t testing.TB) (*Container, string) {
- t.Helper()
- container := SharedOracleContainer(t)
- name := strings.ToUpper(newDatabaseName())
- for _, statement := range []string{
- fmt.Sprintf(`CREATE USER %s IDENTIFIED BY "%s" QUOTA UNLIMITED ON USERS`, name, container.GetPassword()),
- fmt.Sprintf(`GRANT CREATE SESSION, CREATE TABLE, CREATE MATERIALIZED VIEW TO %s`, name),
- } {
- _, err := container.GetDB().Exec(statement)
- require.NoError(t, err)
- }
- return container, name
-}
-
// NewPgDatabase creates an empty database for the test on the shared
// PostgreSQL container and returns its name with a superuser handle to it.
// Anything cluster-wide the test creates, such as a role, should be named
@@ -212,13 +191,24 @@ func NewMongoDatabase(t testing.TB) (*Container, string) {
// NewOracleSchema creates an empty schema for the test on the shared Oracle
// container and returns the container with the schema's name. The schema is a
-// user that can't sign in, with quota for the objects the admin creates in it.
+// user that cannot sign in, with quota for the objects the admin creates in it.
+//
+// It is granted what it must own rather than what it may do: Oracle checks the
+// schema owner's privileges for some of what the admin creates there, a
+// materialized view among them, which fails with ORA-01031 without this. The
+// grants a session would need are left out, since this user has no way to open
+// one.
func NewOracleSchema(t testing.TB) (*Container, string) {
t.Helper()
container := SharedOracleContainer(t)
name := strings.ToUpper(newDatabaseName())
- _, err := container.GetDB().Exec(fmt.Sprintf("CREATE USER %s NO AUTHENTICATION QUOTA UNLIMITED ON USERS", name))
- require.NoError(t, err)
+ for _, statement := range []string{
+ fmt.Sprintf("CREATE USER %s NO AUTHENTICATION QUOTA UNLIMITED ON USERS", name),
+ fmt.Sprintf("GRANT CREATE TABLE, CREATE MATERIALIZED VIEW TO %s", name),
+ } {
+ _, err := container.GetDB().Exec(statement)
+ require.NoError(t, err)
+ }
return container, name
}
diff --git a/backend/common/testcontainer/testcontainer.go b/backend/common/testcontainer/testcontainer.go
index 4c616e6714..e42e6afec8 100644
--- a/backend/common/testcontainer/testcontainer.go
+++ b/backend/common/testcontainer/testcontainer.go
@@ -337,31 +337,6 @@ func getTiDBContainer(ctx context.Context) (*Container, error) {
})
}
-// OracleServiceName is the pluggable database the Oracle container's tests connect to.
-const OracleServiceName = "FREEPDB1"
-
-// getOracleContainer starts Oracle Database Free. The admin handle signs in as
-// SYSTEM, which may create users and objects in any schema; the caller's test
-// binary must link go-ora, which registers the "oracle" driver.
-func getOracleContainer(ctx context.Context) (*Container, error) {
- const user, password = "SYSTEM", "Test123"
- return start(ctx, testcontainers.ContainerRequest{
- Image: "gvenzl/oracle-free:23.26.3-slim-faststart",
- Env: map[string]string{
- "ORACLE_PASSWORD": password,
- },
- WaitingFor: wait.ForLog("DATABASE IS READY TO USE!").WithStartupTimeout(5 * time.Minute),
- }, spec{
- port: "1521/tcp",
- username: user,
- password: password,
- driver: "oracle",
- dsn: func(c *Container) string {
- return fmt.Sprintf("oracle://%s:%s@%s:%s/%s", c.username, c.password, c.host, c.port, OracleServiceName)
- },
- })
-}
-
// getMongoDBContainer starts MongoDB, which has no database/sql driver: its
// tests open the Mongo driver themselves from the container's credentials.
func getMongoDBContainer(ctx context.Context) (*Container, error) {
@@ -381,10 +356,15 @@ func getMongoDBContainer(ctx context.Context) (*Container, error) {
}
// OracleServiceName is the pluggable database the Oracle container serves.
+// OracleServiceName is the pluggable database the Oracle container's tests
+// connect to.
const OracleServiceName = "FREEPDB1"
-// getOracleContainer starts Oracle AI Database 26ai Free. The connect timeout
-// makes a listener that never answers fail each ping instead of hanging it.
+// getOracleContainer starts Oracle Database Free. Its admin handle signs in as
+// SYSTEM, which may create users and objects in any schema; the caller's test
+// binary must link go-ora, which registers the "oracle" driver. The connect
+// timeout makes a listener that never answers fail each ping instead of
+// hanging it.
func getOracleContainer(ctx context.Context) (*Container, error) {
const password = "test-Passw0rd"
return start(ctx, testcontainers.ContainerRequest{