rainforest

package
v2.12.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package rainforest is a golang client for the Rainforest QA API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Browser

type Browser struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

Browser type represents a single browser returned by the API call for a list of browsers

type Client

type Client struct {

	// URL of a Rainforest API endpoint to be used by the client
	BaseURL *url.URL

	// String that will be set as an user agent with current library version appended to it
	UserAgent string

	// Save HTTP Response Headers
	LastResponseHeaders http.Header

	//Set debug flag to decide whether to return headers or not
	DebugFlag bool
	// contains filtered or unexported fields
}

Client is responsible for communicating with Rainforest API

func NewClient

func NewClient(token string, debug bool) *Client

NewClient constructs a new rainforest API Client. As a parameter takes client token which is used for authentication and is available in the rainforest web app.

func (*Client) AddGeneratorRows

func (c *Client) AddGeneratorRows(targetGenerator *Generator, rowData []map[int]string) error

AddGeneratorRows adds rows to the specified tabular variable rowData is in a form of [{ 123: "foo", 124: "bar" }, { 123: "baz", 124: "qux" }] where 123 is a column ID AddGeneratorRowsFromTable is also provided which accepts different rowData format

func (*Client) AddGeneratorRowsFromTable

func (c *Client) AddGeneratorRowsFromTable(targetGenerator *Generator,
	targetColumns []string, rowData [][]string) error

AddGeneratorRowsFromTable adds rows to the specified tabular variable data should be formatted as follows: targetColumns contains names of existing columns to which add data e.g. ["login", "password"] rowData contains row data in columns order specified in targetColumns e.g. [["foo", "bar"], ["baz", "qux"]]

func (*Client) CheckRunStatus

func (c *Client) CheckRunStatus(runID int) (*RunStatus, error)

CheckRunStatus returns the status of a specified run.

func (*Client) ClientToken

func (c *Client) ClientToken() string

ClientToken returns the API authentication token for the client.

func (*Client) CreateRun

func (c *Client) CreateRun(params RunParams) (*RunStatus, error)

CreateRun starts a new RF run with given params.

func (*Client) CreateTabularVar

func (c *Client) CreateTabularVar(name, description string,
	columns []string, singleUse bool) (*Generator, error)

CreateTabularVar creates new tabular variable on RF and returns Generator associated with it columns argument should contain just an array of column names, contents of the generator should be filled using AddGeneratorRows.

func (*Client) CreateTemporaryEnvironment

func (c *Client) CreateTemporaryEnvironment(urlString string) (*Environment, error)

CreateTemporaryEnvironment creates a new temporary environment and returns the Environment.

func (*Client) CreateTest

func (c *Client) CreateTest(test *RFTest) error

CreateTest creates new test on RF, requires RFTest struct to be prepared to upload using helpers

func (*Client) DeleteGenerator

func (c *Client) DeleteGenerator(genID int) error

DeleteGenerator deletes generator with specified ID

func (*Client) DeleteTest

func (c *Client) DeleteTest(testID int) error

DeleteTest deletes test with a specified ID from the RF test suite

func (*Client) DeleteTestByRFMLID

func (c *Client) DeleteTestByRFMLID(testRFMLID string) error

DeleteTestByRFMLID deletes test with a specified RFMLID from the RF test suite

func (*Client) Do

func (c *Client) Do(req *http.Request, out interface{}) (*http.Response, error)

Do sends out the request to the API and unpacks JSON response to the out variable.

func (*Client) GetBrowsers

func (c *Client) GetBrowsers() ([]Browser, error)

GetBrowsers returns a slice of Browsers which are available for the client to run RF tests against.

func (*Client) GetEnvironments

func (c *Client) GetEnvironments() ([]Environment, error)

GetEnvironments fetches environments available to use during the RF runs.

func (*Client) GetFeatures

func (c *Client) GetFeatures() ([]Feature, error)

GetFeatures fetches available features.

