helper

package
v0.4.1-0...-5b560ab Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2020 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package helper contains implementations for plugin testing.

You can test the implemented rules using the mock Runner that is not an RPC client. It is similar to TFLint's Runner, but is implemented from scratch to avoid Terraform dependencies.

Some implementations of the mock Runner have been simplified. As a result, note that some features may not behave exactly as they should.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertIssues

func AssertIssues(t *testing.T, expected Issues, actual Issues)

AssertIssues is an assertion helper for comparing issues.

func AssertIssuesWithoutRange

func AssertIssuesWithoutRange(t *testing.T, expected Issues, actual Issues)

AssertIssuesWithoutRange is an assertion helper for comparing issues except for range.

Types

type Issue

type Issue struct {
	Rule    tflint.Rule
	Message string
	Range   hcl.Range
}

Issue is a stub that has the same structure as the actually used issue object. This is only used for testing, as the mock Runner doesn't depend on the actual Issue structure.

type Issues

type Issues []*Issue

Issues is a list of Issue.

type Runner

type Runner struct {
	Files  map[string]*hcl.File
	Issues Issues
}

Runner is a mock that satisfies the Runner interface for plugin testing.

func TestRunner

func TestRunner(t *testing.T, files map[string]string) *Runner

TestRunner returns a mock Runner for testing. You can pass the map of file names and their contents in the second argument.

func (*Runner) Backend

func (r *Runner) Backend() (*configs.Backend, error)

Backend returns the terraform backend configuration.

func (*Runner) Config

func (r *Runner) Config() (*configs.Config, error)

Config returns the Terraform configuration

func (*Runner) EmitIssue

func (r *Runner) EmitIssue(rule tflint.Rule, message string, location hcl.Range) error

EmitIssue adds an issue to the runner itself.

func (*Runner) EmitIssueOnExpr

func (r *Runner) EmitIssueOnExpr(rule tflint.Rule, message string, expr hcl.Expression) error

EmitIssueOnExpr adds an issue to the runner itself.

func (*Runner) EnsureNoError

func (r *Runner) EnsureNoError(err error, proc func() error) error

EnsureNoError is a method that simply runs a function if there is no error.

func (*Runner) EvaluateExpr

func (r *Runner) EvaluateExpr(expr hcl.Expression, ret interface{}) error

EvaluateExpr returns a value of the passed expression. Note that there is no evaluation, no type conversion, etc.

func (*Runner) EvaluateExprType

func (r *Runner) EvaluateExprType(expr hcl.Expression, ret interface{}, wantType cty.Type) error

EvaluateExprType returns a value of the passed expression. Note that there is no evaluation, no type conversion, etc.

func (*Runner) WalkModuleCalls

func (r *Runner) WalkModuleCalls(walker func(*configs.ModuleCall) error) error

WalkModuleCalls visits all module calls from Files.

func (*Runner) WalkResourceAttributes

func (r *Runner) WalkResourceAttributes(resourceType, attributeName string, walker func(*hcl.Attribute) error) error

WalkResourceAttributes visits all specified attributes from Files.

func (*Runner) WalkResourceBlocks

func (r *Runner) WalkResourceBlocks(resourceType, blockType string, walker func(*hcl.Block) error) error

WalkResourceBlocks visits all specified blocks from Files.

func (*Runner) WalkResources

func (r *Runner) WalkResources(resourceType string, walker func(*configs.Resource) error) error

WalkResources visits all specified resources from Files.

Jump to

Keyboard shortcuts

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