Skip to content

Commit 2c66f20

Browse files
mdelapenyamashail
andauthored
feat: add meilisearch-module (#2835)
* 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>
1 parent 235ab07 commit 2c66f20

File tree

13 files changed

+633
-2
lines changed

13 files changed

+633
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
matrix:
9595
go-version: [1.22.x, 1.x]
9696
platform: [ubuntu-latest]
97-
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]
97+
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]
9898
uses: ./.github/workflows/ci-test-go.yml
9999
with:
100100
go-version: ${{ matrix.go-version }}

.vscode/.testcontainers-go.code-workspace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@
105105
"name": "module / mariadb",
106106
"path": "../modules/mariadb"
107107
},
108+
{
109+
"name": "module / meilisearch",
110+
"path": "../modules/meilisearch"
111+
},
108112
{
109113
"name": "module / milvus",
110114
"path": "../modules/milvus"

docs/modules/meilisearch.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Meilisearch
2+
3+
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>
4+
5+
## Introduction
6+
7+
The Testcontainers module for Meilisearch.
8+
9+
## Adding this module to your project dependencies
10+
11+
Please run the following command to add the Meilisearch module to your Go dependencies:
12+
13+
```
14+
go get github.com/testcontainers/testcontainers-go/modules/meilisearch
15+
```
16+
17+
## Usage example
18+
19+
<!--codeinclude-->
20+
[Creating a Meilisearch container](../../modules/meilisearch/examples_test.go) inside_block:runMeilisearchContainer
21+
<!--/codeinclude-->
22+
23+
## Module Reference
24+
25+
### Run function
26+
27+
- 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>
28+
29+
The Meilisearch module exposes one entrypoint function to create the Meilisearch container, and this function receives three parameters:
30+
31+
```golang
32+
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MeilisearchContainer, error)
33+
```
34+
35+
- `context.Context`, the Go context.
36+
- `string`, the Docker image to use.
37+
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.
38+
39+
### Container Options
40+
41+
When starting the Meilisearch container, you can pass options in a variadic way to configure it.
42+
43+
#### Image
44+
45+
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.
46+
E.g. `Run(context.Background(), "getmeili/meilisearch:v1.10.3")`.
47+
48+
{% include "../features/common_functional_options.md" %}
49+
50+
#### Master Key
51+
52+
- 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>
53+
54+
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.
55+
56+
#### Dump Data
57+
58+
- 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>
59+
60+
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).
61+
62+
### Container Methods
63+
64+
The Meilisearch container exposes the following methods:
65+
66+
#### Address
67+
68+
- 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>
69+
70+
The `Address` method retrieves the address of the Meilisearch container.
71+
It will use http as protocol, as TLS is not supported at the moment.
72+
73+
#### MasterKey
74+
75+
- 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>
76+
77+
The `MasterKey` method retrieves the master key of the Meilisearch container.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ nav:
8888
- modules/kafka.md
8989
- modules/localstack.md
9090
- modules/mariadb.md
91+
- modules/meilisearch.md
9192
- modules/milvus.md
9293
- modules/minio.md
9394
- modules/mockserver.md

modules/meilisearch/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include ../../commons-test.mk
2+
3+
.PHONY: test
4+
test:
5+
$(MAKE) test-meilisearch
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package meilisearch_test
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
8+
"github.com/testcontainers/testcontainers-go"
9+
"github.com/testcontainers/testcontainers-go/modules/meilisearch"
10+
)
11+
12+
func ExampleRun() {
13+
// runMeilisearchContainer {
14+
ctx := context.Background()
15+
16+
meiliContainer, err := meilisearch.Run(
17+
ctx,
18+
"getmeili/meilisearch:v1.10.3",
19+
meilisearch.WithMasterKey("my-master-key"),
20+
meilisearch.WithDumpImport("testdata/movies.dump"),
21+
)
22+
defer func() {
23+
if err := testcontainers.TerminateContainer(meiliContainer); err != nil {
24+
log.Printf("failed to terminate container: %s", err)
25+
}
26+
}()
27+
if err != nil {
28+
log.Printf("failed to start container: %s", err)
29+
return
30+
}
31+
// }
32+
33+
state, err := meiliContainer.State(ctx)
34+
if err != nil {
35+
log.Printf("failed to get container state: %s", err)
36+
return
37+
}
38+
39+
fmt.Println(state.Running)
40+
fmt.Printf("%s\n", meiliContainer.MasterKey())
41+
42+
// Output:
43+
// true
44+
// my-master-key
45+
}

