Skip to content

Commit

Permalink
feat: add meilisearch-module (#2835)
Browse files Browse the repository at this point in the history
* feat: add meilisearch

* fix

* fix

* fix

* fix

* fix

* fix

* resolve comments

* chore: add module scaffolding

* resolve comments

* resolve comments

* add test

* docs: fix order

* chore: clear errors

* fix: use Go 1.22

* fix: run make lint

* chore: customize error

* docs: make explicit that dump files are used

* chore: address review comments

* fix: do not support updating the master key stored in the container

* chore: readability

* chore: not needed t.Run

* chore: use the variable

* chore: no need to defer

---------

Co-authored-by: Mashail 🌻 <malmuzaini@hudhud.sa>
Co-authored-by: Mashail Almuzaini <mashail_d@ymail.com>
  • Loading branch information
3 people authored Oct 21, 2024
1 parent 235ab07 commit 2c66f20
Show file tree
Hide file tree
Showing 13 changed files with 633 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
matrix:
go-version: [1.22.x, 1.x]
platform: [ubuntu-latest]
module: [artemis, azurite, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, databend, dolt, dynamodb, elasticsearch, etcd, gcloud, grafana-lgtm, inbucket, influxdb, k3s, k6, kafka, localstack, mariadb, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, ollama, openfga, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, registry, surrealdb, valkey, vault, vearch, weaviate, yugabytedb]
module: [artemis, azurite, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, databend, dolt, dynamodb, elasticsearch, etcd, gcloud, grafana-lgtm, inbucket, influxdb, k3s, k6, kafka, localstack, mariadb, meilisearch, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, ollama, openfga, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, registry, surrealdb, valkey, vault, vearch, weaviate, yugabytedb]
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 @@ -105,6 +105,10 @@
"name": "module / mariadb",
"path": "../modules/mariadb"
},
{
"name": "module / meilisearch",
"path": "../modules/meilisearch"
},
{
"name": "module / milvus",
"path": "../modules/milvus"
Expand Down
77 changes: 77 additions & 0 deletions docs/modules/meilisearch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Meilisearch

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 Meilisearch.

## Adding this module to your project dependencies

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

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

## Usage example

<!--codeinclude-->
[Creating a Meilisearch container](../../modules/meilisearch/examples_test.go) inside_block:runMeilisearchContainer
<!--/codeinclude-->

## Module Reference

### Run function

- 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>

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

```golang
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MeilisearchContainer, error)
```

- `context.Context`, the Go context.
- `string`, the Docker image to use.
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.

### Container Options

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

#### Image

If you need to set a different Meilisearch Docker image, you can set a valid Docker image as the second argument in the `Run` function.
E.g. `Run(context.Background(), "getmeili/meilisearch:v1.10.3")`.

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

#### Master Key

- 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>

If you need to set a master key, you can use the `WithMasterKey(key string)` option. Otherwise, the default will be used which is `just-a-master-key-for-test`, which is exported on the container fields.

#### Dump Data

- 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>

If you need to dump data in Meilisearch upon initialization for testing, you can use `WithDumpData(filepath string)` option where `filepath` can be an absolute path or relative path to a `dump` file. Please refer to the official Meilisearch documentation about dump files [here](https://www.meilisearch.com/docs/learn/advanced/snapshots_vs_dumps#dumps).

### Container Methods

The Meilisearch container exposes the following methods:

#### Address

- 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>

The `Address` method retrieves the address of the Meilisearch container.
It will use http as protocol, as TLS is not supported at the moment.

#### MasterKey

- 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>

The `MasterKey` method retrieves the master key of the Meilisearch container.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ nav:
- modules/kafka.md
- modules/localstack.md
- modules/mariadb.md
- modules/meilisearch.md
- modules/milvus.md
- modules/minio.md
- modules/mockserver.md
Expand Down
5 changes: 5 additions & 0 deletions modules/meilisearch/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ../../commons-test.mk

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

import (
"context"
"fmt"
"log"

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

func ExampleRun() {
// runMeilisearchContainer {
ctx := context.Background()

meiliContainer, err := meilisearch.Run(
ctx,
"getmeili/meilisearch:v1.10.3",
meilisearch.WithMasterKey("my-master-key"),
meilisearch.WithDumpImport("testdata/movies.dump"),
)
defer func() {
if err := testcontainers.TerminateContainer(meiliContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
// }

state, err := meiliContainer.State(ctx)
if err != nil {
log.Printf("failed to get container state: %s", err)
return
}

fmt.Println(state.Running)
fmt.Printf("%s\n", meiliContainer.MasterKey())

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

go 1.22

require (
github.com/stretchr/testify v1.9.0
github.com/testcontainers/testcontainers-go v0.33.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v27.3.1+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.4 // indirect
github.com/go-logr/logr v1.4.2 // 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/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/docker-image-spec v1.3.1 // 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/sys/userns 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/pmezard/go-difflib v1.0.0 // 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.49.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/otel/sdk v1.31.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/time v0.7.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

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

0 comments on commit 2c66f20

Please sign in to comment.