From 6f4d79799b8c3f0c487f4a14b74ef2468bd7e446 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Tue, 23 Jun 2020 15:40:54 +0200 Subject: [PATCH] add thorough test --- command/inspect_test.go | 39 ++++++++++++++++++- .../hcl/inspect/aws-builds.pkr.hcl | 29 ++++++++++++++ .../{vars => inspect}/fruit_string.pkr.hcl | 0 .../hcl/inspect/virtualbox-builds.pkr.hcl | 0 hcl2template/types.packer_config.go | 12 +++++- 5 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 command/test-fixtures/hcl/inspect/aws-builds.pkr.hcl rename command/test-fixtures/hcl/{vars => inspect}/fruit_string.pkr.hcl (100%) create mode 100644 command/test-fixtures/hcl/inspect/virtualbox-builds.pkr.hcl diff --git a/command/inspect_test.go b/command/inspect_test.go index 27f8474da..573b99680 100644 --- a/command/inspect_test.go +++ b/command/inspect_test.go @@ -29,6 +29,10 @@ local.fruit: "banana" > : + sources: + + null.builder + provisioners: shell-local @@ -38,7 +42,7 @@ local.fruit: "banana" `}, - {[]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: @@ -49,6 +53,39 @@ var.fruit: "peach" [debug: {Type:cty.String,CmdValue:peach,VarfileValue:null,Env > 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 + `}, } diff --git a/command/test-fixtures/hcl/inspect/aws-builds.pkr.hcl b/command/test-fixtures/hcl/inspect/aws-builds.pkr.hcl new file mode 100644 index 000000000..60385b31f --- /dev/null +++ b/command/test-fixtures/hcl/inspect/aws-builds.pkr.hcl @@ -0,0 +1,29 @@ + + +build { + name = "aws_example_builder" + description = <", i) } 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 \n") + } + for _, source := range build.Sources { + fmt.Fprintf(out, "\n %s\n", source) + } fmt.Fprintf(out, "\n provisioners:\n\n") if len(build.ProvisionerBlocks) == 0 { fmt.Fprintf(out, " \n") @@ -485,7 +495,7 @@ func (p *PackerConfig) printBuilds() string { fmt.Fprintf(out, " \n") } for _, pp := range build.PostProcessors { - str := strings.Join([]string{pp.PType, pp.PName}, ".") + str := pp.PType if pp.PName != "" { str = strings.Join([]string{pp.PType, pp.PName}, ".") }