Documentation ¶
Overview ¶
Copyright 2021 Kevin Zuern. All rights reserved.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct { // Before if set will be run before the step is executed. If an error is // returned the test will fail and the step will not be run. Before func(stepNumber int, step *Step) error `yaml:"-"` // Execute if set will be executed to retrieve the result of the // operation from the GraphQL API. An error should be returned only if the // response couldn't be retrieved, for example due to a connection issue. Execute func(*Step) (result map[string]interface{}, err error) `yaml:"-"` // After if set will be run after the step is executed. If an error is // returned the test will fail. result and err are the return values of // executing the step. After func(stepNumber int, step *Step, result map[string]interface{}, err error) error `yaml:"-"` // Endpoint is the endpoint of the GraphQL API. Endpoint string `yaml:"endpoint"` // Header to be included with the request. Additional headers may be added // to this field by the Execute func. Header http.Header `yaml:"header"` // Method alters how the request is sent to the endpoint. Acceptable values are // "", "post", "get". // // The empty string or "post" will use an HTTP POST with a JSON body // containing the operation, query, and variables. // // "get" will use an HTTP GET request with the operation, query, and // variables encoded as URL query parameters. Method string `yaml:"method"` // Custom allows specifying custom configuration which may be useful when // using custom Before, Execute, or After funcs. This is not used inside this // package. Custom interface{} `yaml:"custom"` // AllowErrors if true will not fail a test step if there are errors in the // returned GraphQL response. Useful for making assertions about error // conditions. AllowErrors bool `yaml:"allowErrors"` // Quiet if true will suppress request/response output on a successful run. Quiet bool `yaml:"quiet"` }
Options used to alter the behavior of a test step.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
A Runner runs a test.
func NewRunner ¶
func NewRunner(t testing.TB, options *RunnerOptions) *Runner
NewRunner creates a new test Runner. If options is nil DefaultRunnerOptions is used.
func (*Runner) LoadTestFile ¶
LoadTestFile loads a Test from yamlFilePath.
type RunnerOptions ¶
type RunnerOptions struct { // Verbose makes tests print output on successful test steps as well as // failed ones. Verbose bool IncludeTestName bool IncludeStepName bool IncludeURL bool IncludeHeaders bool IncludeRequestBody bool IncludeResponseBody bool IncludeDiff bool // Output from the Runner will be written here. Output io.Writer }
RunnerOptions are options to configure the test Runner.
func DefaultRunnerOptions ¶ added in v0.0.4
func DefaultRunnerOptions() *RunnerOptions
DefaultRunnerOptions used by this package.
type Step ¶
type Step struct { // Name of the step. Name string `yaml:"name"` // GraphQL Query to send to the endpoint. Query string `yaml:"query"` // Op is the operation name. Op string `yaml:"op"` // Vars are a map of GraphQL variables. Vars map[string]interface{} `yaml:"vars"` // Expect is the expected return value from the API. The step will fail if // errors are present in the returned API response, unless // Options.AllowErrors is set to true. If Expect is nil the step will only // check for the absence of errors. Expect map[string]interface{} `yaml:"expect"` // Options to override test Options for this step only. Options Options `yaml:"options,omitempty"` }
A Step in a test.
type Test ¶
type Test struct { // Name of the test. Name string `yaml:"name"` // Description of the test. Description string `yaml:"description"` // Test steps to run. Steps []*Step `yaml:"steps"` // Options to apply to all steps in the test by default. Options Options `yaml:"options"` }
A Test to be executed.
Click to show internal directories.
Click to hide internal directories.