packer-cn/hcl2template/types.datasource_test.go

94 lines
1.8 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{
Basedir: filepath.Join("testdata", "datasources"),
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{
Basedir: filepath.Join("testdata", "datasources"),
},
true, true,
nil,
false,
},
{"unnamed source",
defaultParser,
parseTestArgs{"testdata/datasources/unnamed.pkr.hcl", nil, nil},
&PackerConfig{
Basedir: filepath.Join("testdata", "datasources"),
},
true, true,
nil,
false,
},
{"inexistent source",
defaultParser,
parseTestArgs{"testdata/datasources/inexistent.pkr.hcl", nil, nil},
&PackerConfig{
Basedir: filepath.Join("testdata", "datasources"),
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{
Basedir: filepath.Join("testdata", "datasources"),
Datasources: Datasources{
{
Type: "amazon-ami",
Name: "test",
}: {
Type: "amazon-ami",
Name: "test",
},
},
},
true, true,
nil,
false,
},
}
testParse(t, tests)
}