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.
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.
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.
MockExprLiteral returns a hcl.Expression that evaluates to the given literal value.
MockExprTraversal returns a hcl.Expression that evaluates the given absolute traversal.
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.
MockExprVariable returns a hcl.Expression that evaluates to the value of the variable with the given name.