mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-09 00:32:09 -04:00
packer_test: add base tests for DAG eval
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.
This commit is contained in:
parent
8d6b8da996
commit
418ebca7ef
3 changed files with 72 additions and 0 deletions
26
packer_test/dag_tests/mix_data_locals_test.go
Normal file
26
packer_test/dag_tests/mix_data_locals_test.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/packer/packer_test/common/check"
|
||||
)
|
||||
|
||||
func (ts *PackerDAGTestSuite) TestWithBothDataLocalMixedOrder() {
|
||||
pluginDir := ts.MakePluginDir()
|
||||
defer pluginDir.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(check.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(check.MustFail())
|
||||
})
|
||||
}
|
||||
}
|
||||
23
packer_test/dag_tests/suite_test.go
Normal file
23
packer_test/dag_tests/suite_test.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer_test/common"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
type PackerDAGTestSuite struct {
|
||||
*common.PackerTestSuite
|
||||
}
|
||||
|
||||
func Test_PackerDAGSuite(t *testing.T) {
|
||||
baseSuite, cleanup := common.InitBaseSuite(t)
|
||||
defer cleanup()
|
||||
|
||||
ts := &PackerDAGTestSuite{
|
||||
baseSuite,
|
||||
}
|
||||
|
||||
suite.Run(t, ts)
|
||||
}
|
||||
23
packer_test/dag_tests/templates/mixed_data_local.pkr.hcl
Normal file
23
packer_test/dag_tests/templates/mixed_data_local.pkr.hcl
Normal file
|
|
@ -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"]
|
||||
}
|
||||
Loading…
Reference in a new issue