Skip to content

Commit

Permalink
Adding surrealDB module (#2192)
Browse files Browse the repository at this point in the history
* Adding surrealDB module

* go mod tidy

* Replacing panics with log.Fatal

* go mod tidy

* Fixing linter errors

* Addressing PR review comments

* chore: bump Go to 1.21

* fix: typo

* fix: update comments

* docs: document options

* fix: wrong copy&paste

* fix: wrong copy&paste

* chore: bump testcontainers-go to latest

* chore: run mod tidy

---------

Co-authored-by: Manuel de la Peña <mdelapenya@gmail.com>
Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>
  • Loading branch information
3 people committed Mar 4, 2024
1 parent e6d6659 commit cf17a02
Show file tree
Hide file tree
Showing 12 changed files with 629 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ updates:
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/surrealdb
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/vault
schedule:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
matrix:
go-version: [1.21.x, 1.x]
platform: [ubuntu-latest]
module: [artemis, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, elasticsearch, gcloud, inbucket, k3s, k6, kafka, localstack, mariadb, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, vault, weaviate]
module: [artemis, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, elasticsearch, gcloud, inbucket, k3s, k6, kafka, localstack, mariadb, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, surrealdb, vault, weaviate]
uses: ./.github/workflows/ci-test-go.yml
with:
go-version: ${{ matrix.go-version }}
Expand Down
4 changes: 4 additions & 0 deletions .vscode/.testcontainers-go.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@
"name": "module / redpanda",
"path": "../modules/redpanda"
},
{
"name": "module / surrealdb",
"path": "../modules/surrealdb"
},
{
"name": "module / vault",
"path": "../modules/vault"
Expand Down
74 changes: 74 additions & 0 deletions docs/modules/surrealdb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# SurrealDB

Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

## Introduction

The Testcontainers module for SurrealDB.

## Adding this module to your project dependencies

Please run the following command to add the SurrealDB module to your Go dependencies:

```
go get github.com/testcontainers/testcontainers-go/modules/surrealdb
```

## Usage example

<!--codeinclude-->
[Creating a SurrealDB container](../../modules/surrealdb/examples_test.go) inside_block:runSurrealDBContainer
<!--/codeinclude-->

## Module reference

The SurrealDB module exposes one entrypoint function to create the SurrealDB container, and this function receives two parameters:

```golang
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*SurrealDBContainer, error)
```

- `context.Context`, the Go context.
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.

### Container Options

When starting the SurrealDB container, you can pass options in a variadic way to configure it.

#### Image

If you need to set a different SurrealDB Docker image, you can use `testcontainers.WithImage` with a valid Docker image
for SurrealDB. E.g. `testcontainers.WithImage("surrealdb/surrealdb:v1.1.1")`.

{% include "../features/common_functional_options.md" %}

#### Set username and password

If you need to set different credentials, you can use `WithUsername` and `WithPassword` options.

!!!info
The default values for the username and the password is `root`.

#### WithAuthentication

If you need to enable authentication, you can use `WithAuthentication` option. By default, it is disabled.

#### WithStrictMode

If you need to enable the strict mode for SurrealDB, you can use `WithStrictMode` option. By default, it is disabled.

### WithAllowAllCaps

If you need to enable the all caps mode for SurrealDB, you can use `WithAllowAllCaps` option. By default, it is disabled.

### Container Methods

The SurrealDB container exposes the following methods:

#### URL

This method returns the websocket URL string to connect to the SurrealDB API, using the `8000` port.

<!--codeinclude-->
[Get websocket URL string](../../modules/surrealdb/surrealdb_test.go) inside_block:websocketURL
<!--/codeinclude-->
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ nav:
- modules/rabbitmq.md
- modules/redis.md
- modules/redpanda.md
- modules/surrealdb.md
- modules/vault.md
- modules/weaviate.md
- Examples:
Expand Down
5 changes: 5 additions & 0 deletions modules/surrealdb/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ../../commons-test.mk

.PHONY: test
test:
$(MAKE) test-surrealdb
38 changes: 38 additions & 0 deletions modules/surrealdb/examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package surrealdb_test

import (
"context"
"fmt"
"log"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/surrealdb"
)

func ExampleRunContainer() {
// runSurrealDBContainer {
ctx := context.Background()

surrealdbContainer, err := surrealdb.RunContainer(ctx, testcontainers.WithImage("surrealdb/surrealdb:v1.1.1"))
if err != nil {
log.Fatal(err)
}

// Clean up the container
defer func() {
if err := surrealdbContainer.Terminate(ctx); err != nil {
log.Fatal(err)
}
}()
// }

state, err := surrealdbContainer.State(ctx)
if err != nil {
log.Fatal(err) // nolint:gocritic
}

fmt.Println(state.Running)

// Output:
// true
}
62 changes: 62 additions & 0 deletions modules/surrealdb/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module github.com/testcontainers/testcontainers-go/modules/surrealdb

go 1.21

require (
github.com/surrealdb/surrealdb.go v0.2.1
github.com/testcontainers/testcontainers-go v0.28.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/containerd v1.7.12 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.3+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/tools v0.10.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)

replace github.com/testcontainers/testcontainers-go => ../..
Loading

0 comments on commit cf17a02

Please sign in to comment.