tester

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package tester contains utilities for executing Rego tests.

Index

Constants

View Source
const TestPrefix = "test_"

TestPrefix declares the prefix for all rules.

Variables

This section is empty.

Functions

func Load added in v0.5.9

func Load(args []string) (map[string]*ast.Module, storage.Store, error)

Load returns modules and an in-memory store for running tests.

Types

type JSONCoverageReporter added in v0.8.0

type JSONCoverageReporter struct {
	Cover   *cover.Cover
	Modules map[string]*ast.Module
	Output  io.Writer
}

JSONCoverageReporter reports coverage as a JSON structure.

func (JSONCoverageReporter) Report added in v0.8.0

func (r JSONCoverageReporter) Report(ch chan *Result) error

Report prints the test report to the reporter's output. If any tests fail or encounter errors, this function returns an error.

type JSONReporter added in v0.8.0

type JSONReporter struct {
	Output io.Writer
}

JSONReporter reports test results as array of JSON objects.

func (JSONReporter) Report added in v0.8.0

func (r JSONReporter) Report(ch chan *Result) error

Report prints the test report to the reporter's output.

type PrettyReporter

type PrettyReporter struct {
	Output  io.Writer
	Verbose bool
}

PrettyReporter reports test results in a simple human readable format.

func (PrettyReporter) Report

func (r PrettyReporter) Report(ch chan *Result) error

Report prints the test report to the reporter's output.

type Reporter added in v0.8.0

type Reporter interface {

	// Report is called with a channel that will contain test results.
	Report(ch chan *Result) error
}

Reporter defines the interface for reporting test results.

type Result

type Result struct {
	Location *ast.Location `json:"location"`
	Package  string        `json:"package"`
	Name     string        `json:"name"`
	Fail     *interface{}  `json:"fail,omitempty"`
	Error    error         `json:"error,omitempty"`
	Duration time.Duration `json:"duration"`
}

Result represents a single test case result.

func Run

func Run(ctx context.Context, paths ...string) ([]*Result, error)

Run executes all test cases found under files in path.

func (Result) Pass

func (r Result) Pass() bool

Pass returns true if the test case passed.

func (*Result) String

func (r *Result) String() string

type Runner

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

Runner implements simple test discovery and execution.

func NewRunner

func NewRunner() *Runner

NewRunner returns a new runner.

func (*Runner) Run added in v0.5.9

func (r *Runner) Run(ctx context.Context, modules map[string]*ast.Module) (ch chan *Result, err error)

Run executes all tests contained in supplied modules.

func (*Runner) SetCompiler

func (r *Runner) SetCompiler(compiler *ast.Compiler) *Runner

SetCompiler sets the compiler used by the runner.

func (*Runner) SetStore added in v0.5.9

func (r *Runner) SetStore(store storage.Store) *Runner

SetStore sets the store to execute tests over.

func (*Runner) SetTracer added in v0.8.0

func (r *Runner) SetTracer(tracer topdown.Tracer) *Runner

SetTracer sets the tracer to use during test execution.

Jump to

Keyboard shortcuts

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