Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add couchbase module #876

Merged
merged 32 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
754c792
create couchbase module
alihanyalcin Feb 17, 2023
46ef6c7
expose enabled service ports
alihanyalcin Feb 17, 2023
5b355b5
add wait until all nodes are healthy
alihanyalcin Feb 17, 2023
953572f
add cluster initialization functions
alihanyalcin Feb 21, 2023
a6b2493
refactor enabledServices for loop with contains method
alihanyalcin Feb 21, 2023
9263849
add configureExternalPorts
alihanyalcin Feb 21, 2023
d5b4f15
refactor doHttpRequest to create new request with context
alihanyalcin Feb 21, 2023
0e43367
add create buckets
alihanyalcin Feb 21, 2023
c8b3714
complete create bucket flow
alihanyalcin Feb 22, 2023
b78012c
add docker image name to config
alihanyalcin Feb 22, 2023
becc912
fix port suffix, mapped port, enabled services and refactor checkAllS…
alihanyalcin Feb 24, 2023
ca30255
add initCluster method
alihanyalcin Feb 24, 2023
8744d2e
refactor bucket definition
alihanyalcin Feb 24, 2023
ea85e52
update module name
alihanyalcin Feb 24, 2023
c1d0914
add ConnectionString, Username, Password for test case and fix config…
alihanyalcin Feb 25, 2023
4badc7b
add test
alihanyalcin Feb 25, 2023
04443f1
goimports and go mod tidy
alihanyalcin Feb 25, 2023
88e6811
fix: use modules instead of example
mdelapenya Feb 27, 2023
9272120
Merge remote-tracking branch 'upstream/main'
alihanyalcin Feb 28, 2023
d42ed48
change WithBasicCredentials with WithBasicAuth
alihanyalcin Feb 28, 2023
a921729
add test for community edition
alihanyalcin Feb 28, 2023
b85dd3d
Merge remote-tracking branch 'upstream/main'
alihanyalcin Mar 2, 2023
effbe26
fix eventing service with community container test
alihanyalcin Mar 2, 2023
5b59b51
update depandabot.yml and go.mod
alihanyalcin Mar 2, 2023
2ed206a
update couchbase doc
alihanyalcin Mar 2, 2023
23b17e0
reorder modules couchbase dependabot.yml
alihanyalcin Mar 3, 2023
d86893a
Update modules/couchbase/go.mod
alihanyalcin Mar 7, 2023
e784d0b
add comments for public methods
alihanyalcin Mar 7, 2023
c11b7a1
Merge remote-tracking branch 'upstream/main'
alihanyalcin Mar 7, 2023
c596691
add option for index storage mode
alihanyalcin Mar 8, 2023
7b65ad0
add comments for index storage modes
alihanyalcin Mar 9, 2023
abef3b2
Merge remote-tracking branch 'upstream/main'
alihanyalcin Mar 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ updates:
interval: monthly
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/couchbase
schedule:
interval: monthly
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/localstack
schedule:
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/module-couchbase.yml
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()
40 changes: 40 additions & 0 deletions docs/modules/couchbase.md
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(),
})
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ nav:
- SQL: features/wait/sql.md
- Modules:
- modules/index.md
- modules/couchbase.md
- modules/localstack.md
- modules/pulsar.md
- Examples:
Expand Down
5 changes: 5 additions & 0 deletions modules/couchbase/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ../../commons-test.mk

.PHONY: test
test:
$(MAKE) test-couchbase
49 changes: 49 additions & 0 deletions modules/couchbase/bucket.go
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
}