From 9b649594c6f6ae7249710fe0aeddce4187a78e13 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 4 Mar 2020 13:01:18 +0100 Subject: [PATCH] update tests --- .../unset_used_string_variable.pkr.hcl | 6 +---- hcl2template/types.packer_config_test.go | 5 +++- hcl2template/types.variables_test.go | 23 +++++++++---------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/hcl2template/testdata/variables/unset_used_string_variable.pkr.hcl b/hcl2template/testdata/variables/unset_used_string_variable.pkr.hcl index 3f4a9c7cb..f8060cccf 100644 --- a/hcl2template/testdata/variables/unset_used_string_variable.pkr.hcl +++ b/hcl2template/testdata/variables/unset_used_string_variable.pkr.hcl @@ -5,10 +5,6 @@ variable "foo" { build { sources = [ - "source.null.null-builder", + "source.null.null-builder${var.foo}", ] } - -source "null" "null-builder" { - communicator = var.foo -} diff --git a/hcl2template/types.packer_config_test.go b/hcl2template/types.packer_config_test.go index 334d9bd8a..d84cef1fc 100644 --- a/hcl2template/types.packer_config_test.go +++ b/hcl2template/types.packer_config_test.go @@ -23,7 +23,8 @@ func TestParser_complete(t *testing.T) { Basedir: "testdata/complete", InputVariables: Variables{ "foo": &Variable{ - Name: "foo", + Name: "foo", + DefaultValue: cty.StringVal("value"), }, "image_id": &Variable{ Name: "image_id", @@ -48,12 +49,14 @@ func TestParser_complete(t *testing.T) { DefaultValue: cty.StringVal("value_image-id-default"), }, "standard_tags": &Variable{ + Name: "standard_tags", DefaultValue: cty.ObjectVal(map[string]cty.Value{ "Component": cty.StringVal("user-service"), "Environment": cty.StringVal("production"), }), }, "abc_map": &Variable{ + Name: "abc_map", DefaultValue: cty.TupleVal([]cty.Value{ cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("a"), diff --git a/hcl2template/types.variables_test.go b/hcl2template/types.variables_test.go index 13ca9298f..b4cd03b78 100644 --- a/hcl2template/types.variables_test.go +++ b/hcl2template/types.variables_test.go @@ -142,22 +142,12 @@ func TestParse_variables(t *testing.T) { Name: "foo", }, }, - Sources: map[SourceRef]*SourceBlock{ - SourceRef{"null", "null-builder"}: &SourceBlock{ - Name: "null-builder", - Type: "null", - }, - }, - Builds: Builds{ - &BuildBlock{ - Sources: []SourceRef{SourceRef{"null", "null-builder"}}, - }, - }, }, true, true, []packer.Build{}, - false, + true, }, + {"unset unused variable", defaultParser, parseTestArgs{"testdata/variables/unset_unused_string_variable.pkr.hcl", nil}, @@ -187,9 +177,12 @@ func TestParse_variables(t *testing.T) { Builder: &null.Builder{}, Provisioners: []packer.CoreBuildProvisioner{}, PostProcessors: [][]packer.CoreBuildPostProcessor{}, + Prepared: true, }, }, + false, }, + {"locals within another locals usage in different files", defaultParser, parseTestArgs{"testdata/variables/complicated", nil}, @@ -197,23 +190,29 @@ func TestParse_variables(t *testing.T) { Basedir: "testdata/variables/complicated", InputVariables: Variables{ "name_prefix": &Variable{ + Name: "name_prefix", DefaultValue: cty.StringVal("foo"), }, }, LocalVariables: Variables{ "name_prefix": &Variable{ + Name: "name_prefix", DefaultValue: cty.StringVal("foo"), }, "foo": &Variable{ + Name: "foo", DefaultValue: cty.StringVal("foo"), }, "bar": &Variable{ + Name: "bar", DefaultValue: cty.StringVal("foo"), }, "for_var": &Variable{ + Name: "for_var", DefaultValue: cty.StringVal("foo"), }, "bar_var": &Variable{ + Name: "bar_var", DefaultValue: cty.TupleVal([]cty.Value{ cty.StringVal("foo"), cty.StringVal("foo"),