Skip to content

Commit

Permalink
Addressing PR review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jespino committed Feb 23, 2024
1 parent 6ce1ec1 commit 5d300e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
31 changes: 10 additions & 21 deletions modules/surrealdb/surrealdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand All @@ -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"},
Expand Down
16 changes: 8 additions & 8 deletions modules/surrealdb/surrealdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ func TestSurrealDBSelect(t *testing.T) {
}
})

// websocketURL {
url, err := container.URL(ctx)
// }
if err != nil {
t.Fatal(err)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -91,7 +85,9 @@ func TestSurrealDBNoAuth(t *testing.T) {
}
})

// websocketURL {
url, err := container.URL(ctx)
// }
if err != nil {
t.Fatal(err)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 5d300e2

Please sign in to comment.