packer-cn/hcl2template/types.build_test.go
Adrien Delorme 193dad46e6
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.

* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 11:49:21 +01:00

106 lines
2.2 KiB
Go

package hcl2template
import (
"path/filepath"
"testing"
"github.com/hashicorp/packer/packer"
)
func TestParse_build(t *testing.T) {
defaultParser := getBasicParser()
tests := []parseTest{
{"basic build no src",
defaultParser,
parseTestArgs{"testdata/build/basic.pkr.hcl", nil},
&PackerConfig{
Basedir: filepath.Join("testdata", "build"),
Builds: Builds{
&BuildBlock{
Sources: []SourceRef{
{
Type: "amazon-ebs",
Name: "ubuntu-1604",
},
refVBIsoUbuntu1204,
},
ProvisionerBlocks: []*ProvisionerBlock{
{
PType: "shell",
},
{
PType: "file",
},
},
PostProcessors: []*PostProcessorBlock{
{
PType: "amazon-import",
},
},
},
},
},
false, false,
[]packer.Build{},
true,
},
{"untyped provisioner",
defaultParser,
parseTestArgs{"testdata/build/provisioner_untyped.pkr.hcl", nil},
&PackerConfig{
Basedir: filepath.Join("testdata", "build"),
Builds: nil,
},
true, true,
nil,
false,
},
{"inexistent provisioner",
defaultParser,
parseTestArgs{"testdata/build/provisioner_inexistent.pkr.hcl", nil},
&PackerConfig{
Basedir: filepath.Join("testdata", "build"),
Builds: nil,
},
true, true,
[]packer.Build{&packer.CoreBuild{}},
false,
},
{"untyped post-processor",
defaultParser,
parseTestArgs{"testdata/build/post-processor_untyped.pkr.hcl", nil},
&PackerConfig{
Basedir: filepath.Join("testdata", "build"),
Builds: nil,
},
true, true,
[]packer.Build{&packer.CoreBuild{}},
false,
},
{"inexistent post-processor",
defaultParser,
parseTestArgs{"testdata/build/post-processor_inexistent.pkr.hcl", nil},
&PackerConfig{
Basedir: filepath.Join("testdata", "build"),
Builds: nil,
},
true, true,
[]packer.Build{},
false,
},
{"invalid source",
defaultParser,
parseTestArgs{"testdata/build/invalid_source_reference.pkr.hcl", nil},
&PackerConfig{
Basedir: filepath.Join("testdata", "build"),
Builds: nil,
},
true, true,
[]packer.Build{},
false,
},
}
testParse(t, tests)
}