hcltest

package
v2.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func MockAttrs

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

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

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

func MockExprLiteral

func MockExprLiteral(val cty.Value) hcl.Expression

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

func MockExprTraversal

func MockExprTraversal(traversal hcl.Traversal) hcl.Expression

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

func MockExprTraversalSrc

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

func MockExprVariable(name string) hcl.Expression

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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