couchbase

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

README

Venom - Executor couchbase

Step to execute actions on a couchbase database using github.com/couchbase/gocb/v2 sdk.

More information you can find here

Connection

To be possible use couchbase executor you need to specify at least the couchbase bucket (in case of no auth and running local).

A minimal couchbase configuration can be the following one:

- type: couchbase
  dsn:  "couchbase://localhost"         # connection string to connect to couchbase.
  username: "{{ .couchbase_username }}" # can be omitted
  password: "{{ .couchbase_password }}" # can be omitted
  bucket: "{{ .couchbase_bucket }}"     # mandatory

A complete couchbase configuration can be the following one

- type: couchbase
  dsn:  "couchbase://localhost"         # will use couchbase://localhost if omitted
  username: "{{ .couchbase_username }}" # can be omitted
  password: "{{ .couchbase_password }}" # can be omitted
  bucket: "{{ .couchbase_bucket }}"     # mandatory
  scope:  "_default"                    # can be omitted, default scope will be used
  collection: "_default"                # can be omitted, default collection will be used
  transcoder: "json"                    # can be omitted, "legacy" will be used
  expiry: 600                           # in seconds, can be omitted (no expiration by default)
  wait_until_ready_timeout: 5           # in seconds, can be 0 (means no wait until bucket is ready)
  profile_wan_development: true         # if true, will use high timeouts to avoid latency issues. default false.

The fields bucket, scope and collection are used as default values. Each action can define a different bucket, scope or collection to use locally.

For transcoder, you have the following options:

Input

See also tests/couchbase.yml for executable examples.

Couchbase can be used to store json structured data, but can store also binary and string types.

Example:

airline_01: # entries are specified as map id => content
  "id": 1
  "type": "airline"
  "name": "first airline"
  "country": "Latveria"
Load fixtures

Not implemented yet.

Retrieve documents

Get will retrieve documents by id. If the id can't be found the flag found will be false.

By using flag with_expiry the expiration of the given entry will be returned (or will be zero if no expiration).

by using flag expiry the get operation became get and touch and the option with_expiry will be ignored.

- type: couchbase
  dsn:  "{{ .couchbase_dsn }}"
  username: "{{ .couchbase_username }}"
  password: "{{ .couchbase_password }}"
  bucket: "travel-sample"
  actions:
    - type: get
      with_expiry: true
      ids: ["airline_10","airline_01"]
    assertions:
      - result.actions.actions0.airline_10.expiry ShouldBeZeroValue
      - result.actions.actions0.airline_10.data ShouldJSONEqual {"id":10,"type":"airline","name":"40-Mile Air","iata":"Q5","icao":"MLA","callsign":"MILE-AIR","country":"United States"}
      - result.actions.actions0.airline_01 ShouldNotBeNil
      - result.actions.actions0.airline_01.found ShouldBeFalse
Insert documents

Insert will create documents by id. If the id already exists the operation is not executed and the flag inserted will be false.

An expiration, in seconds, can be defined via field expiry to override the default expiry (if any)

- type: couchbase
  dsn:  "{{ .couchbase_dsn }}"
  username: "{{ .couchbase_username }}"
  password: "{{ .couchbase_password }}"
  bucket: "travel-sample"
  actions:
    - type: insert
      entries:
        airline_01:
          "id": 1
          "type": "airline"
          "name": "first airline"
          "country": "Latveria"
  assertions:
    - result.actions.actions0.airline_01.inserted ShouldBeTrue
Replace documents

Replace will update documents by id. If the id does not exist the operation is not executed and the flag replaced will be false.

It is possible to preserve the original expiration via boolean field preserve_expiry. An expiration, in seconds, can be defined via field expiry to override the default expiry (if any).

- type: couchbase
  dsn:  "{{ .couchbase_dsn }}"
  username: "{{ .couchbase_username }}"
  password: "{{ .couchbase_password }}"
  bucket: "travel-sample"
  actions:
    - type: replace
      entries:
        airline_01:
          "id": 1
          "type": "airline"
          "name": "first airline"
          "country": "Latveria"
  assertions:
    - result.actions.actions0.airline_01.replaced ShouldBeTrue