func (*Client) GetFolders

func (c *Client) GetFolders() ([]Folder, error)

GetFolders returns a slice of Folders (their names and IDs) which are available for filtering RF tests.

func (*Client) GetGenerators

func (c *Client) GetGenerators() ([]Generator, error)

GetGenerators fetches a list of all available generators for the account

func (*Client) GetPresignedPOST

func (c *Client) GetPresignedPOST(fileExt string, siteID int, environmentID int, appSlot int) (*RFPresignedPostData, error)

GetPresignedPOST requests the presigned POST data from Rainforest so that we can upload the mobile app to S3

func (*Client) GetRunDetails

func (c *Client) GetRunDetails(runID int) (*RunDetails, error)

GetRunDetails returns the top level details of a Run

func (*Client) GetRunGroupDetails

func (c *Client) GetRunGroupDetails(runGroupID int) (*RunGroupDetails, error)

GetRunGroupDetails gets details for a run group from the API.

func (*Client) GetRunGroups

func (c *Client) GetRunGroups() ([]RunGroup, error)

GetRunGroups fetches available run groups.

func (*Client) GetRunTestDetails

func (c *Client) GetRunTestDetails(runID int, testID int) (*RunTestDetails, error)

GetRunTestDetails returns the detailed information for a RunTest

func (*Client) GetSites

func (c *Client) GetSites() ([]Site, error)

GetSites fetches sites available to use during the RF runs.

func (*Client) GetTest

func (c *Client) GetTest(testID int) (*RFTest, error)

GetTest gets a test from RF specified by the given test ID

func (*Client) GetTestIDs

func (c *Client) GetTestIDs() ([]TestIDPair, error)

GetTestIDs returns all tests IDs and RFML IDs to properly map tests to their IDs for uploading and deleting.

func (*Client) GetTests

func (c *Client) GetTests(params *RFTestFilters) ([]RFTest, error)

GetTests returns all tests that are optionally filtered by RFTestFilters

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. Provided url will be resolved using ResolveReference, which works in a similar way to the hrefs in a browser (most important takeaway is to not add preceeding slash to the link as it resolves to a root path of domain). The body argument is JSON endoded and attached as a request body. This function also attaches auth token from the client to the request.

func (*Client) ParseEmbeddedFiles

func (c *Client) ParseEmbeddedFiles(test *RFTest) error

ParseEmbeddedFiles replaces file step variable paths with values expected by Rainforest. eg: {{ file.screenshot(my_screenshot.gif) }} would be translated to the format {{ file.screenshot(FILE_ID, FILE_SIGNATURE) }}.

func (*Client) UpdateTest

func (c *Client) UpdateTest(test *RFTest) error

UpdateTest updates existing test on RF, requires RFTest struct to be prepared to upload using helpers

func (*Client) UpdateURL

func (c *Client) UpdateURL(siteID int, environmentID int, appSlot int, newURL string) error

UpdateURL fetches sites available to use during the RF runs.

func (*Client) UploadToS3

func (c *Client) UploadToS3(postData *RFPresignedPostData, filePath string) error

UploadToS3 creates a http.Request containing the required body for uploading a file to AWS given the values stored in the receiving awsFileInfo struct.

type Environment

type Environment struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Environment represents an environment in Rainforest

type EnvironmentParams

type EnvironmentParams struct {
	Name string `json:"name"`
	URL  string `json:"url"`
}

EnvironmentParams are the parameters used to create a new Environment

type Feature

type Feature struct {
	ID    int    `json:"id"`
	Title string `json:"title"`
}

Feature represents a single feature returned by the API.

type FeatureIDInt

type FeatureIDInt int

FeatureIDInt is a wrapper the int type used in the FeatureID field of RFTest that implements the json.Marshaler interface.

func (*FeatureIDInt) MarshalJSON

func (id *FeatureIDInt) MarshalJSON() ([]byte, error)

