mocks

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(lhs, rhs UID) int

Compare UID values

func NewObjectUpdater

func NewObjectUpdater(db Database) *objectUpdater

NewObjectUpdater returns an object the implements the contrail.objectInterface interface. These are the methods provoded to the generated types classes that allow them to manage get, add and delete operations on references.

Types

type ApiClient

type ApiClient struct {
	IDAssignMap    map[string]string
	InterceptorMap map[string]TypeInterceptor
	// contains filtered or unexported fields
}

ApiClient mocks the contrail.ApiClient interface.

func (*ApiClient) AddInterceptor

func (m *ApiClient) AddInterceptor(typename string, interceptor TypeInterceptor)

AddInterceptor is used to apply a type-specific hook for GET and PUT requests.

func (*ApiClient) Create

func (m *ApiClient) Create(ptr contrail.IObject) error

Create adds an object to the database.

func (*ApiClient) Delete

func (m *ApiClient) Delete(ptr contrail.IObject) error

Delete an object.

func (*ApiClient) DeleteByUuid

func (m *ApiClient) DeleteByUuid(typename string, id string) error

DeleteByUuid removes the object identified by the specified uuid.

func (*ApiClient) FQNameByUuid

func (m *ApiClient) FQNameByUuid(id string) ([]string, error)

FQNameByUuid retrieves the fully qualified name corresponding to a UUID.

func (*ApiClient) FindByName

func (m *ApiClient) FindByName(typename string, fqn string) (contrail.IObject, error)

FindByName reads the database object identified by a colon (:) delimited string.

func (*ApiClient) FindByUuid

func (m *ApiClient) FindByUuid(typename string, id string) (contrail.IObject, error)

FindByUuid retrieves the object specified by uuid.

func (*ApiClient) Init

func (m *ApiClient) Init()

Init initializes the database with default values such as the default-project and ipam.

func (*ApiClient) List

func (m *ApiClient) List(typename string) ([]contrail.ListResult, error)

List retrives the identifiers of all objects of a given type.

func (*ApiClient) ListByParent

func (m *ApiClient) ListByParent(typename string, parentID string) ([]contrail.ListResult, error)

ListByParent retrieves the identifiers of objects of the specified type that are descendents of parent (as identified by UUID)

func (*ApiClient) ListDetail

func (m *ApiClient) ListDetail(typename string, fields []string) ([]contrail.IObject, error)

ListDetail reads all the objects of a given type.

func (*ApiClient) ListDetailByParent

func (m *ApiClient) ListDetailByParent(typename string, parentID string, fields []string) ([]contrail.IObject, error)

ListDetailByParent reads all the objects of the specified type that are descendants of the parent object (as specified by UUID).

func (*ApiClient) Update

func (m *ApiClient) Update(ptr contrail.IObject) error

Update modifies the object in the database.

func (*ApiClient) UuidByName

func (m *ApiClient) UuidByName(typename string, fqn string) (string, error)

UuidByName retrieves the uuid given a fully qualified name as a colon (:) delimited string.

type Database

type Database interface {
	Put(obj contrail.IObject, parent contrail.IObject, refs UIDList) error
	Update(obj contrail.IObject, refs UIDList) error
	Delete(obj contrail.IObject) error
	GetByUUID(id uuid.UUID) (contrail.IObject, error)
	GetByName(typename string, fqn string) (contrail.IObject, error)
	List(typename string) []contrail.IObject
	GetChildren(uid UID, typename string) (UIDList, error)
	GetBackReferences(uid UID, typename string) (UIDList, error)
}

Database defines the interface used to mock the behavior of the contrail API server.

func NewInMemDatabase

func NewInMemDatabase() Database

NewInMemDatabase creates and initializes a InMemDatabase.

type InMemDatabase

type InMemDatabase struct {
	// contains filtered or unexported fields
}

InMemDatabase implements the Database interface.

func (*InMemDatabase) Delete

func (db *InMemDatabase) Delete(obj contrail.IObject) error

Delete an object and any back references on objects that it refers to. Deletes as rejected for objects that have children or back references mimicing the behavior of the Contrail API server.

func (*InMemDatabase) GetBackReferences

func (db *InMemDatabase) GetBackReferences(uid UID, typename string) (UIDList, error)

GetBackReferences retrieves the list of back references.

func (*InMemDatabase) GetByName

func (db *InMemDatabase) GetByName(typename string, fqn string) (contrail.IObject, error)

GetByName retrieves an object specified by colon separated fully qualified name.

func (*InMemDatabase) GetByUUID

func (db *InMemDatabase) GetByUUID(id uuid.UUID) (contrail.IObject, error)

GetByUUID retrieves and object by UUID.

func (*InMemDatabase) GetChildren

func (db *InMemDatabase) GetChildren(uid UID, typename string) (UIDList, error)

GetChildren retrieves the list of children.

func (*InMemDatabase) List

func (db *InMemDatabase) List(typename string) []contrail.IObject

List retrieves all objects of a given type.

func (*InMemDatabase) Put

func (db *InMemDatabase) Put(obj contrail.IObject, parent contrail.IObject, refs UIDList) error

Put adds an object to the database and updates the children list on the parent and the back_references lists of objects that obj refers to.

func (*InMemDatabase) Update

func (db *InMemDatabase) Update(obj contrail.IObject, refs UIDList) error

Update an object in the database, modifying corresponding references (forward and back).

type ObjectData

type ObjectData struct {
	// contains filtered or unexported fields
}

ObjectData stores reference data

type ReferenceMap

type ReferenceMap map[string]UIDList

ReferenceMap stores references by typename

type TypeInterceptor

type TypeInterceptor interface {
	Get(contrail.IObject)
	Put(contrail.IObject)
}

TypeInterceptor defines an interface that intercepts Put and Get requests to the API. Typically used to simulate API server behavior that is type specific. An example is the API server determining the Gateway address on a Subnet.

type TypeMap

type TypeMap map[string]contrail.IObject

TypeMap stores per typename map of name to object.

type UID

type UID [16]byte

UID is defined since uuid.UUID is a slice and cannot be used as a map key.

func (*UID) Interface

func (u *UID) Interface() uuid.UUID

Interface converts the fixed length array representation to the uuid package type.

func (*UID) IsNIL

func (u *UID) IsNIL() bool

IsNIL returns true if the UID value is 0.

type UIDList

type UIDList []UID

UIDList is a slice of UID values

Jump to

Keyboard shortcuts

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