Upsert documents

Upsert will insert or documents by id. It will set the flag upserted to true

It is possible to preserve the original expiration (if any) via boolean field preserve_expiry.

- type: couchbase
  dsn:  "{{ .couchbase_dsn }}"
  username: "{{ .couchbase_username }}"
  password: "{{ .couchbase_password }}"
  bucket: "travel-sample"
  actions:
    - type: upsert
      entries:
        airline_01:
          "id": 1
          "type": "airline"
          "name": "first airline"
          "country": "Latveria"
  assertions:
    - result.actions.actions0.airline_01.upserted ShouldBeTrue

### Remove documents

Delete will remove by id. It will set the flag deleted to true in case the id has been found.

- type: couchbase
  dsn:  "{{ .couchbase_dsn }}"
  username: "{{ .couchbase_username }}"
  password: "{{ .couchbase_password }}"
  bucket: "travel-sample"
  actions:
    - type: delete
      ids: ["airline_01"]
  assertions:
    - result.actions.actions0.airline_01.deleted ShouldBeTrue
Touch documents

Touch will update the object expiration for a given id. It will set the flag touch to true in case the id has been found.

An expiry in seconds can be specified to be used. Unless it will use the global expiry.

- type: couchbase
  dsn:  "{{ .couchbase_dsn }}"
  username: "{{ .couchbase_username }}"
  password: "{{ .couchbase_password }}"
  bucket: "travel-sample"
  actions:
    - type: touch
      expiry: 3600    # 1 hour
      ids: ["airline_01"]
  assertions:
    - result.actions.actions0.airline_01.touched ShouldBeTrue
Check if document exists

The command exists check if the document id exists or not. It will set a boolean flag found with the status.

- type: couchbase
  dsn:  "{{ .couchbase_dsn }}"
  username: "{{ .couchbase_username }}"
  password: "{{ .couchbase_password }}"
  bucket: "travel-sample"
  actions:
    - type: exists
      ids: ["airline_10","airline_01"]
  assertions:
    - result.actions.actions0.airline_10.found ShouldBeTrue
    - result.actions.actions0.airline_01.found ShouldBeFalse

Documentation

Index

Constants

View Source
const (
	// Name of executor
	Name = "couchbase"
)

Variables

This section is empty.

Functions

func New

func New() venom.Executor

New returns a new Executor

Types

type Executor

type Executor struct {
	DSN        string   `json:"dsn"                  yaml:"dsn"                  mapstructure:"dsn"`
	Username   string   `json:"username,omitempty"   yaml:"username,omitempty"   mapstructure:"username"`
	Password   string   `json:"password,omitempty"   yaml:"password,omitempty"   mapstructure:"password"`
	Bucket     string   `json:"bucket"               yaml:"bucket"               mapstructure:"bucket"`
	Scope      string   `json:"scope,omitempty"      yaml:"scope,omitempty"      mapstructure:"scope"`
	Collection string   `json:"collection,omitempty" yaml:"collection,omitempty" mapstructure:"collection"`
	Transcoder string   `json:"transcoder,omitempty" yaml:"transcoder,omitempty" mapstructure:"transcoder"`
	Expiry     *float64 `json:"expiry,omitempty"     yaml:"expiry,omitempty"     mapstructure:"expiry"`

	WaitUntilReadyTimeout float64 `json:"wait_until_ready_timeout,omitempty" yaml:"wait_until_ready_timeout,omitempty" mapstructure:"wait_until_ready_timeout"`

	ProfileWanDevelopment bool `json:"profile_wan_development,omitempty" yaml:"profile_wan_development,omitempty" mapstructure:"profile_wan_development"`

	Actions []map[string]any `json:"actions,omitempty" yaml:"actions,omitempty" mapstructure:"actions"`
	// contains filtered or unexported fields
}

Executor represents a Test Exec

func (*Executor) Run

func (e *Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, error)

Run execute TestStep

func (*Executor) SetDefaults

func (e *Executor) SetDefaults()

type Result

type Result struct {
	Actions []any `json:"actions,omitempty" yaml:"actions,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL