mirror of
https://github.com/hashicorp/packer.git
synced 2026-05-28 04:35:38 -04:00
test(provisioner): add test for shebang within inline script
This commit is contained in:
parent
e8c2f7b3b0
commit
f21b2c8e9b
1 changed files with 44 additions and 0 deletions
|
|
@ -98,6 +98,50 @@ func TestProvisionerPrepare_InlineShebang(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestProvisionerPrepare_ShebangWithinInline(t *testing.T) {
|
||||
config := testConfig()
|
||||
script := `#!/bin/bash
|
||||
echo "Hello, World!"
|
||||
`
|
||||
config["inline"] = []interface{}{script, "foo", "bar"}
|
||||
|
||||
p := new(Provisioner)
|
||||
err := p.Prepare(config)
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
if p.config.InlineShebang != "/bin/bash" {
|
||||
t.Fatalf("bad value: %s", p.config.InlineShebang)
|
||||
}
|
||||
|
||||
// Test with InlineShebang, it should override the shebang in the script
|
||||
config["inline_shebang"] = "foo"
|
||||
p = new(Provisioner)
|
||||
err = p.Prepare(config)
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
if p.config.InlineShebang != "foo" {
|
||||
t.Fatalf("bad value: %s", p.config.InlineShebang)
|
||||
}
|
||||
|
||||
// Test with a inline that does not have a shebang
|
||||
config["inline"] = []interface{}{"foo", "bar"}
|
||||
delete(config, "inline_shebang")
|
||||
p = new(Provisioner)
|
||||
err = p.Prepare(config)
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
if p.config.InlineShebang != "/bin/sh -e" {
|
||||
t.Fatalf("bad value: %s", p.config.InlineShebang)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestProvisionerPrepare_InvalidKey(t *testing.T) {
|
||||
var p Provisioner
|
||||
config := testConfig()
|
||||
|
|
|
|||
Loading…
Reference in a new issue