diff --git a/modules/surrealdb/surrealdb.go b/modules/surrealdb/surrealdb.go index 81aeade5af..700a2579a7 100644 --- a/modules/surrealdb/surrealdb.go +++ b/modules/surrealdb/surrealdb.go @@ -48,36 +48,24 @@ func WithPassword(password string) testcontainers.CustomizeRequestOption { } } -// WithAuthentication enables or disables authentication for the SurrealDB instance -func WithAuthentication(enabled bool) testcontainers.CustomizeRequestOption { +// WithAuthentication enables authentication for the SurrealDB instance +func WithAuthentication() testcontainers.CustomizeRequestOption { return func(req *testcontainers.GenericContainerRequest) { - if enabled { - req.Env["SURREAL_AUTH"] = "true" - } else { - req.Env["SURREAL_AUTH"] = "false" - } + req.Env["SURREAL_AUTH"] = "true" } } // WithStrict enables or disables strict mode for the SurrealDB instance -func WithStrict(enabled bool) testcontainers.CustomizeRequestOption { +func WithStrictMode() testcontainers.CustomizeRequestOption { return func(req *testcontainers.GenericContainerRequest) { - if enabled { - req.Env["SURREAL_STRICT"] = "true" - } else { - req.Env["SURREAL_STRICT"] = "false" - } + req.Env["SURREAL_STRICT"] = "true" } } // WithAllowAllCaps enables or disables all caps for the SurrealDB instance -func WithAllowAllCaps(enabled bool) testcontainers.CustomizeRequestOption { +func WithAllowAllCaps() testcontainers.CustomizeRequestOption { return func(req *testcontainers.GenericContainerRequest) { - if enabled { - req.Env["SURREAL_CAPS_ALLOW_ALL"] = "true" - } else { - req.Env["SURREAL_CAPS_ALLOW_ALL"] = "false" - } + req.Env["SURREAL_CAPS_ALLOW_ALL"] = "false" } } @@ -88,8 +76,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize Env: map[string]string{ "SURREAL_USER": "root", "SURREAL_PASS": "root", - "SURREAL_AUTH": "true", - "SURREAL_CAPS_ALLOW_ALL": "true", + "SURREAL_AUTH": "false", + "SURREAL_STRICT": "false", + "SURREAL_CAPS_ALLOW_ALL": "false", "SURREAL_PATH": "memory", }, ExposedPorts: []string{"8000/tcp"}, diff --git a/modules/surrealdb/surrealdb_test.go b/modules/surrealdb/surrealdb_test.go index e300f39ee2..27ed38017b 100644 --- a/modules/surrealdb/surrealdb_test.go +++ b/modules/surrealdb/surrealdb_test.go @@ -24,9 +24,7 @@ func TestSurrealDBSelect(t *testing.T) { } }) - // websocketURL { url, err := container.URL(ctx) - // } if err != nil { t.Fatal(err) } @@ -37,10 +35,6 @@ func TestSurrealDBSelect(t *testing.T) { } defer db.Close() - if _, err := db.Signin(map[string]string{"user": "root", "pass": "root"}); err != nil { - t.Fatal(err) - } - if _, err := db.Use("test", "test"); err != nil { t.Fatal(err) } @@ -76,10 +70,10 @@ func TestSurrealDBSelect(t *testing.T) { } } -func TestSurrealDBNoAuth(t *testing.T) { +func TestSurrealDBWithAuth(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, testcontainers.WithImage("surrealdb/surrealdb:v1.1.1"), WithAuthentication(false)) + container, err := RunContainer(ctx, testcontainers.WithImage("surrealdb/surrealdb:v1.1.1"), WithAuthentication()) if err != nil { t.Fatal(err) } @@ -91,7 +85,9 @@ func TestSurrealDBNoAuth(t *testing.T) { } }) + // websocketURL { url, err := container.URL(ctx) + // } if err != nil { t.Fatal(err) } @@ -102,6 +98,10 @@ func TestSurrealDBNoAuth(t *testing.T) { } defer db.Close() + if _, err := db.Signin(map[string]string{"user": "root", "pass": "root"}); err != nil { + t.Fatal(err) + } + if _, err := db.Use("test", "test"); err != nil { t.Fatal(err) }