testcases

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

package testcases defines the Case data structure, and a public function for instantiating slices of Cases from JSON test specifications in directory trees on the filesystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Case

type Case struct {
	Config  CaseConfig
	Result  Result
	Skipped bool
	Done    chan struct{}
}

Case is an executable test case. The Config property can be accessed to get information about the case scenario.

func All

func All(opts *TestsCasesOpts) ([]*Case, error)

All returns an array of executable test cases for the directory tree specified by testsRoot. Tests will be executable against the given target.

Cases recursively traverses down the testsRoot directory and collects all test cases it finds. *Any* file in the dir tree which is not a directory or a well-formed JSON test case will cause this function to return an error.

func NewCase

func NewCase(config CaseConfig) *Case

NewCase instantiates and returns a Case struct.

func (*Case) Exec

func (c *Case) Exec(ctx context.Context, pathsRoot string)

Exec executes a test Case and populates the Case's Result struct. The Result is unsuccessful and an error is stored in any of three cases:

  1. The response was invalid for the request according to the OAPI schema.
  2. The response contents did not satisfy the Case's expectations (if any).
  3. Other reasons pertaining to the case specification or the environment. For example, the case contains an invalid route or cannot be unmarshaled (is ill-formed), or a network condition prevented contacting the target.

Otherwise, the Result is marked as a Success and the Error is left nil.

func (Case) ResultsPretty added in v0.2.0

func (c Case) ResultsPretty() string

ResultsPretty returns human-readable test results output suitable for printing to a CLI.

type CaseConfig

type CaseConfig struct {
	Method             string
	Route              string
	AwaitSlot          int
	QueryParams        map[string]string
	ReqBody            interface{}
	ExpectedRespStatus int
	ExpectedRespBody   interface{}
}

CaseConfig describes a test scenario.

type OapiError

type OapiError struct {
	Err            error
	ServerResponse []byte
}

func (OapiError) Error

func (e OapiError) Error() string

type Result

type Result struct {
	Success bool
	Error   error
}

Result describes the result of a test. Error is nil is success is true.

type TestSpecificationError

type TestSpecificationError struct {
	Filepath string
	Err      error
}

func (TestSpecificationError) Error

func (e TestSpecificationError) Error() string

type TestsCasesOpts

type TestsCasesOpts struct {
	// target is a URL hosting an Ethereum 2.0 API where test requests should
	// be sent. For example, http://localhost:5051
	Target string
	// TestsRemote is a URL to a zip file containing a directory tree
	// containing well-specified JSON tests cases.
	TestsRemote string
	// OutDir is the directory where zip files will be downloaded, and
	// unzipped.
	OutDir string
	// testsRoot is a file path to a directory tree containing well-specified
	// JSON tests cases.
	TestsRoot string
}

TestsCasesOpts are used to configure statically defined test cases with dynamic values at runtime.

type UnimplementedOperationError

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

func (UnimplementedOperationError) Error

Jump to

Keyboard shortcuts

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