From 56c2b5ad8b1fe4be98889adb7a92f8cf6f3dd35a Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 3 May 2024 11:06:16 -0400 Subject: [PATCH] test: call different packer cmds for loading tests --- test/loading_test.go | 52 ++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/test/loading_test.go b/test/loading_test.go index 38af28c04..c12f019d2 100644 --- a/test/loading_test.go +++ b/test/loading_test.go @@ -16,25 +16,39 @@ func (ts *PackerTestSuite) TestLoadingOrder() { } }() - tests := []struct { - name string - templatePath string - }{ - { - "HCL2 - No required_plugins, 1.0.10 is the most recent and should load", - "./templates/simple.pkr.hcl", - }, - } + for _, command := range []string{"build", "validate"} { + tests := []struct { + name string + templatePath string + grepStr string + }{ + { + "HCL2 " + command + " - With required_plugins, 1.0.10 is the most recent and should load", + "./templates/simple.pkr.hcl", + "packer-plugin-tester_v1\\.0\\.10[^\n]+ plugin:", + }, + { + "JSON " + command + " - No required_plugins, 1.0.10 is the most recent and should load", + "./templates/simple.json", + "packer-plugin-tester_v1\\.0\\.10[^\n]+ plugin:", + }, + { + "HCL2 " + command + " - With required_plugins, 1.0.9 is pinned, so 1.0.9 should be used", + "./templates/pin_1.0.9.pkr.hcl", + "packer-plugin-tester_v1\\.0\\.9[^\n]+ plugin:", + }, + } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ts.PackerCommand(). - SetArgs("build", tt.templatePath). - AddEnv("PACKER_PLUGIN_PATH", pluginDir). - Assert(t, MustSucceed{}, Grep{ - streams: BothStreams, - expect: "packer-plugin-tester_v1\\.0\\.10[^\n]+ plugin:", - }) - }) + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ts.PackerCommand(). + SetArgs(command, tt.templatePath). + AddEnv("PACKER_PLUGIN_PATH", pluginDir). + Assert(t, MustSucceed{}, Grep{ + streams: BothStreams, + expect: tt.grepStr, + }) + }) + } } }