MarshalJSON treats an FeatureIDInt value of -1 as a special case so that it is marshalledd into a `null` JSON value.

type Folder

type Folder struct {
	ID    int    `json:"id"`
	Title string `json:"title"`
}

Folder type represents a single folder returned by the API call for a list of folders

type Generator

type Generator struct {
	ID          int               `json:"id,omitempty"`
	Name        string            `json:"name,omitempty"`
	CreatedAt   time.Time         `json:"created_at,omitempty"`
	Description string            `json:"description,omitempty"`
	Type        string            `json:"generator_type,omitempty"`
	SingleUse   bool              `json:"single_use,omitempty"`
	Columns     []GeneratorColumn `json:"columns,omitempty"`
	RowCount    int               `json:"row_count,omitempty"`
}

Generator is a type representing generators which can be used as variables in RF tests. They can be builtin or uploaded by customer as a tabular variable.

func (Generator) GetDescription

func (g Generator) GetDescription() string

GetDescription returns the Generator's description

func (Generator) GetID

func (g Generator) GetID() string

GetID returns the Generator name

type GeneratorColumn

type GeneratorColumn struct {
	ID        int       `json:"id,omitempty"`
	CreatedAt time.Time `json:"created_at,omitempty"`
	Name      string    `json:"name,omitempty"`
}

GeneratorColumn is a type of column in a generator

type GeneratorRelatedTests

type GeneratorRelatedTests struct {
	ID    int    `json:"id,omitempty"`
	Title string `json:"title,omitempty"`
}

GeneratorRelatedTests is a type which holds tests where the generator has been used

type RFEmbeddedTest

type RFEmbeddedTest struct {
	RFMLID   string
	Redirect bool
}

RFEmbeddedTest contains an embedded test details

type RFMLReader

type RFMLReader struct {

	// Version sets the RFML spec version, it's set by NewRFMLReader to the newest one.
	Version int
	// Sets the default value of redirect, that's used when it's not specified in RFML
	RedirectDefault bool
	// contains filtered or unexported fields
}

RFMLReader reads form RFML formatted file. It exports some settings that can be set before parsing.

func NewRFMLReader

func NewRFMLReader(r io.Reader) *RFMLReader

NewRFMLReader returns RFML parser based on passed io.Reader - typically a RFML file.

func (*RFMLReader) ReadAll

func (r *RFMLReader) ReadAll() (*RFTest, error)

ReadAll parses whole RFML file using RFML version specified by Version parameter of reader and returns resulting RFTest

type RFMLWriter

type RFMLWriter struct {

	// Version sets the RFML spec version
	Version int
	// contains filtered or unexported fields
}

RFMLWriter writes a RFML formatted test to a given file.

func NewRFMLWriter

func NewRFMLWriter(w io.Writer) *RFMLWriter

NewRFMLWriter returns RFML writer based on passed io.Writer - typically a RFML file.

func (*RFMLWriter) WriteRFMLTest

func (r *RFMLWriter) WriteRFMLTest(test *RFTest) error

WriteRFMLTest writes a given RFTest to its writer in the given RFML version.

type RFPresignedPostData

type RFPresignedPostData struct {
	URL            string            `json:"url"`
	RequiredFields map[string]string `json:"url_fields"`
	RainforestURL  string            `json:"rainforest_url"`
}

RFPresignedPostData represents the url and required fields we must POST to AWS in order to upload

type RFTest

