add thorough test

This commit is contained in:
Adrien Delorme 2020-06-23 15:40:54 +02:00
parent dabcc866e5
commit 6f4d79799b
5 changed files with 78 additions and 2 deletions

View File

@ -29,6 +29,10 @@ local.fruit: "banana"
> <unnamed build 0>: > <unnamed build 0>:
sources:
null.builder
provisioners: provisioners:
shell-local shell-local
@ -38,7 +42,7 @@ local.fruit: "banana"
<no post-processor> <no post-processor>
`}, `},
{[]string{"inspect", "-var=fruit=peach", filepath.Join(testFixture("hcl"), "vars", "fruit_string.pkr.hcl")}, nil, `Packer Inspect: HCL2 mode {[]string{"inspect", "-var=fruit=peach", filepath.Join(testFixture("hcl"), "inspect", "fruit_string.pkr.hcl")}, nil, `Packer Inspect: HCL2 mode
> input-variables: > input-variables:
@ -49,6 +53,39 @@ var.fruit: "peach" [debug: {Type:cty.String,CmdValue:peach,VarfileValue:null,Env
> builds: > 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
`}, `},
} }

View File

@ -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" {
}
}

View File

@ -469,6 +469,16 @@ func (p *PackerConfig) printBuilds() string {
name = fmt.Sprintf("<unnamed build %d>", i) name = fmt.Sprintf("<unnamed build %d>", i)
} }
fmt.Fprintf(out, "\n > %s:\n", name) fmt.Fprintf(out, "\n > %s:\n", name)
if build.Description != "" {
fmt.Fprintf(out, "\n > Description: %s\n", build.Description)
}
fmt.Fprintf(out, "\n sources:\n")
if len(build.Sources) == 0 {
fmt.Fprintf(out, "\n <no source>\n")
}
for _, source := range build.Sources {
fmt.Fprintf(out, "\n %s\n", source)
}
fmt.Fprintf(out, "\n provisioners:\n\n") fmt.Fprintf(out, "\n provisioners:\n\n")
if len(build.ProvisionerBlocks) == 0 { if len(build.ProvisionerBlocks) == 0 {
fmt.Fprintf(out, " <no provisioner>\n") fmt.Fprintf(out, " <no provisioner>\n")
@ -485,7 +495,7 @@ func (p *PackerConfig) printBuilds() string {
fmt.Fprintf(out, " <no post-processor>\n") fmt.Fprintf(out, " <no post-processor>\n")
} }
for _, pp := range build.PostProcessors { for _, pp := range build.PostProcessors {
str := strings.Join([]string{pp.PType, pp.PName}, ".") str := pp.PType
if pp.PName != "" { if pp.PName != "" {
str = strings.Join([]string{pp.PType, pp.PName}, ".") str = strings.Join([]string{pp.PType, pp.PName}, ".")
} }