tools

package
Version: v0.0.0-...-1eb392f Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2015 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package tools implements types which help work with etcd which depend on the api package. TODO: move this package to an etcd specific utility package.

Index

Constants

View Source
const (
	EtcdErrorCodeNotFound      = 100
	EtcdErrorCodeTestFailed    = 101
	EtcdErrorCodeNodeExist     = 105
	EtcdErrorCodeValueRequired = 200
)

Variables

View Source
var (
	EtcdErrorNotFound      = &etcd.EtcdError{ErrorCode: EtcdErrorCodeNotFound}
	EtcdErrorTestFailed    = &etcd.EtcdError{ErrorCode: EtcdErrorCodeTestFailed}
	EtcdErrorNodeExist     = &etcd.EtcdError{ErrorCode: EtcdErrorCodeNodeExist}
	EtcdErrorValueRequired = &etcd.EtcdError{ErrorCode: EtcdErrorCodeValueRequired}
)

Functions

This section is empty.

Types

type EtcdClient

type EtcdClient interface {
	GetCluster() []string
	Get(key string, sort, recursive bool) (*etcd.Response, error)
	Set(key, value string, ttl uint64) (*etcd.Response, error)
	Create(key, value string, ttl uint64) (*etcd.Response, error)
	CompareAndSwap(key, value string, ttl uint64, prevValue string, prevIndex uint64) (*etcd.Response, error)
	Delete(key string, recursive bool) (*etcd.Response, error)
	// I'd like to use directional channels here (e.g. <-chan) but this interface mimics
	// the etcd client interface which doesn't, and it doesn't seem worth it to wrap the api.
	Watch(prefix string, waitIndex uint64, recursive bool, receiver chan *etcd.Response, stop chan bool) (*etcd.Response, error)
}

EtcdClient is an injectable interface for testing.

type EtcdResponseWithError

type EtcdResponseWithError struct {
	R *etcd.Response
	E error
	// if N is non-null, it will be assigned into the map after this response is used for an operation
	N *EtcdResponseWithError
}

type FakeEtcdClient

type FakeEtcdClient struct {
	Data        map[string]EtcdResponseWithError
	DeletedKeys []string

	sync.Mutex
	Err    error
	CasErr error

	Ix          int
	TestIndex   bool
	ChangeIndex uint64
	LastSetTTL  uint64
	Machines    []string

	// Will become valid after Watch is called; tester may write to it. Tester may
	// also read from it to verify that it's closed after injecting an error.
	WatchResponse chan *etcd.Response
	WatchIndex    uint64
	// Write to this to prematurely stop a Watch that is running in a goroutine.
	WatchInjectError chan<- error
	WatchStop        chan<- bool
	// If non-nil, will be returned immediately when Watch is called.
	WatchImmediateError error
	// contains filtered or unexported fields
}

func NewFakeEtcdClient

func NewFakeEtcdClient(t TestLogger) *FakeEtcdClient

func (*FakeEtcdClient) CompareAndSwap

func (f *FakeEtcdClient) CompareAndSwap(key, value string, ttl uint64, prevValue string, prevIndex uint64) (*etcd.Response, error)

func (*FakeEtcdClient) Create

func (f *FakeEtcdClient) Create(key, value string, ttl uint64) (*etcd.Response, error)

func (*FakeEtcdClient) Delete

func (f *FakeEtcdClient) Delete(key string, recursive bool) (*etcd.Response, error)

func (*FakeEtcdClient) ExpectNotFoundGet

func (f *FakeEtcdClient) ExpectNotFoundGet(key string)

func (*FakeEtcdClient) Get

func (f *FakeEtcdClient) Get(key string, sort, recursive bool) (*etcd.Response, error)

func (*FakeEtcdClient) GetCluster

func (f *FakeEtcdClient) GetCluster() []string

func (*FakeEtcdClient) NewError

func (f *FakeEtcdClient) NewError(code int) *etcd.EtcdError

func (*FakeEtcdClient) Set

func (f *FakeEtcdClient) Set(key, value string, ttl uint64) (*etcd.Response, error)

func (*FakeEtcdClient) SetError

func (f *FakeEtcdClient) SetError(err error)

func (*FakeEtcdClient) WaitForWatchCompletion

func (f *FakeEtcdClient) WaitForWatchCompletion()

func (*FakeEtcdClient) Watch

func (f *FakeEtcdClient) Watch(prefix string, waitIndex uint64, recursive bool, receiver chan *etcd.Response, stop chan bool) (*etcd.Response, error)

type TestLogger

type TestLogger interface {
	Fatalf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Logf(format string, args ...interface{})
}

TestLogger is a type passed to Test functions to support formatted test logs.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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