Skip to content

Commit

Permalink
packer_test: add SkipNoAcc function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lbajolet-hashicorp committed Jun 12, 2024
1 parent 65b47ac commit e7ab35c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packer_test/core_tests/local_eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
)

func (ts *PackerCoreTestSuite) TestEvalLocalsOrder() {
ts.SkipNoAcc()

pluginDir, cleanup := ts.MakePluginDir()
defer cleanup()

Expand Down
14 changes: 14 additions & 0 deletions packer_test/lib/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ func (ts *PackerTestSuite) BuildSimplePlugin(versionString string, t *testing.T)
return outBin
}

// 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 PackerCoreSuite(t *testing.T) (*PackerTestSuite, func()) {
ts := &PackerTestSuite{}

Expand Down
6 changes: 6 additions & 0 deletions packer_test/plugin_tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package plugin_tests
import "github.com/hashicorp/packer/packer_test/lib"

func (ts *PackerPluginTestSuite) TestPackerInitForce() {
ts.SkipNoAcc()

pluginPath, cleanup := ts.MakePluginDir()
defer cleanup()

Expand All @@ -20,6 +22,8 @@ func (ts *PackerPluginTestSuite) TestPackerInitForce() {
}

func (ts *PackerPluginTestSuite) TestPackerInitUpgrade() {
ts.SkipNoAcc()

pluginPath, cleanup := ts.MakePluginDir()
defer cleanup()

Expand Down Expand Up @@ -64,6 +68,8 @@ func (ts *PackerPluginTestSuite) TestPackerInitWithNonGithubSource() {
}

func (ts *PackerPluginTestSuite) TestPackerInitWithMixedVersions() {
ts.SkipNoAcc()

pluginPath, cleanup := ts.MakePluginDir()
defer cleanup()

Expand Down

0 comments on commit e7ab35c

Please sign in to comment.