packer-cn/hcl2template/types.source_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

85 lines
1.6 KiB
Go

package hcl2template
import (
"path/filepath"
"testing"
"github.com/hashicorp/packer/packer"
)
func TestParse_source(t *testing.T) {
defaultParser := getBasicParser()
tests := []parseTest{
{"two basic sources",
defaultParser,
parseTestArgs{"testdata/sources/basic.pkr.hcl", nil},
&PackerConfig{
Basedir: filepath.Join("testdata", "sources"),
Sources: map[SourceRef]*SourceBlock{
{
Type: "virtualbox-iso",
Name: "ubuntu-1204",
}: {
Type: "virtualbox-iso",
Name: "ubuntu-1204",
},
},
},
false, false,
[]packer.Build{},
false,
},
{"untyped source",
defaultParser,
parseTestArgs{"testdata/sources/untyped.pkr.hcl", nil},
&PackerConfig{
Basedir: filepath.Join("testdata", "sources"),
},
true, true,
nil,
false,
},
{"unnamed source",
defaultParser,
parseTestArgs{"testdata/sources/unnamed.pkr.hcl", nil},
&PackerConfig{
Basedir: filepath.Join("testdata", "sources"),
},
true, true,
nil,
false,
},
{"inexistent source",
defaultParser,
parseTestArgs{"testdata/sources/inexistent.pkr.hcl", nil},
&PackerConfig{
Basedir: filepath.Join("testdata", "sources"),
},
true, true,
nil,
false,
},
{"duplicate source",
defaultParser,
parseTestArgs{"testdata/sources/duplicate.pkr.hcl", nil},
&PackerConfig{
Basedir: filepath.Join("testdata", "sources"),
Sources: map[SourceRef]*SourceBlock{
{
Type: "virtualbox-iso",
Name: "ubuntu-1204",
}: {
Type: "virtualbox-iso",
Name: "ubuntu-1204",
},
},
},
true, true,
nil,
false,
},
}
testParse(t, tests)
}