packer-cn/hcl2template/types.datasource_test.go

126 lines
2.7 KiB
Go
Raw Normal View History

2021-01-20 04:37:16 -05:00
package hcl2template
import (
"path/filepath"
"testing"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
)
func TestParse_datasource(t *testing.T) {
defaultParser := getBasicParser()
tests := []parseTest{
{"two basic datasources",
defaultParser,
parseTestArgs{"testdata/datasources/basic.pkr.hcl", nil, nil},
&PackerConfig{
CorePackerVersionString: lockedVersion,
Basedir: filepath.Join("testdata", "datasources"),
2021-01-20 04:37:16 -05:00
Datasources: Datasources{
{
Type: "amazon-ami",
Name: "test",
}: {
Type: "amazon-ami",
Name: "test",
},
},
},
false, false,
[]packersdk.Build{},
false,
},
{"untyped datasource",
defaultParser,
parseTestArgs{"testdata/datasources/untyped.pkr.hcl", nil, nil},
&PackerConfig{
CorePackerVersionString: lockedVersion,
Basedir: filepath.Join("testdata", "datasources"),
2021-01-20 04:37:16 -05:00
},
true, true,
nil,
false,
},
{"unnamed source",
defaultParser,
parseTestArgs{"testdata/datasources/unnamed.pkr.hcl", nil, nil},
&PackerConfig{
CorePackerVersionString: lockedVersion,
Basedir: filepath.Join("testdata", "datasources"),
2021-01-20 04:37:16 -05:00
},
true, true,
nil,
false,
},
{"not allowed usage of data source within another data source",
defaultParser,
parseTestArgs{"testdata/datasources/not-allowed.pkr.hcl", nil, nil},
&PackerConfig{
CorePackerVersionString: lockedVersion,
Basedir: filepath.Join("testdata", "datasources"),
Datasources: Datasources{
{
Type: "amazon-ami",
Name: "test_0",
}: {
Type: "amazon-ami",
Name: "test_0",
},
{
Type: "amazon-ami",
Name: "test_1",
}: {
Type: "amazon-ami",
Name: "test_1",
},
},
},
true, true,
nil,
false,
},
2021-01-20 04:37:16 -05:00
{"inexistent source",
defaultParser,
parseTestArgs{"testdata/datasources/inexistent.pkr.hcl", nil, nil},
&PackerConfig{
CorePackerVersionString: lockedVersion,
Basedir: filepath.Join("testdata", "datasources"),
2021-01-20 04:37:16 -05:00
Datasources: Datasources{
{
Type: "inexistant",
Name: "test",
}: {
Type: "inexistant",
Name: "test",
},
},
},
true, true,
nil,
false,
},
{"duplicate source",
defaultParser,
parseTestArgs{"testdata/datasources/duplicate.pkr.hcl", nil, nil},
&PackerConfig{
CorePackerVersionString: lockedVersion,
Basedir: filepath.Join("testdata", "datasources"),
2021-01-20 04:37:16 -05:00
Datasources: Datasources{
{
Type: "amazon-ami",
Name: "test",
}: {
Type: "amazon-ami",
Name: "test",
},
},
},
true, true,
nil,
false,
},
}
testParse(t, tests)
}