From 35b2317ef3b34742369cdbcf498e8993a820e9ff Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Thu, 15 Aug 2024 10:05:27 -0400 Subject: [PATCH] packer_test: rename/split lib into common/check The lib name for the common components for writing packer_test suites was not clear, and did not follow the convention established in Packer core and plugins. Therefore this commit does two things: first the lib is renamed into common as to follow this convention, and clearly document which components are common to all tests. Also checkers are placed in a subpackage of common, common/check, so that it is clearer what is meant to be used as checks for a command's execution status after it's been run, as part of Assert. --- packer_test/{lib => common}/base.go | 2 +- packer_test/{lib => common/check}/gadgets.go | 2 +- .../{lib => common/check}/pipe_checker.go | 2 +- packer_test/{lib => common}/commands.go | 14 ++- packer_test/{lib => common}/fs.go | 2 +- packer_test/{lib => common}/plugin.go | 5 +- .../{lib => common}/plugin_tester/LICENSE | 0 .../{lib => common}/plugin_tester/README.md | 0 .../plugin_tester/builder/dynamic/artifact.go | 0 .../plugin_tester/builder/dynamic/builder.go | 0 .../builder/dynamic/builder.hcl2spec.go | 0 .../builder/dynamic/builder_acc_test.go | 0 .../builder/dynamic/step_say_config.go | 0 .../dynamic/test-fixtures/template.pkr.hcl | 0 .../plugin_tester/datasource/dynamic/data.go | 0 .../datasource/dynamic/data.hcl2spec.go | 0 .../datasource/dynamic/data_acc_test.go | 0 .../dynamic/test-fixtures/template.pkr.hcl | 0 .../plugin_tester/datasource/parrot/data.go | 0 .../datasource/parrot/data.hcl2spec.go | 0 .../plugin_tester/datasource/sleeper/data.go | 0 .../datasource/sleeper/data.hcl2spec.go | 0 .../plugin_tester/docs/README.md | 0 .../docs/builders/builder-name.mdx | 0 .../docs/datasources/datasource-name.mdx | 0 .../post-processors/postprocessor-name.mdx | 0 .../docs/provisioners/provisioner-name.mdx | 0 .../plugin_tester/example/README.md | 0 .../plugin_tester/example/build.pkr.hcl | 0 .../plugin_tester/example/data.pkr.hcl | 0 .../plugin_tester/example/variables.pkr.hcl | 0 .../{lib => common}/plugin_tester/go.mod | 0 .../{lib => common}/plugin_tester/go.sum | 0 .../{lib => common}/plugin_tester/main.go | 0 .../post-processor/dynamic/post-processor.go | 0 .../dynamic/post-processor.hcl2spec.go | 0 .../dynamic/post-processor_acc_test.go | 0 .../dynamic/test-fixtures/template.pkr.hcl | 0 .../provisioner/dynamic/provisioner.go | 0 .../dynamic/provisioner.hcl2spec.go | 0 .../dynamic/provisioner_acc_test.go | 0 .../dynamic/test-fixtures/template.pkr.hcl | 0 .../plugin_tester/version/version.go | 0 packer_test/{lib => common}/suite.go | 2 +- packer_test/core_tests/local_eval_test.go | 12 +- packer_test/core_tests/suite_test.go | 6 +- packer_test/plugin_tests/init_test.go | 22 ++-- packer_test/plugin_tests/install_test.go | 36 +++--- packer_test/plugin_tests/loading_test.go | 107 +++++++++--------- .../plugin_tests/plugins_remove_test.go | 54 ++++----- packer_test/plugin_tests/suite_test.go | 6 +- 51 files changed, 138 insertions(+), 134 deletions(-) rename packer_test/{lib => common}/base.go (98%) rename packer_test/{lib => common/check}/gadgets.go (99%) rename packer_test/{lib => common/check}/pipe_checker.go (99%) rename packer_test/{lib => common}/commands.go (92%) rename packer_test/{lib => common}/fs.go (99%) rename packer_test/{lib => common}/plugin.go (98%) rename packer_test/{lib => common}/plugin_tester/LICENSE (100%) rename packer_test/{lib => common}/plugin_tester/README.md (100%) rename packer_test/{lib => common}/plugin_tester/builder/dynamic/artifact.go (100%) rename packer_test/{lib => common}/plugin_tester/builder/dynamic/builder.go (100%) rename packer_test/{lib => common}/plugin_tester/builder/dynamic/builder.hcl2spec.go (100%) rename packer_test/{lib => common}/plugin_tester/builder/dynamic/builder_acc_test.go (100%) rename packer_test/{lib => common}/plugin_tester/builder/dynamic/step_say_config.go (100%) rename packer_test/{lib => common}/plugin_tester/builder/dynamic/test-fixtures/template.pkr.hcl (100%) rename packer_test/{lib => common}/plugin_tester/datasource/dynamic/data.go (100%) rename packer_test/{lib => common}/plugin_tester/datasource/dynamic/data.hcl2spec.go (100%) rename packer_test/{lib => common}/plugin_tester/datasource/dynamic/data_acc_test.go (100%) rename packer_test/{lib => common}/plugin_tester/datasource/dynamic/test-fixtures/template.pkr.hcl (100%) rename packer_test/{lib => common}/plugin_tester/datasource/parrot/data.go (100%) rename packer_test/{lib => common}/plugin_tester/datasource/parrot/data.hcl2spec.go (100%) rename packer_test/{lib => common}/plugin_tester/datasource/sleeper/data.go (100%) rename packer_test/{lib => common}/plugin_tester/datasource/sleeper/data.hcl2spec.go (100%) rename packer_test/{lib => common}/plugin_tester/docs/README.md (100%) rename packer_test/{lib => common}/plugin_tester/docs/builders/builder-name.mdx (100%) rename packer_test/{lib => common}/plugin_tester/docs/datasources/datasource-name.mdx (100%) rename packer_test/{lib => common}/plugin_tester/docs/post-processors/postprocessor-name.mdx (100%) rename packer_test/{lib => common}/plugin_tester/docs/provisioners/provisioner-name.mdx (100%) rename packer_test/{lib => common}/plugin_tester/example/README.md (100%) rename packer_test/{lib => common}/plugin_tester/example/build.pkr.hcl (100%) rename packer_test/{lib => common}/plugin_tester/example/data.pkr.hcl (100%) rename packer_test/{lib => common}/plugin_tester/example/variables.pkr.hcl (100%) rename packer_test/{lib => common}/plugin_tester/go.mod (100%) rename packer_test/{lib => common}/plugin_tester/go.sum (100%) rename packer_test/{lib => common}/plugin_tester/main.go (100%) rename packer_test/{lib => common}/plugin_tester/post-processor/dynamic/post-processor.go (100%) rename packer_test/{lib => common}/plugin_tester/post-processor/dynamic/post-processor.hcl2spec.go (100%) rename packer_test/{lib => common}/plugin_tester/post-processor/dynamic/post-processor_acc_test.go (100%) rename packer_test/{lib => common}/plugin_tester/post-processor/dynamic/test-fixtures/template.pkr.hcl (100%) rename packer_test/{lib => common}/plugin_tester/provisioner/dynamic/provisioner.go (100%) rename packer_test/{lib => common}/plugin_tester/provisioner/dynamic/provisioner.hcl2spec.go (100%) rename packer_test/{lib => common}/plugin_tester/provisioner/dynamic/provisioner_acc_test.go (100%) rename packer_test/{lib => common}/plugin_tester/provisioner/dynamic/test-fixtures/template.pkr.hcl (100%) rename packer_test/{lib => common}/plugin_tester/version/version.go (100%) rename packer_test/{lib => common}/suite.go (99%) diff --git a/packer_test/lib/base.go b/packer_test/common/base.go similarity index 98% rename from packer_test/lib/base.go rename to packer_test/common/base.go index a54c43a1c..3e94d0394 100644 --- a/packer_test/lib/base.go +++ b/packer_test/common/base.go @@ -1,4 +1,4 @@ -package lib +package common import ( "fmt" diff --git a/packer_test/lib/gadgets.go b/packer_test/common/check/gadgets.go similarity index 99% rename from packer_test/lib/gadgets.go rename to packer_test/common/check/gadgets.go index 5fae9d97d..9eecc57cf 100644 --- a/packer_test/lib/gadgets.go +++ b/packer_test/common/check/gadgets.go @@ -1,4 +1,4 @@ -package lib +package check import ( "fmt" diff --git a/packer_test/lib/pipe_checker.go b/packer_test/common/check/pipe_checker.go similarity index 99% rename from packer_test/lib/pipe_checker.go rename to packer_test/common/check/pipe_checker.go index 1279b5b9c..014d6dfc9 100644 --- a/packer_test/lib/pipe_checker.go +++ b/packer_test/common/check/pipe_checker.go @@ -1,4 +1,4 @@ -package lib +package check import ( "fmt" diff --git a/packer_test/lib/commands.go b/packer_test/common/commands.go similarity index 92% rename from packer_test/lib/commands.go rename to packer_test/common/commands.go index 6e90bd625..4e2ebd285 100644 --- a/packer_test/lib/commands.go +++ b/packer_test/common/commands.go @@ -1,4 +1,4 @@ -package lib +package common import ( "fmt" @@ -6,6 +6,8 @@ import ( "os/exec" "strings" "testing" + + "github.com/hashicorp/packer/packer_test/common/check" ) type packerCommand struct { @@ -139,7 +141,7 @@ func (pc *packerCommand) Run() (string, string, error) { pc.err = cmd.Run() // Check that the command didn't panic, and if it did, we can immediately error - panicErr := PanicCheck{}.Check(pc.stdout.String(), pc.stderr.String(), pc.err) + panicErr := check.PanicCheck{}.Check(pc.stdout.String(), pc.stderr.String(), pc.err) if panicErr != nil { pc.t.Fatalf("Packer panicked during execution: %s", panicErr) } @@ -147,16 +149,16 @@ func (pc *packerCommand) Run() (string, string, error) { return pc.stdout.String(), pc.stderr.String(), pc.err } -func (pc *packerCommand) Assert(checks ...Checker) { +func (pc *packerCommand) Assert(checks ...check.Checker) { attempt := 0 for pc.runs > 0 { attempt++ stdout, stderr, err := pc.Run() - for _, check := range checks { - checkErr := check.Check(stdout, stderr, err) + for _, checker := range checks { + checkErr := checker.Check(stdout, stderr, err) if checkErr != nil { - checkerName := InferName(check) + checkerName := check.InferName(checker) pc.t.Errorf("check %q failed: %s", checkerName, checkErr) } } diff --git a/packer_test/lib/fs.go b/packer_test/common/fs.go similarity index 99% rename from packer_test/lib/fs.go rename to packer_test/common/fs.go index ce497601d..3fa3affe9 100644 --- a/packer_test/lib/fs.go +++ b/packer_test/common/fs.go @@ -1,4 +1,4 @@ -package lib +package common import ( "crypto/sha256" diff --git a/packer_test/lib/plugin.go b/packer_test/common/plugin.go similarity index 98% rename from packer_test/lib/plugin.go rename to packer_test/common/plugin.go index 2d3c379c6..59a07a247 100644 --- a/packer_test/lib/plugin.go +++ b/packer_test/common/plugin.go @@ -1,4 +1,4 @@ -package lib +package common import ( "fmt" @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/go-version" "github.com/hashicorp/packer-plugin-sdk/plugin" + "github.com/hashicorp/packer/packer_test/common/check" ) // LDFlags compiles the ldflags for the plugin to compile based on the information provided. @@ -156,7 +157,7 @@ func (ts *PackerTestSuite) MakePluginDir(pluginVersions ...string) (pluginTempDi for _, pluginVersion := range pluginVersions { path := ts.GetPluginPath(t, pluginVersion) cmd := ts.PackerCommand().SetArgs("plugins", "install", "--path", path, "github.com/hashicorp/tester").AddEnv("PACKER_PLUGIN_PATH", pluginTempDir) - cmd.Assert(MustSucceed()) + cmd.Assert(check.MustSucceed()) out, stderr, cmdErr := cmd.Run() if cmdErr != nil { err = fmt.Errorf("failed to install tester plugin version %q: %s\nCommand stdout: %s\nCommand stderr: %s", pluginVersion, err, out, stderr) diff --git a/packer_test/lib/plugin_tester/LICENSE b/packer_test/common/plugin_tester/LICENSE similarity index 100% rename from packer_test/lib/plugin_tester/LICENSE rename to packer_test/common/plugin_tester/LICENSE diff --git a/packer_test/lib/plugin_tester/README.md b/packer_test/common/plugin_tester/README.md similarity index 100% rename from packer_test/lib/plugin_tester/README.md rename to packer_test/common/plugin_tester/README.md diff --git a/packer_test/lib/plugin_tester/builder/dynamic/artifact.go b/packer_test/common/plugin_tester/builder/dynamic/artifact.go similarity index 100% rename from packer_test/lib/plugin_tester/builder/dynamic/artifact.go rename to packer_test/common/plugin_tester/builder/dynamic/artifact.go diff --git a/packer_test/lib/plugin_tester/builder/dynamic/builder.go b/packer_test/common/plugin_tester/builder/dynamic/builder.go similarity index 100% rename from packer_test/lib/plugin_tester/builder/dynamic/builder.go rename to packer_test/common/plugin_tester/builder/dynamic/builder.go diff --git a/packer_test/lib/plugin_tester/builder/dynamic/builder.hcl2spec.go b/packer_test/common/plugin_tester/builder/dynamic/builder.hcl2spec.go similarity index 100% rename from packer_test/lib/plugin_tester/builder/dynamic/builder.hcl2spec.go rename to packer_test/common/plugin_tester/builder/dynamic/builder.hcl2spec.go diff --git a/packer_test/lib/plugin_tester/builder/dynamic/builder_acc_test.go b/packer_test/common/plugin_tester/builder/dynamic/builder_acc_test.go similarity index 100% rename from packer_test/lib/plugin_tester/builder/dynamic/builder_acc_test.go rename to packer_test/common/plugin_tester/builder/dynamic/builder_acc_test.go diff --git a/packer_test/lib/plugin_tester/builder/dynamic/step_say_config.go b/packer_test/common/plugin_tester/builder/dynamic/step_say_config.go similarity index 100% rename from packer_test/lib/plugin_tester/builder/dynamic/step_say_config.go rename to packer_test/common/plugin_tester/builder/dynamic/step_say_config.go diff --git a/packer_test/lib/plugin_tester/builder/dynamic/test-fixtures/template.pkr.hcl b/packer_test/common/plugin_tester/builder/dynamic/test-fixtures/template.pkr.hcl similarity index 100% rename from packer_test/lib/plugin_tester/builder/dynamic/test-fixtures/template.pkr.hcl rename to packer_test/common/plugin_tester/builder/dynamic/test-fixtures/template.pkr.hcl diff --git a/packer_test/lib/plugin_tester/datasource/dynamic/data.go b/packer_test/common/plugin_tester/datasource/dynamic/data.go similarity index 100% rename from packer_test/lib/plugin_tester/datasource/dynamic/data.go rename to packer_test/common/plugin_tester/datasource/dynamic/data.go diff --git a/packer_test/lib/plugin_tester/datasource/dynamic/data.hcl2spec.go b/packer_test/common/plugin_tester/datasource/dynamic/data.hcl2spec.go similarity index 100% rename from packer_test/lib/plugin_tester/datasource/dynamic/data.hcl2spec.go rename to packer_test/common/plugin_tester/datasource/dynamic/data.hcl2spec.go diff --git a/packer_test/lib/plugin_tester/datasource/dynamic/data_acc_test.go b/packer_test/common/plugin_tester/datasource/dynamic/data_acc_test.go similarity index 100% rename from packer_test/lib/plugin_tester/datasource/dynamic/data_acc_test.go rename to packer_test/common/plugin_tester/datasource/dynamic/data_acc_test.go diff --git a/packer_test/lib/plugin_tester/datasource/dynamic/test-fixtures/template.pkr.hcl b/packer_test/common/plugin_tester/datasource/dynamic/test-fixtures/template.pkr.hcl similarity index 100% rename from packer_test/lib/plugin_tester/datasource/dynamic/test-fixtures/template.pkr.hcl rename to packer_test/common/plugin_tester/datasource/dynamic/test-fixtures/template.pkr.hcl diff --git a/packer_test/lib/plugin_tester/datasource/parrot/data.go b/packer_test/common/plugin_tester/datasource/parrot/data.go similarity index 100% rename from packer_test/lib/plugin_tester/datasource/parrot/data.go rename to packer_test/common/plugin_tester/datasource/parrot/data.go diff --git a/packer_test/lib/plugin_tester/datasource/parrot/data.hcl2spec.go b/packer_test/common/plugin_tester/datasource/parrot/data.hcl2spec.go similarity index 100% rename from packer_test/lib/plugin_tester/datasource/parrot/data.hcl2spec.go rename to packer_test/common/plugin_tester/datasource/parrot/data.hcl2spec.go diff --git a/packer_test/lib/plugin_tester/datasource/sleeper/data.go b/packer_test/common/plugin_tester/datasource/sleeper/data.go similarity index 100% rename from packer_test/lib/plugin_tester/datasource/sleeper/data.go rename to packer_test/common/plugin_tester/datasource/sleeper/data.go diff --git a/packer_test/lib/plugin_tester/datasource/sleeper/data.hcl2spec.go b/packer_test/common/plugin_tester/datasource/sleeper/data.hcl2spec.go similarity index 100% rename from packer_test/lib/plugin_tester/datasource/sleeper/data.hcl2spec.go rename to packer_test/common/plugin_tester/datasource/sleeper/data.hcl2spec.go diff --git a/packer_test/lib/plugin_tester/docs/README.md b/packer_test/common/plugin_tester/docs/README.md similarity index 100% rename from packer_test/lib/plugin_tester/docs/README.md rename to packer_test/common/plugin_tester/docs/README.md diff --git a/packer_test/lib/plugin_tester/docs/builders/builder-name.mdx b/packer_test/common/plugin_tester/docs/builders/builder-name.mdx similarity index 100% rename from packer_test/lib/plugin_tester/docs/builders/builder-name.mdx rename to packer_test/common/plugin_tester/docs/builders/builder-name.mdx diff --git a/packer_test/lib/plugin_tester/docs/datasources/datasource-name.mdx b/packer_test/common/plugin_tester/docs/datasources/datasource-name.mdx similarity index 100% rename from packer_test/lib/plugin_tester/docs/datasources/datasource-name.mdx rename to packer_test/common/plugin_tester/docs/datasources/datasource-name.mdx diff --git a/packer_test/lib/plugin_tester/docs/post-processors/postprocessor-name.mdx b/packer_test/common/plugin_tester/docs/post-processors/postprocessor-name.mdx similarity index 100% rename from packer_test/lib/plugin_tester/docs/post-processors/postprocessor-name.mdx rename to packer_test/common/plugin_tester/docs/post-processors/postprocessor-name.mdx diff --git a/packer_test/lib/plugin_tester/docs/provisioners/provisioner-name.mdx b/packer_test/common/plugin_tester/docs/provisioners/provisioner-name.mdx similarity index 100% rename from packer_test/lib/plugin_tester/docs/provisioners/provisioner-name.mdx rename to packer_test/common/plugin_tester/docs/provisioners/provisioner-name.mdx diff --git a/packer_test/lib/plugin_tester/example/README.md b/packer_test/common/plugin_tester/example/README.md similarity index 100% rename from packer_test/lib/plugin_tester/example/README.md rename to packer_test/common/plugin_tester/example/README.md diff --git a/packer_test/lib/plugin_tester/example/build.pkr.hcl b/packer_test/common/plugin_tester/example/build.pkr.hcl similarity index 100% rename from packer_test/lib/plugin_tester/example/build.pkr.hcl rename to packer_test/common/plugin_tester/example/build.pkr.hcl diff --git a/packer_test/lib/plugin_tester/example/data.pkr.hcl b/packer_test/common/plugin_tester/example/data.pkr.hcl similarity index 100% rename from packer_test/lib/plugin_tester/example/data.pkr.hcl rename to packer_test/common/plugin_tester/example/data.pkr.hcl diff --git a/packer_test/lib/plugin_tester/example/variables.pkr.hcl b/packer_test/common/plugin_tester/example/variables.pkr.hcl similarity index 100% rename from packer_test/lib/plugin_tester/example/variables.pkr.hcl rename to packer_test/common/plugin_tester/example/variables.pkr.hcl diff --git a/packer_test/lib/plugin_tester/go.mod b/packer_test/common/plugin_tester/go.mod similarity index 100% rename from packer_test/lib/plugin_tester/go.mod rename to packer_test/common/plugin_tester/go.mod diff --git a/packer_test/lib/plugin_tester/go.sum b/packer_test/common/plugin_tester/go.sum similarity index 100% rename from packer_test/lib/plugin_tester/go.sum rename to packer_test/common/plugin_tester/go.sum diff --git a/packer_test/lib/plugin_tester/main.go b/packer_test/common/plugin_tester/main.go similarity index 100% rename from packer_test/lib/plugin_tester/main.go rename to packer_test/common/plugin_tester/main.go diff --git a/packer_test/lib/plugin_tester/post-processor/dynamic/post-processor.go b/packer_test/common/plugin_tester/post-processor/dynamic/post-processor.go similarity index 100% rename from packer_test/lib/plugin_tester/post-processor/dynamic/post-processor.go rename to packer_test/common/plugin_tester/post-processor/dynamic/post-processor.go diff --git a/packer_test/lib/plugin_tester/post-processor/dynamic/post-processor.hcl2spec.go b/packer_test/common/plugin_tester/post-processor/dynamic/post-processor.hcl2spec.go similarity index 100% rename from packer_test/lib/plugin_tester/post-processor/dynamic/post-processor.hcl2spec.go rename to packer_test/common/plugin_tester/post-processor/dynamic/post-processor.hcl2spec.go diff --git a/packer_test/lib/plugin_tester/post-processor/dynamic/post-processor_acc_test.go b/packer_test/common/plugin_tester/post-processor/dynamic/post-processor_acc_test.go similarity index 100% rename from packer_test/lib/plugin_tester/post-processor/dynamic/post-processor_acc_test.go rename to packer_test/common/plugin_tester/post-processor/dynamic/post-processor_acc_test.go diff --git a/packer_test/lib/plugin_tester/post-processor/dynamic/test-fixtures/template.pkr.hcl b/packer_test/common/plugin_tester/post-processor/dynamic/test-fixtures/template.pkr.hcl similarity index 100% rename from packer_test/lib/plugin_tester/post-processor/dynamic/test-fixtures/template.pkr.hcl rename to packer_test/common/plugin_tester/post-processor/dynamic/test-fixtures/template.pkr.hcl diff --git a/packer_test/lib/plugin_tester/provisioner/dynamic/provisioner.go b/packer_test/common/plugin_tester/provisioner/dynamic/provisioner.go similarity index 100% rename from packer_test/lib/plugin_tester/provisioner/dynamic/provisioner.go rename to packer_test/common/plugin_tester/provisioner/dynamic/provisioner.go diff --git a/packer_test/lib/plugin_tester/provisioner/dynamic/provisioner.hcl2spec.go b/packer_test/common/plugin_tester/provisioner/dynamic/provisioner.hcl2spec.go similarity index 100% rename from packer_test/lib/plugin_tester/provisioner/dynamic/provisioner.hcl2spec.go rename to packer_test/common/plugin_tester/provisioner/dynamic/provisioner.hcl2spec.go diff --git a/packer_test/lib/plugin_tester/provisioner/dynamic/provisioner_acc_test.go b/packer_test/common/plugin_tester/provisioner/dynamic/provisioner_acc_test.go similarity index 100% rename from packer_test/lib/plugin_tester/provisioner/dynamic/provisioner_acc_test.go rename to packer_test/common/plugin_tester/provisioner/dynamic/provisioner_acc_test.go diff --git a/packer_test/lib/plugin_tester/provisioner/dynamic/test-fixtures/template.pkr.hcl b/packer_test/common/plugin_tester/provisioner/dynamic/test-fixtures/template.pkr.hcl similarity index 100% rename from packer_test/lib/plugin_tester/provisioner/dynamic/test-fixtures/template.pkr.hcl rename to packer_test/common/plugin_tester/provisioner/dynamic/test-fixtures/template.pkr.hcl diff --git a/packer_test/lib/plugin_tester/version/version.go b/packer_test/common/plugin_tester/version/version.go similarity index 100% rename from packer_test/lib/plugin_tester/version/version.go rename to packer_test/common/plugin_tester/version/version.go diff --git a/packer_test/lib/suite.go b/packer_test/common/suite.go similarity index 99% rename from packer_test/lib/suite.go rename to packer_test/common/suite.go index 4d22ca9cb..5c7477ce3 100644 --- a/packer_test/lib/suite.go +++ b/packer_test/common/suite.go @@ -1,4 +1,4 @@ -package lib +package common import ( "fmt" diff --git a/packer_test/core_tests/local_eval_test.go b/packer_test/core_tests/local_eval_test.go index 4a74785c3..245fe0577 100644 --- a/packer_test/core_tests/local_eval_test.go +++ b/packer_test/core_tests/local_eval_test.go @@ -3,7 +3,7 @@ package core_test import ( "fmt" - "github.com/hashicorp/packer/packer_test/lib" + "github.com/hashicorp/packer/packer_test/common/check" ) func (ts *PackerCoreTestSuite) TestEvalLocalsOrder() { @@ -16,8 +16,8 @@ func (ts *PackerCoreTestSuite) TestEvalLocalsOrder() { Runs(10). Stdin("local.test_local\n"). SetArgs("console", "./templates/locals_no_order.pkr.hcl"). - Assert(lib.MustSucceed(), - lib.GrepInverted("\\[\\]", lib.GrepStdout)) + Assert(check.MustSucceed(), + check.GrepInverted("\\[\\]", check.GrepStdout)) } func (ts *PackerCoreTestSuite) TestLocalDuplicates() { @@ -28,9 +28,9 @@ func (ts *PackerCoreTestSuite) TestLocalDuplicates() { ts.Run(fmt.Sprintf("duplicate local detection with %s command - expect error", cmd), func() { ts.PackerCommand().UsePluginDir(pluginDir). SetArgs(cmd, "./templates/locals_duplicate.pkr.hcl"). - Assert(lib.MustFail(), - lib.Grep("Duplicate local definition"), - lib.Grep("Local variable \"test\" is defined twice")) + Assert(check.MustFail(), + check.Grep("Duplicate local definition"), + check.Grep("Local variable \"test\" is defined twice")) }) } } diff --git a/packer_test/core_tests/suite_test.go b/packer_test/core_tests/suite_test.go index 220dfece8..9e067e9ae 100644 --- a/packer_test/core_tests/suite_test.go +++ b/packer_test/core_tests/suite_test.go @@ -3,16 +3,16 @@ package core_test import ( "testing" - "github.com/hashicorp/packer/packer_test/lib" + "github.com/hashicorp/packer/packer_test/common" "github.com/stretchr/testify/suite" ) type PackerCoreTestSuite struct { - *lib.PackerTestSuite + *common.PackerTestSuite } func Test_PackerCoreSuite(t *testing.T) { - baseSuite, cleanup := lib.InitBaseSuite(t) + baseSuite, cleanup := common.InitBaseSuite(t) defer cleanup() ts := &PackerCoreTestSuite{ diff --git a/packer_test/plugin_tests/init_test.go b/packer_test/plugin_tests/init_test.go index b7f53e304..617449f0c 100644 --- a/packer_test/plugin_tests/init_test.go +++ b/packer_test/plugin_tests/init_test.go @@ -1,6 +1,6 @@ package plugin_tests -import "github.com/hashicorp/packer/packer_test/lib" +import "github.com/hashicorp/packer/packer_test/common/check" func (ts *PackerPluginTestSuite) TestPackerInitForce() { ts.SkipNoAcc() @@ -11,13 +11,13 @@ func (ts *PackerPluginTestSuite) TestPackerInitForce() { ts.Run("installs any missing plugins", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("init", "--force", "./templates/init/hashicups.pkr.hcl"). - Assert(lib.MustSucceed(), lib.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", lib.GrepStdout)) + Assert(check.MustSucceed(), check.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", check.GrepStdout)) }) ts.Run("reinstalls plugins matching version constraints", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("init", "--force", "./templates/init/hashicups.pkr.hcl"). - Assert(lib.MustSucceed(), lib.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", lib.GrepStdout)) + Assert(check.MustSucceed(), check.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", check.GrepStdout)) }) } @@ -29,7 +29,7 @@ func (ts *PackerPluginTestSuite) TestPackerInitUpgrade() { cmd := ts.PackerCommand().UsePluginDir(pluginPath) cmd.SetArgs("plugins", "install", "github.com/hashicorp/hashicups", "1.0.1") - cmd.Assert(lib.MustSucceed(), lib.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.1", lib.GrepStdout)) + cmd.Assert(check.MustSucceed(), check.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.1", check.GrepStdout)) _, _, err := cmd.Run() if err != nil { @@ -39,7 +39,7 @@ func (ts *PackerPluginTestSuite) TestPackerInitUpgrade() { ts.Run("upgrades a plugin to the latest matching version constraints", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("init", "--upgrade", "./templates/init/hashicups.pkr.hcl"). - Assert(lib.MustSucceed(), lib.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", lib.GrepStdout)) + Assert(check.MustSucceed(), check.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", check.GrepStdout)) }) } @@ -50,20 +50,20 @@ func (ts *PackerPluginTestSuite) TestPackerInitWithNonGithubSource() { ts.Run("try installing from a non-github source, should fail", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("init", "./templates/init/non_gh.pkr.hcl"). - Assert(lib.MustFail(), lib.Grep(`doesn't appear to be a valid "github.com" source address`, lib.GrepStdout)) + Assert(check.MustFail(), check.Grep(`doesn't appear to be a valid "github.com" source address`, check.GrepStdout)) }) ts.Run("manually install plugin to the expected source", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugins", "install", "--path", ts.GetPluginPath(ts.T(), "1.0.10"), "hubgit.com/hashicorp/tester"). - Assert(lib.MustSucceed(), lib.Grep("packer-plugin-tester_v1.0.10", lib.GrepStdout)) + Assert(check.MustSucceed(), check.Grep("packer-plugin-tester_v1.0.10", check.GrepStdout)) }) ts.Run("re-run packer init on same template, should succeed silently", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("init", "./templates/init/non_gh.pkr.hcl"). - Assert(lib.MustSucceed(), - lib.MkPipeCheck("no output in stdout").SetTester(lib.ExpectEmptyInput()).SetStream(lib.OnlyStdout)) + Assert(check.MustSucceed(), + check.MkPipeCheck("no output in stdout").SetTester(check.ExpectEmptyInput()).SetStream(check.OnlyStdout)) }) } @@ -76,7 +76,7 @@ func (ts *PackerPluginTestSuite) TestPackerInitWithMixedVersions() { ts.Run("skips the plugin installation with mixed versions before exiting with an error", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("init", "./templates/init/mixed_versions.pkr.hcl"). - Assert(lib.MustFail(), - lib.Grep("binary reported a pre-release version of 10.7.3-dev", lib.GrepStdout)) + Assert(check.MustFail(), + check.Grep("binary reported a pre-release version of 10.7.3-dev", check.GrepStdout)) }) } diff --git a/packer_test/plugin_tests/install_test.go b/packer_test/plugin_tests/install_test.go index 80576b327..5bc8306e5 100644 --- a/packer_test/plugin_tests/install_test.go +++ b/packer_test/plugin_tests/install_test.go @@ -1,6 +1,6 @@ package plugin_tests -import "github.com/hashicorp/packer/packer_test/lib" +import "github.com/hashicorp/packer/packer_test/common/check" func (ts *PackerPluginTestSuite) TestInstallPluginWithMetadata() { tempPluginDir, cleanup := ts.MakePluginDir() @@ -9,25 +9,25 @@ func (ts *PackerPluginTestSuite) TestInstallPluginWithMetadata() { ts.Run("install plugin with metadata in version", func() { ts.PackerCommand().UsePluginDir(tempPluginDir). SetArgs("plugins", "install", "--path", ts.GetPluginPath(ts.T(), "1.0.0+metadata"), "github.com/hashicorp/tester"). - Assert(lib.MustSucceed(), lib.Grep("Successfully installed plugin", lib.GrepStdout)) + Assert(check.MustSucceed(), check.Grep("Successfully installed plugin", check.GrepStdout)) }) ts.Run("metadata plugin installed must not have metadata in its path", func() { ts.PackerCommand().UsePluginDir(tempPluginDir). SetArgs("plugins", "installed"). - Assert(lib.MustSucceed(), lib.Grep("packer-plugin-tester_v1.0.0[^+]", lib.GrepStdout)) + Assert(check.MustSucceed(), check.Grep("packer-plugin-tester_v1.0.0[^+]", check.GrepStdout)) }) ts.Run("plugin with metadata should work with validate", func() { ts.PackerCommand().UsePluginDir(tempPluginDir). SetArgs("validate", "./templates/simple.pkr.hcl"). - Assert(lib.MustSucceed(), lib.Grep("packer-plugin-tester_v1.0.0[^+][^\\n]+plugin:", lib.GrepStderr)) + Assert(check.MustSucceed(), check.Grep("packer-plugin-tester_v1.0.0[^+][^\\n]+plugin:", check.GrepStderr)) }) ts.Run("plugin with metadata should work with build", func() { ts.PackerCommand().UsePluginDir(tempPluginDir). SetArgs("build", "./templates/simple.pkr.hcl"). - Assert(lib.MustSucceed(), lib.Grep("packer-plugin-tester_v1.0.0[^+][^\\n]+plugin:", lib.GrepStderr)) + Assert(check.MustSucceed(), check.Grep("packer-plugin-tester_v1.0.0[^+][^\\n]+plugin:", check.GrepStderr)) }) } @@ -38,22 +38,22 @@ func (ts *PackerPluginTestSuite) TestInstallPluginWithPath() { ts.Run("install plugin with pre-release only", func() { ts.PackerCommand().UsePluginDir(tempPluginDir). SetArgs("plugins", "install", "--path", ts.GetPluginPath(ts.T(), "1.0.0-dev"), "github.com/hashicorp/tester"). - Assert(lib.MustSucceed(), lib.Grep("Successfully installed plugin", lib.GrepStdout)) + Assert(check.MustSucceed(), check.Grep("Successfully installed plugin", check.GrepStdout)) }) ts.Run("install same plugin with pre-release + metadata", func() { ts.PackerCommand().UsePluginDir(tempPluginDir). SetArgs("plugins", "install", "--path", ts.GetPluginPath(ts.T(), "1.0.0-dev+metadata"), "github.com/hashicorp/tester"). - Assert(lib.MustSucceed(), lib.Grep("Successfully installed plugin", lib.GrepStdout)) + Assert(check.MustSucceed(), check.Grep("Successfully installed plugin", check.GrepStdout)) }) ts.Run("list plugins, should only report one plugin", func() { ts.PackerCommand().UsePluginDir(tempPluginDir). SetArgs("plugins", "installed"). - Assert(lib.MustSucceed(), - lib.Grep("plugin-tester_v1.0.0-dev[^+]", lib.GrepStdout), - lib.GrepInverted("plugin-tester_v1.0.0-dev\\+", lib.GrepStdout), - lib.LineCountCheck(1)) + Assert(check.MustSucceed(), + check.Grep("plugin-tester_v1.0.0-dev[^+]", check.GrepStdout), + check.GrepInverted("plugin-tester_v1.0.0-dev\\+", check.GrepStdout), + check.LineCountCheck(1)) }) } @@ -66,7 +66,7 @@ func (ts *PackerPluginTestSuite) TestInstallPluginPrerelease() { ts.Run("try install plugin with alpha1 prerelease - should fail", func() { ts.PackerCommand().UsePluginDir(pluginDir). SetArgs("plugins", "install", "--path", pluginPath, "github.com/hashicorp/tester"). - Assert(lib.MustFail(), lib.Grep("Packer can only install plugin releases with this command", lib.GrepStdout)) + Assert(check.MustFail(), check.Grep("Packer can only install plugin releases with this command", check.GrepStdout)) }) } @@ -79,7 +79,7 @@ func (ts *PackerPluginTestSuite) TestRemoteInstallWithPluginsInstall() { ts.Run("install latest version of a remote plugin with packer plugins install", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugins", "install", "github.com/hashicorp/hashicups"). - Assert(lib.MustSucceed()) + Assert(check.MustSucceed()) }) } @@ -92,15 +92,15 @@ func (ts *PackerPluginTestSuite) TestRemoteInstallOfPreReleasePlugin() { ts.Run("try to init with a pre-release constraint - should fail", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("init", "templates/pre-release_constraint.pkr.hcl"). - Assert(lib.MustFail(), - lib.Grep("Invalid version constraint", lib.GrepStdout), - lib.Grep("Unsupported prerelease for constraint", lib.GrepStdout)) + Assert(check.MustFail(), + check.Grep("Invalid version constraint", check.GrepStdout), + check.Grep("Unsupported prerelease for constraint", check.GrepStdout)) }) ts.Run("try to plugins install with a pre-release version - should fail", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugin", "install", "github.com/hashicorp/hashicups", "1.0.2-dev"). - Assert(lib.MustFail(), - lib.Grep("Unsupported prerelease for constraint", lib.GrepStdout)) + Assert(check.MustFail(), + check.Grep("Unsupported prerelease for constraint", check.GrepStdout)) }) } diff --git a/packer_test/plugin_tests/loading_test.go b/packer_test/plugin_tests/loading_test.go index 2281d66dc..fa13ac027 100644 --- a/packer_test/plugin_tests/loading_test.go +++ b/packer_test/plugin_tests/loading_test.go @@ -6,7 +6,8 @@ import ( "os" "path/filepath" - "github.com/hashicorp/packer/packer_test/lib" + "github.com/hashicorp/packer/packer_test/common" + "github.com/hashicorp/packer/packer_test/common/check" ) func (ts *PackerPluginTestSuite) TestLoadingOrder() { @@ -41,7 +42,7 @@ func (ts *PackerPluginTestSuite) TestLoadingOrder() { ts.PackerCommand(). SetArgs(command, tt.templatePath). UsePluginDir(pluginDir). - Assert(lib.MustSucceed(), lib.Grep(tt.grepStr)) + Assert(check.MustSucceed(), check.Grep(tt.grepStr)) }) } } @@ -53,45 +54,45 @@ func (ts *PackerPluginTestSuite) TestLoadWithLegacyPluginName() { plugin := ts.GetPluginPath(ts.T(), "1.0.10") - lib.CopyFile(ts.T(), filepath.Join(pluginDir, "packer-plugin-tester"), plugin) + common.CopyFile(ts.T(), filepath.Join(pluginDir, "packer-plugin-tester"), plugin) ts.Run("only legacy plugins installed: expect build to fail", func() { ts.Run("with required_plugins - expect prompt for packer init", func() { ts.PackerCommand().UsePluginDir(pluginDir). SetArgs("build", "templates/simple.pkr.hcl"). - Assert(lib.MustFail(), - lib.Grep("Did you run packer init for this project", lib.GrepStdout), - lib.Grep("following plugins are required", lib.GrepStdout)) + Assert(check.MustFail(), + check.Grep("Did you run packer init for this project", check.GrepStdout), + check.Grep("following plugins are required", check.GrepStdout)) }) ts.Run("JSON template, without required_plugins: should say the component is unknown", func() { ts.PackerCommand().UsePluginDir(pluginDir). SetArgs("build", "templates/simple.json"). - Assert(lib.MustFail(), - lib.Grep("The builder tester-dynamic is unknown by Packer", lib.GrepStdout)) + Assert(check.MustFail(), + check.Grep("The builder tester-dynamic is unknown by Packer", check.GrepStdout)) }) }) pluginDir, cleanup = ts.MakePluginDir("1.0.0") defer cleanup() - lib.CopyFile(ts.T(), filepath.Join(pluginDir, "packer-plugin-tester"), plugin) + common.CopyFile(ts.T(), filepath.Join(pluginDir, "packer-plugin-tester"), plugin) ts.Run("multiple plugins installed: one with no version in path, one with qualified name. Should pick-up the qualified one only.", func() { ts.PackerCommand().UsePluginDir(pluginDir). SetArgs("build", "templates/simple.pkr.hcl"). - Assert(lib.MustSucceed(), lib.Grep("packer-plugin-tester_v1\\.0\\.0[^\\n]+ plugin:", lib.GrepStderr)) + Assert(check.MustSucceed(), check.Grep("packer-plugin-tester_v1\\.0\\.0[^\\n]+ plugin:", check.GrepStderr)) }) - wd, cleanup := lib.TempWorkdir(ts.T(), "./templates/simple.pkr.hcl") + wd, cleanup := common.TempWorkdir(ts.T(), "./templates/simple.pkr.hcl") defer cleanup() - lib.CopyFile(ts.T(), filepath.Join(wd, "packer-plugin-tester"), plugin) + common.CopyFile(ts.T(), filepath.Join(wd, "packer-plugin-tester"), plugin) ts.Run("multiple plugins installed: 1.0.0 in plugin dir with sum, one in workdir (no version). Should load 1.0.0", func() { ts.PackerCommand().UsePluginDir(pluginDir).SetWD(wd). SetArgs("build", "simple.pkr.hcl"). - Assert(lib.MustSucceed(), lib.Grep("packer-plugin-tester_v1\\.0\\.0[^\\n]+ plugin:", lib.GrepStderr)) + Assert(check.MustSucceed(), check.Grep("packer-plugin-tester_v1\\.0\\.0[^\\n]+ plugin:", check.GrepStderr)) }) } @@ -102,35 +103,35 @@ func (ts *PackerPluginTestSuite) TestLoadWithSHAMismatches() { pluginDir, cleanup := ts.MakePluginDir("1.0.9") defer cleanup() - pluginDestName := lib.ExpectedInstalledName("1.0.10") + pluginDestName := common.ExpectedInstalledName("1.0.10") - lib.CopyFile(ts.T(), filepath.Join(pluginDir, "github.com", "hashicorp", "tester", pluginDestName), plugin) + common.CopyFile(ts.T(), filepath.Join(pluginDir, "github.com", "hashicorp", "tester", pluginDestName), plugin) ts.PackerCommand().UsePluginDir(pluginDir). SetArgs("plugins", "installed"). - Assert(lib.MustSucceed(), - lib.Grep("packer-plugin-tester_v1\\.0\\.9[^\\n]+", lib.GrepStdout), - lib.GrepInverted("packer-plugin-tester_v1.0.10", lib.GrepStdout), - lib.Grep("v1.0.10[^\\n]+ignoring possibly unsafe binary", lib.GrepStderr)) + Assert(check.MustSucceed(), + check.Grep("packer-plugin-tester_v1\\.0\\.9[^\\n]+", check.GrepStdout), + check.GrepInverted("packer-plugin-tester_v1.0.10", check.GrepStdout), + check.Grep("v1.0.10[^\\n]+ignoring possibly unsafe binary", check.GrepStderr)) }) ts.Run("move plugin with right name, invalid SHA256SUM, should reject", func() { pluginDir, cleanup := ts.MakePluginDir("1.0.9") defer cleanup() - pluginDestName := lib.ExpectedInstalledName("1.0.10") - lib.CopyFile(ts.T(), filepath.Join(pluginDir, "github.com", "hashicorp", "tester", pluginDestName), plugin) - lib.WriteFile(ts.T(), + pluginDestName := common.ExpectedInstalledName("1.0.10") + common.CopyFile(ts.T(), filepath.Join(pluginDir, "github.com", "hashicorp", "tester", pluginDestName), plugin) + common.WriteFile(ts.T(), filepath.Join(pluginDir, "github.com", "hashicorp", "tester", fmt.Sprintf("%s_SHA256SUM", pluginDestName)), fmt.Sprintf("%x", sha256.New().Sum([]byte("Not the plugin's contents for sure.")))) ts.PackerCommand().UsePluginDir(pluginDir). SetArgs("plugins", "installed"). - Assert(lib.MustSucceed(), - lib.Grep("packer-plugin-tester_v1\\.0\\.9[^\\n]+", lib.GrepStdout), - lib.GrepInverted("packer-plugin-tester_v1.0.10", lib.GrepStdout), - lib.Grep("v1.0.10[^\\n]+ignoring possibly unsafe binary", lib.GrepStderr), - lib.Grep(`Checksums \(\*sha256\.digest\) did not match.`, lib.GrepStderr)) + Assert(check.MustSucceed(), + check.Grep("packer-plugin-tester_v1\\.0\\.9[^\\n]+", check.GrepStdout), + check.GrepInverted("packer-plugin-tester_v1.0.10", check.GrepStdout), + check.Grep("v1.0.10[^\\n]+ignoring possibly unsafe binary", check.GrepStderr), + check.Grep(`Checksums \(\*sha256\.digest\) did not match.`, check.GrepStderr)) }) } @@ -145,13 +146,13 @@ func (ts *PackerPluginTestSuite) TestPluginPathEnvvarWithMultiplePaths() { ts.Run("load plugin with two dirs - not supported anymore, should error", func() { ts.PackerCommand().UsePluginDir(pluginDirVal). SetArgs("plugins", "installed"). - Assert(lib.MustFail(), - lib.Grep("Multiple paths are no longer supported for PACKER_PLUGIN_PATH"), - lib.MkPipeCheck("All envvars are suggested", - lib.PipeGrep(`\* PACKER_PLUGIN_PATH=`), - lib.LineCount()). - SetStream(lib.OnlyStderr). - SetTester(lib.IntCompare(lib.Eq, 2))) + Assert(check.MustFail(), + check.Grep("Multiple paths are no longer supported for PACKER_PLUGIN_PATH"), + check.MkPipeCheck("All envvars are suggested", + check.PipeGrep(`\* PACKER_PLUGIN_PATH=`), + check.LineCount()). + SetStream(check.OnlyStderr). + SetTester(check.IntCompare(check.Eq, 2))) }) } @@ -159,7 +160,7 @@ func (ts *PackerPluginTestSuite) TestInstallNonCanonicalPluginVersion() { pluginPath, cleanup := ts.MakePluginDir() defer cleanup() - lib.ManualPluginInstall(ts.T(), + common.ManualPluginInstall(ts.T(), filepath.Join(pluginPath, "github.com", "hashicorp", "tester"), ts.GetPluginPath(ts.T(), "1.0.10"), "001.00.010") @@ -167,9 +168,9 @@ func (ts *PackerPluginTestSuite) TestInstallNonCanonicalPluginVersion() { ts.Run("try listing plugins with non-canonical version installed - report none", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugins", "installed"). - Assert(lib.MustSucceed(), - lib.Grep(`version .* in path is non canonical`, lib.GrepStderr), - lib.MkPipeCheck("no output in stdout").SetTester(lib.ExpectEmptyInput()).SetStream(lib.OnlyStdout)) + Assert(check.MustSucceed(), + check.Grep(`version .* in path is non canonical`, check.GrepStderr), + check.MkPipeCheck("no output in stdout").SetTester(check.ExpectEmptyInput()).SetStream(check.OnlyStdout)) }) } @@ -177,7 +178,7 @@ func (ts *PackerPluginTestSuite) TestLoadPluginWithMetadataInName() { pluginPath, cleanup := ts.MakePluginDir() defer cleanup() - lib.ManualPluginInstall(ts.T(), + common.ManualPluginInstall(ts.T(), filepath.Join(pluginPath, "github.com", "hashicorp", "tester"), ts.GetPluginPath(ts.T(), "1.0.10+metadata"), "1.0.10+metadata") @@ -185,9 +186,9 @@ func (ts *PackerPluginTestSuite) TestLoadPluginWithMetadataInName() { ts.Run("try listing plugins with metadata in name - report none", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugins", "installed"). - Assert(lib.MustSucceed(), - lib.Grep("found version .* with metadata in the name", lib.GrepStderr), - lib.MkPipeCheck("no output in stdout").SetTester(lib.ExpectEmptyInput()).SetStream(lib.OnlyStdout)) + Assert(check.MustSucceed(), + check.Grep("found version .* with metadata in the name", check.GrepStderr), + check.MkPipeCheck("no output in stdout").SetTester(check.ExpectEmptyInput()).SetStream(check.OnlyStdout)) }) } @@ -199,15 +200,15 @@ func (ts *PackerPluginTestSuite) TestLoadWithOnlyReleaseFlag() { ts.Run(fmt.Sprintf("run %s without --ignore-prerelease flag - pick 1.0.1-dev by default", cmd), func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs(cmd, "./templates/simple.pkr.hcl"). - Assert(lib.MustSucceed(), - lib.Grep("packer-plugin-tester_v1.0.1-dev.*: plugin process exited", lib.GrepStderr)) + Assert(check.MustSucceed(), + check.Grep("packer-plugin-tester_v1.0.1-dev.*: plugin process exited", check.GrepStderr)) }) ts.Run(fmt.Sprintf("run %s with --ignore-prerelease flag - pick 1.0.0", cmd), func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs(cmd, "--ignore-prerelease-plugins", "./templates/simple.pkr.hcl"). - Assert(lib.MustSucceed(), - lib.Grep("packer-plugin-tester_v1.0.0.*: plugin process exited", lib.GrepStderr)) + Assert(check.MustSucceed(), + check.Grep("packer-plugin-tester_v1.0.0.*: plugin process exited", check.GrepStderr)) }) } } @@ -216,7 +217,7 @@ func (ts *PackerPluginTestSuite) TestWithLegacyConfigAndComponents() { pluginDir, cleanup := ts.MakePluginDir("1.0.0") defer cleanup() - workdir, cleanup := lib.TempWorkdir(ts.T(), "./sample_config.json", "./templates/simple.json", "./templates/simple.pkr.hcl") + workdir, cleanup := common.TempWorkdir(ts.T(), "./sample_config.json", "./templates/simple.json", "./templates/simple.pkr.hcl") defer cleanup() for _, cmd := range []string{"validate", "build"} { @@ -224,18 +225,18 @@ func (ts *PackerPluginTestSuite) TestWithLegacyConfigAndComponents() { ts.PackerCommand().UsePluginDir(pluginDir).SetWD(workdir). SetArgs(cmd, "simple.json"). AddEnv("PACKER_CONFIG", filepath.Join(workdir, "sample_config.json")). - Assert(lib.MustFail(), - lib.Grep("Your configuration file describes some legacy components", lib.GrepStderr), - lib.Grep("packer-provisioner-super-shell", lib.GrepStderr)) + Assert(check.MustFail(), + check.Grep("Your configuration file describes some legacy components", check.GrepStderr), + check.Grep("packer-provisioner-super-shell", check.GrepStderr)) }) ts.Run(fmt.Sprintf("%s simple HCL2 template with config.json and components defined", cmd), func() { ts.PackerCommand().UsePluginDir(pluginDir).SetWD(workdir). SetArgs(cmd, "simple.pkr.hcl"). AddEnv("PACKER_CONFIG", filepath.Join(workdir, "sample_config.json")). - Assert(lib.MustFail(), - lib.Grep("Your configuration file describes some legacy components", lib.GrepStderr), - lib.Grep("packer-provisioner-super-shell", lib.GrepStderr)) + Assert(check.MustFail(), + check.Grep("Your configuration file describes some legacy components", check.GrepStderr), + check.Grep("packer-provisioner-super-shell", check.GrepStderr)) }) } } diff --git a/packer_test/plugin_tests/plugins_remove_test.go b/packer_test/plugin_tests/plugins_remove_test.go index c5f859677..23e49151f 100644 --- a/packer_test/plugin_tests/plugins_remove_test.go +++ b/packer_test/plugin_tests/plugins_remove_test.go @@ -4,7 +4,7 @@ import ( "path/filepath" "strings" - "github.com/hashicorp/packer/packer_test/lib" + "github.com/hashicorp/packer/packer_test/common/check" ) func (ts *PackerPluginTestSuite) TestPluginsRemoveWithSourceAddress() { @@ -19,10 +19,10 @@ func (ts *PackerPluginTestSuite) TestPluginsRemoveWithSourceAddress() { ts.Run("plugins remove with source address removes all installed plugin versions", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugins", "remove", "github.com/hashicorp/tester"). - Assert(lib.MustSucceed(), - lib.Grep("packer-plugin-tester_v1.0.9", lib.GrepStdout), - lib.Grep("packer-plugin-tester_v1.0.10", lib.GrepStdout), - lib.Grep("packer-plugin-tester_v2.0.0", lib.GrepStdout), + Assert(check.MustSucceed(), + check.Grep("packer-plugin-tester_v1.0.9", check.GrepStdout), + check.Grep("packer-plugin-tester_v1.0.10", check.GrepStdout), + check.Grep("packer-plugin-tester_v2.0.0", check.GrepStdout), ) }) @@ -35,8 +35,8 @@ func (ts *PackerPluginTestSuite) TestPluginsRemoveWithSourceAddress() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugins", "remove", "github.com/hashicorp/testerONE"). Assert( - lib.MustFail(), - lib.Grep("No installed plugin found matching the plugin constraints github.com/hashicorp/testerONE"), + check.MustFail(), + check.Grep("No installed plugin found matching the plugin constraints github.com/hashicorp/testerONE"), ) }) @@ -44,8 +44,8 @@ func (ts *PackerPluginTestSuite) TestPluginsRemoveWithSourceAddress() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugins", "remove", "github.com/hashicorp/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/tester"). Assert( - lib.MustFail(), - lib.Grep("The source URL must have at most 16 components"), + check.MustFail(), + check.Grep("The source URL must have at most 16 components"), ) }) } @@ -62,17 +62,17 @@ func (ts *PackerPluginTestSuite) TestPluginsRemoveWithSourceAddressAndVersion() ts.Run("plugins remove with source address and version removes only the versioned plugin", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugins", "remove", "github.com/hashicorp/tester", ">= 2.0.0"). - Assert(lib.MustSucceed(), lib.Grep("packer-plugin-tester_v2.0.0", lib.GrepStdout)) + Assert(check.MustSucceed(), check.Grep("packer-plugin-tester_v2.0.0", check.GrepStdout)) }) ts.Run("plugins installed after single plugins remove outputs remaining installed plugins", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugins", "installed"). Assert( - lib.MustSucceed(), - lib.Grep("packer-plugin-tester_v1.0.9", lib.GrepStdout), - lib.Grep("packer-plugin-tester_v1.0.10", lib.GrepStdout), - lib.GrepInverted("packer-plugin-tester_v2.0.0", lib.GrepStdout), + check.MustSucceed(), + check.Grep("packer-plugin-tester_v1.0.9", check.GrepStdout), + check.Grep("packer-plugin-tester_v1.0.10", check.GrepStdout), + check.GrepInverted("packer-plugin-tester_v2.0.0", check.GrepStdout), ) }) @@ -96,18 +96,18 @@ func (ts *PackerPluginTestSuite) TestPluginsRemoveWithLocalPath() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugins", "remove", plugins[0]). Assert( - lib.MustSucceed(), - lib.Grep("packer-plugin-tester_v1.0.9", lib.GrepStdout), - lib.GrepInverted("packer-plugin-tester_v1.0.10", lib.GrepStdout), + check.MustSucceed(), + check.Grep("packer-plugin-tester_v1.0.9", check.GrepStdout), + check.GrepInverted("packer-plugin-tester_v1.0.10", check.GrepStdout), ) }) ts.Run("plugins installed after calling plugins remove outputs remaining installed plugins", func() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugins", "installed"). Assert( - lib.MustSucceed(), - lib.Grep("packer-plugin-tester_v1.0.10", lib.GrepStdout), - lib.GrepInverted("packer-plugin-tester_v1.0.9", lib.GrepStdout), + check.MustSucceed(), + check.Grep("packer-plugin-tester_v1.0.10", check.GrepStdout), + check.GrepInverted("packer-plugin-tester_v1.0.9", check.GrepStdout), ) }) @@ -120,8 +120,8 @@ func (ts *PackerPluginTestSuite) TestPluginsRemoveWithLocalPath() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugins", "remove", filepath.Base(plugins[0])). Assert( - lib.MustFail(), - lib.Grep("A source URL must at least contain a host and a path with 2 components", lib.GrepStdout), + check.MustFail(), + check.Grep("A source URL must at least contain a host and a path with 2 components", check.GrepStdout), ) }) @@ -129,8 +129,8 @@ func (ts *PackerPluginTestSuite) TestPluginsRemoveWithLocalPath() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugins", "remove", ts.T().TempDir()). Assert( - lib.MustFail(), - lib.Grep("is not under the plugin directory inferred by Packer", lib.GrepStdout), + check.MustFail(), + check.Grep("is not under the plugin directory inferred by Packer", check.GrepStdout), ) }) } @@ -148,8 +148,8 @@ func (ts *PackerPluginTestSuite) TestPluginsRemoveWithNoArguments() { ts.PackerCommand().UsePluginDir(pluginPath). SetArgs("plugins", "remove"). Assert( - lib.MustFail(), - lib.Grep("Usage: packer plugins remove ", lib.GrepStdout), + check.MustFail(), + check.Grep("Usage: packer plugins remove ", check.GrepStdout), ) }) @@ -165,7 +165,7 @@ func InstalledPlugins(ts *PackerPluginTestSuite, dir string) []string { cmd := ts.PackerCommand().UsePluginDir(dir). SetArgs("plugins", "installed") - cmd.Assert(lib.MustSucceed()) + cmd.Assert(check.MustSucceed()) if ts.T().Failed() { ts.T().Fatalf("Failed to execute plugin installed for %q", dir) } diff --git a/packer_test/plugin_tests/suite_test.go b/packer_test/plugin_tests/suite_test.go index 9153c455e..e7247dfcb 100644 --- a/packer_test/plugin_tests/suite_test.go +++ b/packer_test/plugin_tests/suite_test.go @@ -3,16 +3,16 @@ package plugin_tests import ( "testing" - "github.com/hashicorp/packer/packer_test/lib" + "github.com/hashicorp/packer/packer_test/common" "github.com/stretchr/testify/suite" ) type PackerPluginTestSuite struct { - *lib.PackerTestSuite + *common.PackerTestSuite } func Test_PackerPluginSuite(t *testing.T) { - baseSuite, cleanup := lib.InitBaseSuite(t) + baseSuite, cleanup := common.InitBaseSuite(t) defer cleanup() baseSuite.CompileTestPluginVersions(t, "1.0.0",