mirror of https://github.com/hashicorp/packer
commit
7eda9eacc6
@ -0,0 +1,106 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func Test_commands(t *testing.T) {
|
||||
|
||||
tc := []struct {
|
||||
command []string
|
||||
env []string
|
||||
expected string
|
||||
}{
|
||||
{[]string{"inspect", "-var=fruit=banana", filepath.Join(testFixture("var-arg"), "fruit_builder.pkr.hcl")}, nil, `Packer Inspect: HCL2 mode
|
||||
|
||||
> input-variables:
|
||||
|
||||
var.fruit: "banana" [debug: {Type:cty.String,CmdValue:banana,VarfileValue:null,EnvValue:null,DefaultValue:null}]
|
||||
|
||||
> local-variables:
|
||||
|
||||
local.fruit: "banana"
|
||||
|
||||
> builds:
|
||||
|
||||
> <unnamed build 0>:
|
||||
|
||||
sources:
|
||||
|
||||
null.builder
|
||||
|
||||
provisioners:
|
||||
|
||||
shell-local
|
||||
|
||||
post-processors:
|
||||
|
||||
<no post-processor>
|
||||
|
||||
`},
|
||||
{[]string{"inspect", "-var=fruit=peach", filepath.Join(testFixture("hcl"), "inspect", "fruit_string.pkr.hcl")}, nil, `Packer Inspect: HCL2 mode
|
||||
|
||||
> input-variables:
|
||||
|
||||
var.fruit: "peach" [debug: {Type:cty.String,CmdValue:peach,VarfileValue:null,EnvValue:null,DefaultValue:banana}]
|
||||
|
||||
> local-variables:
|
||||
|
||||
|
||||
> builds:
|
||||
|
||||
`},
|
||||
{[]string{"inspect", "-var=fruit=peach", filepath.Join(testFixture("hcl"), "inspect")}, nil, `Packer Inspect: HCL2 mode
|
||||
|
||||
> input-variables:
|
||||
|
||||
var.fruit: "peach" [debug: {Type:cty.String,CmdValue:peach,VarfileValue:null,EnvValue:null,DefaultValue:banana}]
|
||||
|
||||
> local-variables:
|
||||
|
||||
|
||||
> builds:
|
||||
|
||||
> aws_example_builder:
|
||||
|
||||
> Description: The builder of clouds !!
|
||||
|
||||
Use it at will.
|
||||
|
||||
|
||||
sources:
|
||||
|
||||
amazon-ebs.example-1
|
||||
|
||||
amazon-ebs.example-2
|
||||
|
||||
provisioners:
|
||||
|
||||
shell
|
||||
|
||||
post-processors:
|
||||
|
||||
manifest
|
||||
|
||||
`},
|
||||
}
|
||||
|
||||
for _, tc := range tc {
|
||||
t.Run(fmt.Sprintf("packer %s", tc.command), func(t *testing.T) {
|
||||
p := helperCommand(t, tc.command...)
|
||||
p.Env = append(p.Env, tc.env...)
|
||||
bs, err := p.Output()
|
||||
if err != nil {
|
||||
t.Fatalf("%v: %s", err, bs)
|
||||
}
|
||||
actual := string(bs)
|
||||
if diff := cmp.Diff(tc.expected, actual); diff != "" {
|
||||
t.Fatalf("unexpected ouput %s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
|
||||
|
||||
build {
|
||||
name = "aws_example_builder"
|
||||
description = <<EOF
|
||||
The builder of clouds !!
|
||||
|
||||
Use it at will.
|
||||
EOF
|
||||
|
||||
sources = [
|
||||
"source.amazon-ebs.example-1",
|
||||
|
||||
// this one is not defined but we don't want to error there, we just
|
||||
// would like to show what sources are being referenced.
|
||||
"source.amazon-ebs.example-2",
|
||||
]
|
||||
|
||||
provisioner "shell" {
|
||||
files = [
|
||||
"bins/install-this.sh",
|
||||
"bins/install-that.sh",
|
||||
"bins/conf-this.sh",
|
||||
]
|
||||
}
|
||||
|
||||
post-processor "manifest" {
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
|
||||
variable "fruit" {
|
||||
type = string
|
||||
default = "banana"
|
||||
}
|
||||
Loading…
Reference in new issue