add test for unset variable
This commit is contained in:
parent
00c812cfe8
commit
79867ca26e
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/hcl/v2"
|
||||
"github.com/hashicorp/hcl/v2/hclparse"
|
||||
"github.com/hashicorp/packer/builder/null"
|
||||
. "github.com/hashicorp/packer/hcl2template/internal"
|
||||
"github.com/hashicorp/packer/helper/config"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
|
@ -21,6 +22,7 @@ func getBasicParser() *Parser {
|
|||
BuilderSchemas: packer.MapOfBuilder{
|
||||
"amazon-ebs": func() (packer.Builder, error) { return &MockBuilder{}, nil },
|
||||
"virtualbox-iso": func() (packer.Builder, error) { return &MockBuilder{}, nil },
|
||||
"null": func() (packer.Builder, error) { return &null.Builder{}, nil },
|
||||
},
|
||||
ProvisionersSchemas: packer.MapOfProvisioner{
|
||||
"shell": func() (packer.Provisioner, error) { return &MockProvisioner{}, nil },
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
variable "foo" {
|
||||
type = string
|
||||
}
|
||||
|
||||
build {
|
||||
sources = [
|
||||
"source.null.null-builder",
|
||||
]
|
||||
}
|
||||
|
||||
source "null" "null-builder" {
|
||||
communicator = var.foo
|
||||
}
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/zclconf/go-cty/cty/convert"
|
||||
|
||||
"github.com/hashicorp/hcl/v2"
|
||||
"github.com/hashicorp/packer/builder/null"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
|
@ -97,6 +98,34 @@ func TestParse_variables(t *testing.T) {
|
|||
[]packer.Build{},
|
||||
false,
|
||||
},
|
||||
{"unset variable",
|
||||
defaultParser,
|
||||
parseTestArgs{"testdata/variables/unset_string_variable.pkr.hcl", nil},
|
||||
&PackerConfig{
|
||||
Basedir: filepath.Join("testdata", "variables"),
|
||||
InputVariables: Variables{
|
||||
"foo": &Variable{},
|
||||
},
|
||||
Sources: map[SourceRef]*SourceBlock{
|
||||
SourceRef{"null", "null-builder"}: &SourceBlock{
|
||||
Name: "null-builder",
|
||||
Type: "null",
|
||||
},
|
||||
},
|
||||
Builds: Builds{
|
||||
&BuildBlock{
|
||||
Sources: []SourceRef{SourceRef{"null", "null-builder"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
false, false,
|
||||
[]packer.Build{
|
||||
&packer.CoreBuild{
|
||||
Builder: &null.Builder{},
|
||||
},
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
testParse(t, tests)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue