hcl2: github.com/hashicorp/hcl2/hcltest Index | Files

package hcltest

import "github.com/hashicorp/hcl2/hcltest"

Package hcltest contains utilities that aim to make it more convenient to write tests for code that interacts with the HCL API.

This package is intended for use only in test code. It is optimized for convenience of use over all other concerns.

Index

Package Files

doc.go mock.go

func MockAttrs Uses

func MockAttrs(exprs map[string]hcl.Expression) hcl.Attributes

MockAttrs constructs and returns a hcl.Attributes map with attributes derived from the given expression map.

Each entry in the map becomes an attribute whose name is the key and whose expression is the value.

func MockBody Uses

func MockBody(content *hcl.BodyContent) hcl.Body

MockBody returns a hcl.Body implementation that works in terms of a caller-constructed hcl.BodyContent, thus avoiding the need to parse a "real" HCL config file to use as input to a test.

func MockExprList Uses

func MockExprList(exprs []hcl.Expression) hcl.Expression

func MockExprLiteral Uses

func MockExprLiteral(val cty.Value) hcl.Expression

MockExprLiteral returns a hcl.Expression that evaluates to the given literal value.

func MockExprTraversal Uses

func MockExprTraversal(traversal hcl.Traversal) hcl.Expression

MockExprTraversal returns a hcl.Expression that evaluates the given absolute traversal.

func MockExprTraversalSrc Uses

func MockExprTraversalSrc(src string) hcl.Expression

MockExprTraversalSrc is like MockExprTraversal except it takes a traversal string as defined by the native syntax and parses it first.

This method is primarily for testing with hard-coded traversal strings, so it will panic if the given string is not syntactically correct.

func MockExprVariable Uses

func MockExprVariable(name string) hcl.Expression

MockExprVariable returns a hcl.Expression that evaluates to the value of the variable with the given name.

Package hcltest imports 4 packages (graph). Updated 2018-07-27. Refresh now. Tools for package owners.