memcached

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: MIT Imports: 5 Imported by: 1

README

Gnomock Memcached

Gnomock Memcached is a Gnomock preset for running tests against a real Memcached container, without mocks.

package memcached_test

import (
	"fmt"
	"testing"

	memcachedclient "github.com/bradfitz/gomemcache/memcache"
	"github.com/orlangure/gnomock"
	"github.com/orlangure/gnomock/preset/memcached"
)

func ExamplePreset() {
	vs := make(map[string][]byte)

	// String
	vs["a"] = []byte("foo")
	// Number
	vsb := make([]byte, 4)
	binary.LittleEndian.PutUint32(vsb, 42)
	vs["b"] = vsb

	p := memcached.Preset(memcached.WithValues(vs))
	container, _ := gnomock.Start(p)

	defer func() { _ = gnomock.Stop(container) }()

	addr := container.DefaultAddress()
	client := memcachedclient.New(addr)

	itemA, _ := client.Get("a")
	fmt.Println(string(itemA.Value))

	itemB, _ := client.Get("b")
	fmt.Println(binary.LittleEndian.Uint32(itemB.Value))

	// Output:
	// foo
	// 42
}

Documentation

Overview

Package memcached includes Memcached implementation of Gnomock Preset interface. This Preset can be passed to gnomock.StartPreset function to create a configured Memcached container to use in tests

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Preset

func Preset(opts ...Option) gnomock.Preset

Preset creates a new Gmomock Memcached preset. This preset includes a Memcached specific healthcheck function, default Memcached image and port, and allows to optionally set up initial state.

Types

type Option

type Option func(*P)

Option is an optional configuration of this Gnomock preset. Use available Options to configure the container.

func WithByteValues

func WithByteValues(vs map[string][]byte) Option

WithByteValues initializes Memcached with the provided key/value paris. These values never expire. Only byte slices are supported.

func WithValues

func WithValues(vs map[string]string) Option

WithValues initializes Memcached with the provided key/value pairs. These values never expire. Only strings are supported.

func WithVersion

func WithVersion(version string) Option

WithVersion sets image version.

type P

type P struct {
	Values     map[string]string `json:"values"`
	ByteValues map[string][]byte `json:"byteValues"`
	Version    string            `json:"version"`
}

P is a Gnomock Preset implementation for Memcached storage.

func (*P) Image

func (p *P) Image() string

Image returns an image that should be pulled to create this container.

func (*P) Options

func (p *P) Options() []gnomock.Option

Options returns a list of options to configure this container.

func (*P) Ports

func (p *P) Ports() gnomock.NamedPorts

Ports returns ports that should be used to access this container.

Jump to

Keyboard shortcuts

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