type RFTest struct {
	TestID      int                      `json:"id"`
	RFMLID      string                   `json:"rfml_id"`
	Source      string                   `json:"source"`
	Title       string                   `json:"title,omitempty"`
	State       string                   `json:"state,omitempty"`
	StartURI    string                   `json:"start_uri"`
	SiteID      int                      `json:"site_id,omitempty"`
	Description string                   `json:"description,omitempty"`
	Tags        []string                 `json:"tags"`
	BrowsersMap []map[string]interface{} `json:"browsers"`
	Elements    []testElement            `json:"elements,omitempty"`
	FeatureID   FeatureIDInt             `json:"feature_id,omitempty"`

	// Browsers and Steps are helper fields
	Browsers []string      `json:"-"`
	Steps    []interface{} `json:"-"`
	// RFMLPath is a helper field for keeping track of the filepath to the
	// test's RFML file.
	RFMLPath string `json:"-"`

	// Execute is a non-API field that specifies whether the test should be
	// executed or just uploaded (e.g. for embedded tests). It defaults to
	// true when reading from RFML.
	Execute bool `json:"-"`
}

RFTest is a struct representing the Rainforest Test with its settings and steps

func (*RFTest) HasUploadableFiles

func (t *RFTest) HasUploadableFiles() bool

HasUploadableFiles returns true if test has embedded files in the format {{ file.screenshot(path/to/file) }} or {{ file.download(path/to/file) }}. It returns false otherwise.

func (*RFTest) PrepareToUploadFromRFML

func (t *RFTest) PrepareToUploadFromRFML(coll TestIDCollection) error

PrepareToUploadFromRFML uses different helper methods to prepare struct for API upload

func (*RFTest) PrepareToWriteAsRFML

func (t *RFTest) PrepareToWriteAsRFML(coll TestIDCollection, flattenedSteps bool) error

PrepareToWriteAsRFML uses different helper methods to prepare struct for translation to RFML

type RFTestFilters

type RFTestFilters struct {
	Tags          []string
	SiteID        int
	SmartFolderID int
	FeatureID     int
	RunGroupID    int
}

RFTestFilters are used to translate test filters to a proper query string

type RFTestStep

type RFTestStep struct {
	Action   string
	Response string
	Redirect bool
}

RFTestStep contains single Rainforest step

type RunBrowserDetails

type RunBrowserDetails struct {
	Name     string        `json:"name"`
	Feedback []RunFeedback `json:"feedback"`
}

RunBrowserDetails contains details about a Browser of a Run Step

type RunDetails

type RunDetails struct {
	ID                 int                  `json:"id"`
	Description        string               `json:"description"`
	Release            string               `json:"release"`
	TotalTests         int                  `json:"total_tests"`
	TotalFailedTests   int                  `json:"total_failed_tests"`
	TotalNoResultTests int                  `json:"total_no_result_tests"`
	StateDetails       RunStateDetails      `json:"state_details"`
	Timestamps         map[string]time.Time `json:"timestamps"`
	Tests              []RunTestDetails     `json:"tests"`
}

RunDetails contains top level details of a Run

type RunFeedback

type RunFeedback struct {
	JobState      string `json:"job_state"`
	Result        string `json:"result"`
	FailureNote   string `json:"note"`
	Comment       string `json:"comment"`
	CommentReason string `json:"comment_reason"`
}

RunFeedback contains details about the feedback of a Run Step for a browser

type RunGroup

type RunGroup struct {
	ID    int    `json:"id"`
	Title string `json:"title"`
}

RunGroup represents a single run group returned by the API.

type RunGroupDetails

type RunGroupDetails struct {
	ID          int    `json:"id"`
	Title       string `json:"title"`
	Environment struct {
		Name string `json:"name"`
	} `json:"environment"`
	Crowd      string `json:"crowd"`
	RerouteGeo string `json:"reroute_geo"`
	Schedule   struct {
		RepeatRules []struct {
			Day  string `json:"day"`
			Time string `json:"time"`
		} `json:"repeat_rules"`
	} `json:"schedule"`
}

RunGroupDetails shows the details for a particular run group.

func (*RunGroupDetails) Print

func (rgd *RunGroupDetails) Print()

Print prints out details for a particular run group.

type RunParams

