From dbaaab512a4d90a37907ce757ee1c9a24872bb5b Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Wed, 12 Jun 2024 15:54:03 -0400 Subject: [PATCH] packer_test: add SkipNoAcc function The SkipNoAcc function on PackerTestSuite allows to mark a test run as not to be run every time we run `make test`, but only when PACKER_ACC=1 is set in the environment. This allows us to skip executing tests that are either long-running, or that depend on external dependencies (typically Github), which have a higher potential to fail on a normal run of Packer tests. --- packer_test/init_test.go | 6 ++++++ packer_test/install_test.go | 4 ++++ packer_test/suite_test.go | 14 ++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/packer_test/init_test.go b/packer_test/init_test.go index 6a9196a94..38939ec25 100644 --- a/packer_test/init_test.go +++ b/packer_test/init_test.go @@ -1,6 +1,8 @@ package packer_test func (ts *PackerTestSuite) TestPackerInitForce() { + ts.SkipNoAcc() + pluginPath, cleanup := ts.MakePluginDir() defer cleanup() @@ -18,6 +20,8 @@ func (ts *PackerTestSuite) TestPackerInitForce() { } func (ts *PackerTestSuite) TestPackerInitUpgrade() { + ts.SkipNoAcc() + pluginPath, cleanup := ts.MakePluginDir() defer cleanup() @@ -62,6 +66,8 @@ func (ts *PackerTestSuite) TestPackerInitWithNonGithubSource() { } func (ts *PackerTestSuite) TestPackerInitWithMixedVersions() { + ts.SkipNoAcc() + pluginPath, cleanup := ts.MakePluginDir() defer cleanup() diff --git a/packer_test/install_test.go b/packer_test/install_test.go index 1f039b51e..3472c9af3 100644 --- a/packer_test/install_test.go +++ b/packer_test/install_test.go @@ -69,6 +69,8 @@ func (ts *PackerTestSuite) TestInstallPluginPrerelease() { } func (ts *PackerTestSuite) TestRemoteInstallWithPluginsInstall() { + ts.SkipNoAcc() + pluginPath, cleanup := ts.MakePluginDir() defer cleanup() @@ -80,6 +82,8 @@ func (ts *PackerTestSuite) TestRemoteInstallWithPluginsInstall() { } func (ts *PackerTestSuite) TestRemoteInstallOfPreReleasePlugin() { + ts.SkipNoAcc() + pluginPath, cleanup := ts.MakePluginDir() defer cleanup() diff --git a/packer_test/suite_test.go b/packer_test/suite_test.go index 0b6b98241..ad76281c6 100644 --- a/packer_test/suite_test.go +++ b/packer_test/suite_test.go @@ -42,6 +42,20 @@ func (ts *PackerTestSuite) buildPluginBinaries(t *testing.T) { wg.Wait() } +// SkipNoAcc is a pre-condition that skips the test if the PACKER_ACC environment +// variable is unset, or set to "0". +// +// This allows us to build tests with a potential for long runs (or errors like +// rate-limiting), so we can still test them, but only in a longer timeouted +// context. +func (ts *PackerTestSuite) SkipNoAcc() { + acc := os.Getenv("PACKER_ACC") + if acc == "" || acc == "0" { + ts.T().Logf("Skipping test as `PACKER_ACC` is unset.") + ts.T().Skip() + } +} + func Test_PackerCoreSuite(t *testing.T) { ts := &PackerTestSuite{}