Documentation ¶
Index ¶
- Variables
- type Client
- type Fields
- type Locator
- type Parameter
- type ParameterKind
- type Process
- type Resource
- type TestClient
- func (c *TestClient) Create(namespace, typ string, fields Fields) (*Resource, error)
- func (c *TestClient) CreateServer(namespace, typ string, fields Fields) (*Resource, error)
- func (c *TestClient) Delete(l *Locator) error
- func (c *TestClient) DeleteProcess(href string) error
- func (c *TestClient) Get(l *Locator) (*Resource, error)
- func (c *TestClient) GetProcess(href string) (*Process, error)
- func (c *TestClient) GetUser() (map[string]interface{}, error)
- func (c *TestClient) List(l *Locator, link string, filters Fields) ([]*Resource, error)
- func (c *TestClient) RunProcess(rcl string, parameters []*Parameter) (*Process, error)
- func (c *TestClient) Update(l *Locator, fields Fields) error
- type TestClientExpectation
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned by Get and Update if no resource with the // given locator could be found. ErrNotFound = fmt.Errorf("resource not found") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // Create creates a new resource given a namespace, type name // and field values. Create(string, string, Fields) (*Resource, error) // CreateServer creates a new server resource given a namespace, type name // and field values. CreateServer(string, string, Fields) (*Resource, error) // List lists resources given a root resource locator, an // optional link to nested resources and optional filters. If // the root locator contains a Href then a link must be provided // and List returns the resources retrieved by following the // link. If the root locator does not contain a href then no // link can be provided and List returns the (top level) // resources of the given locator type. In both cases the result // may be filtered using the last argument. List(*Locator, string, Fields) ([]*Resource, error) // Get retrieves a resource given its locator. Get returns // ErrNotFound if no resource could be found for the given // locator. Get(*Locator) (*Resource, error) // Update updates the fields of a resource. Update returns // ErrNotFound if no resource could be found for the given // locator. Update(*Locator, Fields) error // Delete deletes an existing resource. Delete does nothing if // the resource cannot be found. Delete(*Locator) error // RunProcess runs a Cloud Workflow process initialized with the // given source code. The process runs synchronously and // RunProcess returns after it completes or fails. The RCL code // must define a definition called 'main' that accepts the given // parameter values. RunProcess(source string, parameters []*Parameter) (*Process, error) // GetProcess retrieves the process with the given href. GetProcess(href string) (*Process, error) // DeleteProcess deletes the process with the given href. DeleteProcess(href string) error // GetUser returns the user's information (name, surname, email, company, ...) GetUser() (map[string]interface{}, error) }
Client is the RightScale API client.
type Fields ¶
type Fields map[string]interface{}
Fields represent arbitrary resource fields as consumed by the underlying API.
type Locator ¶
type Locator struct { // Href is the resource path as defined by the underlying // service provider. Href string // Namespace identifies the service that exposes the resource. // The value can be one of the RightScale built-in namespaces: // "rs_cm", "rs_ss" or "rs_ca" or the name of a RightScale // plugin. Namespace string // Type is the name of the resource type scoped by the // namespace, e.g. "servers". Type string // ActionParams allows for the passing of arbitrary extra parameters // to the RightScale APIs. These extra parameters are generally scoped // to a given namespace and resource. ActionParams map[string]string }
Locator contains the information needed to manage a cloud resource via the RightScale APIs.
type Parameter ¶
type Parameter struct { // Kind is the kind of parameter. Kind ParameterKind `json:"kind"` // Value is the parameter value. The mapping of parameter kind // to Go type is as follows: // // Parameter Kind | Go type // ----------------+----------------------------------------------- // KindString | string // KindNumber | [u]int, [u]int32, [u]int64, float32 or float64 // KindBool | bool // KindDateTime | string (RFC3339 time value) // KindDuration | string (RCL duration, e.g. "1h1s") // KindNull | nil // KindArray | []*Parameter // KindObject | map[string]interface{} // KindCollection | map[string]interface{} // KindDeclaration | map[string]interface{} // // The map values for Parameter strict with kind: // // - KindObject must be Parameter structs. // - KindCollection must be map[string]interface{} with keys // 'namespace', 'type', 'hrefs' and 'details'. // - KindDeclaration must be map[string]interface{} with keys // 'namespace', 'type' and 'fields'. // Value interface{} `json:"value"` }
Parameter describes a RCL definition parameter value or output.
type ParameterKind ¶
type ParameterKind string
ParameterKind is the RCL definition parameter kind enum.
const ( KindString ParameterKind = "string" KindNumber ParameterKind = "number" KindBool ParameterKind = "bool" KindNull ParameterKind = "null" KindArray ParameterKind = "array" KindObject ParameterKind = "object" KindCollection ParameterKind = "collection" KindDeclaration ParameterKind = "declaration" )
type Process ¶
type Process struct { // Href is the process API resource href. Href string // Outputs lists the process outputs. Outputs map[string]interface{} // Status is the process status, one of "completed", "failed", // "canceled" or "aborted". Status string // Error is a synthesized error constructed when the process // fails. It may be ErrNotFound in case the process failed due // to a "ResourceNotFound" RightScale API response. Error error }
Process represents a Cloud Workflow process.
type Resource ¶
type Resource struct { // Locator is the resource locator. Locator *Locator // Fields lists the resource fields. Fields Fields }
Resource represents a resource managed by the RightScale platform.
type TestClient ¶
type TestClient struct {
*TestClientExpectation
}
TestClient is a mock of the Client.
func NewTestClient ¶
func NewTestClient() *TestClient
NewTestClient creates a Client which uses expectations set by the tests to implement the behavior.
func (*TestClient) Create ¶
func (c *TestClient) Create(namespace, typ string, fields Fields) (*Resource, error)
Create runs any preset expectation.
func (*TestClient) CreateServer ¶
func (c *TestClient) CreateServer(namespace, typ string, fields Fields) (*Resource, error)
CreateServer runs any preset expectation.
func (*TestClient) Delete ¶
func (c *TestClient) Delete(l *Locator) error
Delete runs any preset expectation.
func (*TestClient) DeleteProcess ¶
func (c *TestClient) DeleteProcess(href string) error
DeleteProcess runs any preset expectation.
func (*TestClient) Get ¶
func (c *TestClient) Get(l *Locator) (*Resource, error)
Get runs any preset expectation.
func (*TestClient) GetProcess ¶
func (c *TestClient) GetProcess(href string) (*Process, error)
GetProcess runs any preset expectation.
func (*TestClient) GetUser ¶
func (c *TestClient) GetUser() (map[string]interface{}, error)
GetUser returns the user's information (name, surname, email, company, ...) The user is the one that generated the RefreshToken provided to authenticate in RightScale
func (*TestClient) RunProcess ¶
func (c *TestClient) RunProcess(rcl string, parameters []*Parameter) (*Process, error)
RunProcess runs any preset expectation.
type TestClientExpectation ¶
type TestClientExpectation struct {
// contains filtered or unexported fields
}
TestClientExpectation is a generic mock.
func NewTestClientExpectation ¶
func NewTestClientExpectation() *TestClientExpectation
NewTestClientExpectation creates a new *TestClientExpectation
func (*TestClientExpectation) Expect ¶
func (c *TestClientExpectation) Expect(fn string, e interface{})
Expect records the request handler in the list of expected request calls.
func (*TestClientExpectation) ExpectNTimes ¶
func (c *TestClientExpectation) ExpectNTimes(n int, fn string, e interface{})
ExpectNTimes records the request handler n times in the list of expected request calls.
func (*TestClientExpectation) Expectation ¶
func (c *TestClientExpectation) Expectation(fn string) interface{}
Expectation removes the expectation for the function with the given name from the expected calls if there is one and returns it. If there is no (more) expectations for the function, it prints a warning to stderr and returns nil.
func (*TestClientExpectation) MetExpectations ¶
func (c *TestClientExpectation) MetExpectations() error
MetExpectations returns nil if there no expectation left to be called and if there is no call that was made that did not match an expectation. It returns an error describing what is left to be called or what was called with no expectation otherwise.