add tests and update override example
This commit is contained in:
parent
62c3743890
commit
39a8dee4ea
|
@ -328,19 +328,32 @@ func TestBuild(t *testing.T) {
|
|||
func Test_build_output(t *testing.T) {
|
||||
|
||||
tc := []struct {
|
||||
command []string
|
||||
env []string
|
||||
expected string
|
||||
runtime string
|
||||
command []string
|
||||
env []string
|
||||
expected []string
|
||||
notExpected []string
|
||||
runtime string
|
||||
}{
|
||||
{[]string{"build", "--color=false", testFixture("hcl", "reprepare", "shell-local.pkr.hcl")}, nil,
|
||||
`
|
||||
null.example: hello from the NULL builder packeruser
|
||||
Build 'null.example' finished after`, "posix"},
|
||||
{[]string{"build", "--color=false", testFixture("hcl", "reprepare", "shell-local-windows.pkr.hcl")}, nil,
|
||||
`
|
||||
null.example: hello from the NULL builder packeruser
|
||||
Build 'null.example' finished after`, "windows"},
|
||||
{[]string{"build", "--color=false", testFixture("hcl", "reprepare", "shell-local.pkr.hcl")},
|
||||
nil,
|
||||
[]string{"null.example: hello from the NULL builder packeruser", "Build 'null.example' finished after"},
|
||||
[]string{},
|
||||
"posix"},
|
||||
{[]string{"build", "--color=false", testFixture("hcl", "reprepare", "shell-local-windows.pkr.hcl")},
|
||||
nil,
|
||||
[]string{"null.example: hello from the NULL builder packeruser", "Build 'null.example' finished after"},
|
||||
[]string{},
|
||||
"windows"},
|
||||
{[]string{"build", "--color=false", testFixture("hcl", "provisioner-override.pkr.hcl")},
|
||||
nil,
|
||||
[]string{"null.example1: yes overridden", "null.example2: not overridden"},
|
||||
[]string{"null.example2: yes overridden", "null.example1: not overridden"},
|
||||
"posix"},
|
||||
{[]string{"build", "--color=false", testFixture("provisioners", "provisioner-override.json")},
|
||||
nil,
|
||||
[]string{"example1: yes overridden", "example2: not overridden"},
|
||||
[]string{"example2: yes overridden", "example1: not overridden"},
|
||||
"posix"},
|
||||
}
|
||||
|
||||
for _, tc := range tc {
|
||||
|
@ -354,8 +367,15 @@ Build 'null.example' finished after`, "windows"},
|
|||
if err != nil {
|
||||
t.Fatalf("%v: %s", err, bs)
|
||||
}
|
||||
if !strings.Contains(string(bs), tc.expected) {
|
||||
t.Fatalf("Should contain output %s.\nReceived: %s", tc.expected, string(bs))
|
||||
for _, expected := range tc.expected {
|
||||
if !strings.Contains(string(bs), expected) {
|
||||
t.Fatalf("Should contain output %s.\nReceived: %s", tc.expected, string(bs))
|
||||
}
|
||||
}
|
||||
for _, notExpected := range tc.notExpected {
|
||||
if strings.Contains(string(bs), notExpected) {
|
||||
t.Fatalf("Should NOT contain output %s.\nReceived: %s", tc.expected, string(bs))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
source "null" "example1" {
|
||||
communicator = "none"
|
||||
}
|
||||
|
||||
source "null" "example2" {
|
||||
communicator = "none"
|
||||
}
|
||||
|
||||
build {
|
||||
sources = ["source.null.example1", "source.null.example2"]
|
||||
provisioner "shell-local" {
|
||||
inline = ["echo not overridden"]
|
||||
override = {
|
||||
example1 = {
|
||||
inline = ["echo yes overridden"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"builders": [
|
||||
{
|
||||
"type": "null",
|
||||
"name": "example1",
|
||||
"communicator": "none"
|
||||
},
|
||||
{
|
||||
"type": "null",
|
||||
"name": "example2",
|
||||
"communicator": "none"
|
||||
}
|
||||
],
|
||||
"provisioners": [
|
||||
{
|
||||
"type": "shell-local",
|
||||
"inline": ["echo not overridden"],
|
||||
"override": {
|
||||
"example1": {
|
||||
"inline": ["echo yes overridden"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -13,29 +13,53 @@ Parameters common to all provisioners:
|
|||
In JSON:
|
||||
```json
|
||||
{
|
||||
"type": "shell",
|
||||
"script": "script.sh",
|
||||
"override": {
|
||||
"example_one": {
|
||||
"script": "basic_one-script.sh"
|
||||
"builders": [
|
||||
{
|
||||
"type": "null",
|
||||
"name": "example1",
|
||||
"communicator": "none"
|
||||
},
|
||||
{
|
||||
"type": "null",
|
||||
"name": "example2",
|
||||
"communicator": "none"
|
||||
}
|
||||
}
|
||||
],
|
||||
"provisioners": [
|
||||
{
|
||||
"type": "shell-local",
|
||||
"inline": ["echo not overridden"],
|
||||
"override": {
|
||||
"example1": {
|
||||
"inline": ["echo yes overridden"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
In HCL2:
|
||||
```hcl
|
||||
build {
|
||||
sources = ["docker.example_one", "docker.example_two"]
|
||||
provisioner "shell" {
|
||||
script = "script.sh"
|
||||
override = {
|
||||
example_one = {
|
||||
script = "basic-one-script.sh"
|
||||
}
|
||||
}
|
||||
source "null" "example1" {
|
||||
communicator = "none"
|
||||
}
|
||||
|
||||
source "null" "example2" {
|
||||
communicator = "none"
|
||||
}
|
||||
|
||||
build {
|
||||
sources = ["source.null.example1", "source.null.example2"]
|
||||
provisioner "shell-local" {
|
||||
inline = ["echo not overridden"]
|
||||
override = {
|
||||
example1 = {
|
||||
inline = ["echo yes overridden"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- `timeout` (duration) - If the provisioner takes more than for example
|
||||
|
|
Loading…
Reference in New Issue