diff --git a/command/exec_test.go b/command/exec_test.go index 2ffc7fefa..d9508a090 100644 --- a/command/exec_test.go +++ b/command/exec_test.go @@ -85,6 +85,8 @@ func TestHelperProcess(*testing.T) { switch cmd { case "console": os.Exit((&ConsoleCommand{Meta: commandMeta()}).Run(args)) + case "inspect": + os.Exit((&InspectCommand{Meta: commandMeta()}).Run(args)) default: fmt.Fprintf(os.Stderr, "Unknown command %q\n", cmd) os.Exit(2) diff --git a/command/inspect_test.go b/command/inspect_test.go index d47dcf0d9..35575e2c9 100644 --- a/command/inspect_test.go +++ b/command/inspect_test.go @@ -1 +1,57 @@ 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: + + > : + + provisioners: + + shell-local + + post-processors: + + + +`}, + } + + 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) + } + }) + } +}