modules/meilisearch/go.mod

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
module github.com/testcontainers/testcontainers-go/modules/meilisearch
2+
3+
go 1.22
4+
5+
require (
6+
github.com/stretchr/testify v1.9.0
7+
github.com/testcontainers/testcontainers-go v0.33.0
8+
)
9+
10+
require (
11+
dario.cat/mergo v1.0.0 // indirect
12+
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 // indirect
13+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
14+
github.com/Microsoft/go-winio v0.6.2 // indirect
15+
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
16+
github.com/containerd/log v0.1.0 // indirect
17+
github.com/containerd/platforms v0.2.1 // indirect
18+
github.com/cpuguy83/dockercfg v0.3.2 // indirect
19+
github.com/davecgh/go-spew v1.1.1 // indirect
20+
github.com/distribution/reference v0.6.0 // indirect
21+
github.com/docker/docker v27.3.1+incompatible // indirect
22+
github.com/docker/go-connections v0.5.0 // indirect
23+
github.com/docker/go-units v0.5.0 // indirect
24+
github.com/felixge/httpsnoop v1.0.4 // indirect
25+
github.com/go-logr/logr v1.4.2 // indirect
26+
github.com/go-logr/stdr v1.2.2 // indirect
27+
github.com/go-ole/go-ole v1.2.6 // indirect
28+
github.com/gogo/protobuf v1.3.2 // indirect
29+
github.com/google/uuid v1.6.0 // indirect
30+
github.com/klauspost/compress v1.17.4 // indirect
31+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
32+
github.com/magiconair/properties v1.8.7 // indirect
33+
github.com/moby/docker-image-spec v1.3.1 // indirect
34+
github.com/moby/patternmatcher v0.6.0 // indirect
35+
github.com/moby/sys/sequential v0.5.0 // indirect
36+
github.com/moby/sys/user v0.1.0 // indirect
37+
github.com/moby/sys/userns v0.1.0 // indirect
38+
github.com/moby/term v0.5.0 // indirect
39+
github.com/morikuni/aec v1.0.0 // indirect
40+
github.com/opencontainers/go-digest v1.0.0 // indirect
41+
github.com/opencontainers/image-spec v1.1.0 // indirect
42+
github.com/pkg/errors v0.9.1 // indirect
43+
github.com/pmezard/go-difflib v1.0.0 // indirect
44+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
45+
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
46+
github.com/shoenig/go-m1cpu v0.1.6 // indirect
47+
github.com/sirupsen/logrus v1.9.3 // indirect
48+
github.com/tklauser/go-sysconf v0.3.12 // indirect
49+
github.com/tklauser/numcpus v0.6.1 // indirect
50+
github.com/yusufpapurcu/wmi v1.2.3 // indirect
51+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
52+
go.opentelemetry.io/otel v1.31.0 // indirect
53+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0 // indirect
54+
go.opentelemetry.io/otel/metric v1.31.0 // indirect
55+
go.opentelemetry.io/otel/sdk v1.31.0 // indirect
56+
go.opentelemetry.io/otel/trace v1.31.0 // indirect
57+
golang.org/x/crypto v0.24.0 // indirect
58+
golang.org/x/sys v0.26.0 // indirect
59+
golang.org/x/time v0.7.0 // indirect
60+
gopkg.in/yaml.v3 v3.0.1 // indirect
61+
)
62+
63+
replace github.com/testcontainers/testcontainers-go => ../..

0 commit comments

Comments
 (0)