From 85e615bbe22e22613807c764d1c0e0e637f3b28f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 26 May 2015 09:16:39 -0700 Subject: [PATCH] packer: a lot more provisioner tests --- packer/core_test.go | 68 +++++++++++++++++++ .../build-prov-skip-include.json | 10 +++ packer/test-fixtures/build-prov-skip.json | 10 +++ 3 files changed, 88 insertions(+) create mode 100644 packer/test-fixtures/build-prov-skip-include.json create mode 100644 packer/test-fixtures/build-prov-skip.json diff --git a/packer/core_test.go b/packer/core_test.go index c8cdfbfb8..5ef96dc96 100644 --- a/packer/core_test.go +++ b/packer/core_test.go @@ -154,6 +154,74 @@ func TestCoreBuild_prov(t *testing.T) { } } +func TestCoreBuild_provSkip(t *testing.T) { + config := TestCoreConfig(t) + testCoreTemplate(t, config, fixtureDir("build-prov-skip.json")) + b := TestBuilder(t, config, "test") + p := TestProvisioner(t, config, "test") + core := TestCore(t, config) + + b.ArtifactId = "hello" + + build, err := core.Build("test") + if err != nil { + t.Fatalf("err: %s", err) + } + + if _, err := build.Prepare(); err != nil { + t.Fatalf("err: %s", err) + } + + artifact, err := build.Run(nil, nil) + if err != nil { + t.Fatalf("err: %s", err) + } + if len(artifact) != 1 { + t.Fatalf("bad: %#v", artifact) + } + + if artifact[0].Id() != b.ArtifactId { + t.Fatalf("bad: %s", artifact[0].Id()) + } + if p.ProvCalled { + t.Fatal("provisioner should not be called") + } +} + +func TestCoreBuild_provSkipInclude(t *testing.T) { + config := TestCoreConfig(t) + testCoreTemplate(t, config, fixtureDir("build-prov-skip-include.json")) + b := TestBuilder(t, config, "test") + p := TestProvisioner(t, config, "test") + core := TestCore(t, config) + + b.ArtifactId = "hello" + + build, err := core.Build("test") + if err != nil { + t.Fatalf("err: %s", err) + } + + if _, err := build.Prepare(); err != nil { + t.Fatalf("err: %s", err) + } + + artifact, err := build.Run(nil, nil) + if err != nil { + t.Fatalf("err: %s", err) + } + if len(artifact) != 1 { + t.Fatalf("bad: %#v", artifact) + } + + if artifact[0].Id() != b.ArtifactId { + t.Fatalf("bad: %s", artifact[0].Id()) + } + if !p.ProvCalled { + t.Fatal("provisioner should be called") + } +} + func TestCoreValidate(t *testing.T) { cases := []struct { File string diff --git a/packer/test-fixtures/build-prov-skip-include.json b/packer/test-fixtures/build-prov-skip-include.json new file mode 100644 index 000000000..2ba5e77de --- /dev/null +++ b/packer/test-fixtures/build-prov-skip-include.json @@ -0,0 +1,10 @@ +{ + "builders": [{ + "type": "test" + }], + + "provisioners": [{ + "type": "test", + "only": ["test"] + }] +} diff --git a/packer/test-fixtures/build-prov-skip.json b/packer/test-fixtures/build-prov-skip.json new file mode 100644 index 000000000..bd9fa5072 --- /dev/null +++ b/packer/test-fixtures/build-prov-skip.json @@ -0,0 +1,10 @@ +{ + "builders": [{ + "type": "test" + }], + + "provisioners": [{ + "type": "test", + "only": ["foo"] + }] +}