Documentation
¶
Index ¶
- Constants
- func NewBucket(name string) bucket
- func WithAdminCredentials(username, password string) credentialsCustomizer
- func WithBuckets(bucket ...bucket) bucketCustomizer
- func WithIndexStorage(indexStorageMode indexStorageMode) indexStorageCustomizer
- func WithServiceAnalytics() serviceCustomizer
- func WithServiceEventing() serviceCustomizer
- type Config
- type CouchbaseContainer
- func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*CouchbaseContainer, error)
- func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*CouchbaseContainer, error)deprecated
- func StartContainer(ctx context.Context, opts ...Option) (*CouchbaseContainer, error)
- type Option
- type Service
Examples ¶
Constants ¶
const ( MGMT_PORT = "8091" MGMT_SSL_PORT = "18091" VIEW_PORT = "8092" VIEW_SSL_PORT = "18092" QUERY_PORT = "8093" QUERY_SSL_PORT = "18093" SEARCH_PORT = "8094" SEARCH_SSL_PORT = "18094" ANALYTICS_PORT = "8095" ANALYTICS_SSL_PORT = "18095" EVENTING_PORT = "8096" EVENTING_SSL_PORT = "18096" KV_PORT = "11210" KV_SSL_PORT = "11207" )
const ( // MemoryOptimized sets the cluster-wide index storage mode to use memory optimized global // secondary indexes which can perform index maintenance and index scan faster at in-memory speeds. // This is the default value for the testcontainers couchbase implementation. MemoryOptimized indexStorageMode = "memory_optimized" // Plasma sets the cluster-wide index storage mode to use the Plasma storage engine, // which can utilize both memory and persistent storage for index maintenance and index scans. Plasma indexStorageMode = "plasma" // ForestDB sets the cluster-wide index storage mode to use the forestdb storage engine, // which only utilizes persistent storage for index maintenance and scans. It is the only option available // for the community edition. ForestDB indexStorageMode = "forestdb" )
Variables ¶
This section is empty.
Functions ¶
func NewBucket ¶
func NewBucket(name string) bucket
NewBucket creates a new bucket with the given name, using default values for all other fields.
func WithAdminCredentials ¶
func WithAdminCredentials(username, password string) credentialsCustomizer
WithAdminCredentials sets the username and password for the administrator user.
func WithBuckets ¶
func WithBuckets(bucket ...bucket) bucketCustomizer
WithBucket adds buckets to the couchbase container
func WithIndexStorage ¶
func WithIndexStorage(indexStorageMode indexStorageMode) indexStorageCustomizer
WithBucket adds buckets to the couchbase container
func WithServiceAnalytics ¶
func WithServiceAnalytics() serviceCustomizer
WithServiceAnalytics enables the Analytics service.
func WithServiceEventing ¶
func WithServiceEventing() serviceCustomizer
WithServiceEventing enables the Eventing service.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is the configuration for the Couchbase container, that will be stored in the container itself.
type CouchbaseContainer ¶
type CouchbaseContainer struct {
testcontainers.Container
// contains filtered or unexported fields
}
CouchbaseContainer represents the Couchbase container type used in the module
func Run ¶ added in v0.32.0
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*CouchbaseContainer, error)
Run creates an instance of the Couchbase container type
Example ¶
// runCouchbaseContainer {
ctx := context.Background()
bucketName := "testBucket"
bucket := couchbase.NewBucket(bucketName)
bucket = bucket.WithQuota(100).
WithReplicas(0).
WithFlushEnabled(false).
WithPrimaryIndex(true)
couchbaseContainer, err := couchbase.Run(ctx,
"couchbase:community-7.1.1",
couchbase.WithAdminCredentials("testcontainers", "testcontainers.IS.cool!"),
couchbase.WithBuckets(bucket),
)
defer func() {
if err := testcontainers.TerminateContainer(couchbaseContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
// }
state, err := couchbaseContainer.State(ctx)
if err != nil {
log.Printf("failed to get container state: %s", err)
return
}
fmt.Println(state.Running)
connectionString, err := couchbaseContainer.ConnectionString(ctx)
if err != nil {
log.Printf("failed to get connection string: %s", err)
return
}
cluster, err := gocb.Connect(connectionString, gocb.ClusterOptions{
Username: couchbaseContainer.Username(),
Password: couchbaseContainer.Password(),
})
if err != nil {
log.Printf("failed to connect to cluster: %s", err)
return
}
buckets, err := cluster.Buckets().GetAllBuckets(nil)
if err != nil {
log.Printf("failed to get buckets: %s", err)
return
}
fmt.Println(len(buckets))
fmt.Println(buckets[bucketName].Name)
Output: true 1 testBucket
func RunContainer
deprecated
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*CouchbaseContainer, error)
Deprecated: use Run instead RunContainer creates an instance of the Couchbase container type
func StartContainer ¶
func StartContainer(ctx context.Context, opts ...Option) (*CouchbaseContainer, error)
StartContainer creates an instance of the Couchbase container type Deprecated: use RunContainer instead
func (*CouchbaseContainer) ConnectionString ¶
func (c *CouchbaseContainer) ConnectionString(ctx context.Context) (string, error)
ConnectionString returns the connection string to connect to the Couchbase container instance. It returns a string with the format couchbase://<host>:<port>
func (*CouchbaseContainer) Password ¶
func (c *CouchbaseContainer) Password() string
Password returns the password of the Couchbase administrator.
func (*CouchbaseContainer) Username ¶
func (c *CouchbaseContainer) Username() string
Username returns the username of the Couchbase administrator.
type Option ¶
type Option func(*Config)
Option is a function that configures the Couchbase container. Deprecated: Use the With* functions instead.
func WithAnalyticsService ¶
func WithAnalyticsService() Option
WithAnalyticsService enables the analytics service in the container. Only available in the Enterprise Edition of Couchbase Server. Deprecated: Use WithServiceAnalytics instead.
func WithBucket ¶
func WithBucket(bucket bucket) Option
WithBucket adds a bucket to the container. Deprecated: Use WithBuckets instead.
func WithCredentials ¶
WithCredentials sets the username and password for the administrator user. Deprecated: Use WithAdminCredentials instead.
func WithEventingService ¶
func WithEventingService() Option
WithEnterpriseService enables the eventing service in the container. Only available in the Enterprise Edition of Couchbase Server. Deprecated: Use WithServiceEventing instead.
func WithImageName ¶
WithImageName allows to override the default image name. Deprecated: Use testcontainers.WithImage instead.
func WithIndexStorageMode ¶
func WithIndexStorageMode(indexStorageMode indexStorageMode) Option
WithIndexStorageMode sets the storage mode to be used in the cluster. Deprecated: Use WithIndexStorage instead.