Skip to content

Commit

Permalink
packer_test: add base tests for DAG eval
Browse files Browse the repository at this point in the history
Since we introduce the DAG with this series of commits, only on locals
and data sources, we need to make sure that the behaviour is what we
expect.

Therefore, this commit adds a basic test with Packer build, and packer
validate, to evaluate a template with both locals and data sources
depending on one another.

This is rejected with the sequential evaluation methods, as we process
the different types one-by-one, whereas the DAG allows us to mix the
order between the two, while still rejecting circular dependencies (and
doing that before they even get evaluated), and self-references.
  • Loading branch information
lbajolet-hashicorp committed Sep 5, 2024
1 parent 81511d4 commit 7fae5b6
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packer_test/dag_tests/mix_data_locals_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"

"github.com/hashicorp/packer/packer_test/lib"
)

func (ts *PackerDAGTestSuite) TestWithBothDataLocalMixedOrder() {
pluginDir, cleanup := ts.MakePluginDir()
defer cleanup()

for _, cmd := range []string{"build", "validate"} {
ts.Run(fmt.Sprintf("%s: evaluating with DAG - success expected", cmd), func() {
ts.PackerCommand().UsePluginDir(pluginDir).
SetArgs(cmd, "./templates/mixed_data_local.pkr.hcl").
Assert(lib.MustSucceed())
})

ts.Run(fmt.Sprintf("%s: evaluating sequentially - failure expected", cmd), func() {
ts.PackerCommand().UsePluginDir(pluginDir).
SetArgs(cmd, "--use-sequential-evaluation", "./templates/mixed_data_local.pkr.hcl").
Assert(lib.MustFail())
})
}
}
23 changes: 23 additions & 0 deletions packer_test/dag_tests/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"testing"

"github.com/hashicorp/packer/packer_test/lib"
"github.com/stretchr/testify/suite"
)

type PackerDAGTestSuite struct {
*lib.PackerTestSuite
}

func Test_PackerDAGSuite(t *testing.T) {
baseSuite, cleanup := lib.PackerCoreSuite(t)
defer cleanup()

ts := &PackerDAGTestSuite{
baseSuite,
}

suite.Run(t, ts)
}
23 changes: 23 additions & 0 deletions packer_test/dag_tests/templates/mixed_data_local.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
data "null" "head" {
input = "foo"
}

locals {
loc = "${data.null.head.output}"
}

data "null" "tail" {
input = "${local.loc}"
}

locals {
last = "final - ${data.null.tail.output}"
}

source "null" "test" {
communicator = "none"
}

build {
sources = ["null.test"]
}

0 comments on commit 7fae5b6

Please sign in to comment.