type RunParams struct {
	// This can be eiter []int or string containing 'all'
	Tests         interface{} `json:"tests,omitempty"`
	RFMLIDs       []string    `json:"rfml_ids,omitempty"`
	Tags          []string    `json:"tags,omitempty"`
	SmartFolderID int         `json:"smart_folder_id,omitempty"`
	SiteID        int         `json:"site_id,omitempty"`
	Crowd         string      `json:"crowd,omitempty"`
	Conflict      string      `json:"conflict,omitempty"`
	Browsers      []string    `json:"browsers,omitempty"`
	Description   string      `json:"description,omitempty"`
	Release       string      `json:"release,omitempty"`
	EnvironmentID int         `json:"environment_id,omitempty"`
	FeatureID     int         `json:"feature_id,omitempty"`
	RunGroupID    int         `json:"-"`
}

RunParams is a struct holding all potential parameters needed to start a new RF run.

type RunStateDetails

type RunStateDetails struct {
	Name         string `json:"name"`
	IsFinalState bool   `json:"is_final_state"`
}

RunStateDetails contains details about the state of a Run

type RunStatus

type RunStatus struct {
	ID           int    `json:"id"`
	State        string `json:"state"`
	StateDetails struct {
		Name         string `json:"name"`
		IsFinalState bool   `json:"is_final_state"`
	} `json:"state_details"`
	Result          string `json:"result"`
	CurrentProgress struct {
		Percent  int `json:"percent"`
		Total    int `json:"total"`
		Complete int `json:"complete"`
		NoResult int `json:"no_result"`
	} `json:"current_progress"`
	FrontendURL string `json:"frontend_url,omitempty"`
}

RunStatus represents a status of a RF run in progress.

type RunStepDetails

type RunStepDetails struct {
	Browsers []RunBrowserDetails `json:"browsers"`
}

RunStepDetails contains details about a Run Step

type RunTestDetails

type RunTestDetails struct {
	ID        int              `json:"id"`
	Title     string           `json:"title"`
	CreatedAt time.Time        `json:"created_at"`
	UpdatedAt time.Time        `json:"updated_at"`
	Result    string           `json:"result"`
	Steps     []RunStepDetails `json:"steps"`
}

RunTestDetails contains details about a Run Test

type Site

type Site struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Category string `json:"category"`
}

Site type represents a single site returned by the API call for a list of sites

type SiteEnvironment

type SiteEnvironment struct {
	ID            int    `json:"id"`
	SiteID        int    `json:"site_id"`
	EnvironmentID int    `json:"environment_id"`
	URL           string `json:"url"`
}

SiteEnvironment type represents a single SiteEnvironment returned by the API call for a list of sites

type SiteEnvironmentUpdate

type SiteEnvironmentUpdate struct {
	URL string `json:"url"`
}

SiteEnvironmentUpdate type is the body of site_environments PUT update for updating the URL

type SiteEnvironmentsData

type SiteEnvironmentsData struct {
	SiteEnvironments []SiteEnvironment `json:"site_environments"`
}

SiteEnvironmentsData type represents the collection returned when calling the site_environments get endpoint

type TestIDCollection

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

TestIDCollection efficiently finds corresponding test IDs and RFML IDs.

func NewTestIDCollection

func NewTestIDCollection(testIDPairs []TestIDPair) *TestIDCollection

NewTestIDCollection creates a new collection for a given slice of TestIDPairs

func (TestIDCollection) GetRFMLID

func (coll TestIDCollection) GetRFMLID(testID int) (string, error)

GetRFMLID finds the corresponding RFML ID for a test ID

func (TestIDCollection) GetTestID

func (coll TestIDCollection) GetTestID(rfmlID string) (int, error)

GetTestID find the corresponding test ID for a RFML ID

type TestIDPair

type TestIDPair struct {
	ID     int    `json:"id"`
	RFMLID string `json:"rfml_id"`
}

TestIDPair is a type representing RF tests that contain the test definitions.

Jump to

Keyboard shortcuts

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