Commit 76c10596 authored by Megan Marsh's avatar Megan Marsh
Browse files

add tests, and simplify code

Showing with 37 additions and 6 deletions
+37 -6
......@@ -13,7 +13,7 @@ source "amazon-ebs" "ubuntu-1604" {
}
source "virtualbox-iso" "ubuntu-1204" {
string = "string"
string = "${source.name}-${source.type}"
int = 42
int64 = 43
bool = true
......
......@@ -3,9 +3,11 @@ package hcl2template
import (
"path/filepath"
"testing"
"time"
"github.com/hashicorp/go-version"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/template/config"
"github.com/hashicorp/packer/hcl2template/addrs"
. "github.com/hashicorp/packer/hcl2template/internal"
hcl2template "github.com/hashicorp/packer/hcl2template/internal"
......@@ -204,7 +206,39 @@ func TestParser_complete(t *testing.T) {
&packer.CoreBuild{
Type: "virtualbox-iso.ubuntu-1204",
Prepared: true,
Builder: basicMockBuilder,
Builder: &MockBuilder{
Config: MockConfig{
NestedMockConfig: NestedMockConfig{
// interpolates source and type in builder
String: "ubuntu-1204-virtualbox-iso",
Int: 42,
Int64: 43,
Bool: true,
Trilean: config.TriTrue,
Duration: 10 * time.Second,
MapStringString: map[string]string{
"a": "b",
"c": "d",
},
SliceString: []string{
"a",
"b",
"c",
},
SliceSliceString: [][]string{
{"a", "b"},
{"c", "d"},
},
Tags: []MockTag{},
Datasource: "string",
},
Nested: builderBasicNestedMockConfig,
NestedSlice: []NestedMockConfig{
builderBasicNestedMockConfig,
builderBasicNestedMockConfig,
},
},
},
Provisioners: []packer.CoreBuildProvisioner{
{
PType: "shell",
......
......@@ -111,10 +111,7 @@ func (cfg *PackerConfig) startBuilder(source SourceUseBlock, ectx *hcl.EvalConte
body := source.Body
// Add known values to source accessor in eval context.
ectx.Variables[sourcesAccessor] = cty.ObjectVal(map[string]cty.Value{
"type": cty.StringVal(source.Type),
"name": cty.StringVal(source.Name),
})
ectx.Variables[sourcesAccessor] = cty.ObjectVal(source.ctyValues())
decoded, moreDiags := decodeHCL2Spec(body, ectx, builder)
diags = append(diags, moreDiags...)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment