-
-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create couchbase module * expose enabled service ports * add wait until all nodes are healthy * add cluster initialization functions * refactor enabledServices for loop with contains method * add configureExternalPorts * refactor doHttpRequest to create new request with context * add create buckets * complete create bucket flow * add docker image name to config * fix port suffix, mapped port, enabled services and refactor checkAllServicesEnabled with gjson * add initCluster method * refactor bucket definition * update module name * add ConnectionString, Username, Password for test case and fix configure external port * add test * goimports and go mod tidy * fix: use modules instead of example * change WithBasicCredentials with WithBasicAuth * add test for community edition * fix eventing service with community container test * update depandabot.yml and go.mod * update couchbase doc * reorder modules couchbase dependabot.yml * Update modules/couchbase/go.mod Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com> * add comments for public methods * add option for index storage mode * add comments for index storage modes --------- Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>
- Loading branch information
1 parent
a0293bf
commit f90c104
Showing
14 changed files
with
1,380 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Couchbase module pipeline | ||
|
||
on: [push, pull_request] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test-couchbase: | ||
strategy: | ||
matrix: | ||
go-version: [1.18.x, 1.x] | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v3 | ||
|
||
- name: modVerify | ||
working-directory: ./modules/couchbase | ||
run: go mod verify | ||
|
||
- name: modTidy | ||
working-directory: ./modules/couchbase | ||
run: make tools-tidy | ||
|
||
- name: gotestsum | ||
working-directory: ./modules/couchbase | ||
run: make test-unit | ||
|
||
- name: Run checker | ||
run: | | ||
./scripts/check_environment.sh | ||
- name: Test Summary | ||
uses: test-summary/action@4ee9ece4bca777a38f05c8fc578ac2007fe266f7 | ||
with: | ||
paths: "**/TEST-couchbase*.xml" | ||
if: always() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Couchbase | ||
|
||
<img src="https://cdn.worldvectorlogo.com/logos/couchbase.svg" width="300" /> | ||
|
||
Testcontainers module for Couchbase. [Couchbase](https://www.couchbase.com/) is a document oriented NoSQL database. | ||
|
||
## Adding this module to your project dependencies | ||
|
||
Please run the following command to add the Couchbase module to your Go dependencies: | ||
|
||
``` | ||
go get github.com/testcontainers/testcontainers-go/modules/couchbase | ||
``` | ||
|
||
## Usage example | ||
|
||
1. The **StartContainer** function is the main entry point to create a new CouchbaseContainer instance. | ||
It takes a context and zero or more Option values to configure the container. | ||
It creates a new container instance, initializes the couchbase cluster, and creates buckets. | ||
If successful, it returns the **CouchbaseContainer** instance. | ||
```go | ||
container, err := couchbase.StartContainer(ctx, | ||
WithImageName("couchbase:community-7.1.1"), | ||
WithBucket(NewBucket(bucketName))) | ||
``` | ||
2. The **ConnectionString** method returns the connection string to connect to the Couchbase container instance. | ||
It returns a string with the format `couchbase://<host>:<port>`. | ||
The **Username** method returns the username of the Couchbase administrator. | ||
The **Password** method returns the password of the Couchbase administrator. | ||
```go | ||
connectionString, err := container.ConnectionString(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cluster, err := gocb.Connect(connectionString, gocb.ClusterOptions{ | ||
Username: container.Username(), | ||
Password: container.Password(), | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include ../../commons-test.mk | ||
|
||
.PHONY: test | ||
test: | ||
$(MAKE) test-couchbase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package couchbase | ||
|
||
type bucket struct { | ||
name string | ||
flushEnabled bool | ||
queryPrimaryIndex bool | ||
quota int | ||
numReplicas int | ||
} | ||
|
||
func NewBucket(name string) bucket { | ||
return bucket{ | ||
name: name, | ||
flushEnabled: false, | ||
queryPrimaryIndex: true, | ||
quota: 100, | ||
numReplicas: 0, | ||
} | ||
} | ||
|
||
func (b bucket) WithReplicas(numReplicas int) bucket { | ||
if numReplicas < 0 { | ||
numReplicas = 0 | ||
} else if numReplicas > 3 { | ||
numReplicas = 3 | ||
} | ||
|
||
b.numReplicas = numReplicas | ||
return b | ||
} | ||
|
||
func (b bucket) WithFlushEnabled(flushEnabled bool) bucket { | ||
b.flushEnabled = flushEnabled | ||
return b | ||
} | ||
|
||
func (b bucket) WithQuota(quota int) bucket { | ||
if quota < 100 { | ||
quota = 100 | ||
} | ||
|
||
b.quota = quota | ||
return b | ||
} | ||
|
||
func (b bucket) WithPrimaryIndex(primaryIndex bool) bucket { | ||
b.queryPrimaryIndex = primaryIndex | ||
return b | ||
} |
Oops, something went wrong.