diff --git a/test/fixtures/provisioner-file/dir/file.txt b/test/fixtures/provisioner-file/dir/file.txt new file mode 100644 index 000000000..806dddba5 --- /dev/null +++ b/test/fixtures/provisioner-file/dir/file.txt @@ -0,0 +1 @@ +337 miles diff --git a/test/fixtures/provisioner-file/dir_no_trailing.json b/test/fixtures/provisioner-file/dir_no_trailing.json new file mode 100644 index 000000000..e48a2f160 --- /dev/null +++ b/test/fixtures/provisioner-file/dir_no_trailing.json @@ -0,0 +1,22 @@ +{ + "builders": [{ + "type": "amazon-ebs", + "ami_name": "packer-test {{timestamp}}", + "instance_type": "m1.small", + "region": "us-east-1", + "ssh_username": "ubuntu", + "source_ami": "ami-0568456c", + "tags": { + "packer-test": "true" + } + }], + + "provisioners": [{ + "type": "file", + "source": "dir", + "destination": "/tmp" + }, { + "type": "shell", + "inline": ["cat /tmp/dir/file.txt"] + }] +} diff --git a/test/fixtures/provisioner-file/dir_with_trailing.json b/test/fixtures/provisioner-file/dir_with_trailing.json new file mode 100644 index 000000000..bf5f75415 --- /dev/null +++ b/test/fixtures/provisioner-file/dir_with_trailing.json @@ -0,0 +1,22 @@ +{ + "builders": [{ + "type": "amazon-ebs", + "ami_name": "packer-test {{timestamp}}", + "instance_type": "m1.small", + "region": "us-east-1", + "ssh_username": "ubuntu", + "source_ami": "ami-0568456c", + "tags": { + "packer-test": "true" + } + }], + + "provisioners": [{ + "type": "file", + "source": "dir/", + "destination": "/tmp" + }, { + "type": "shell", + "inline": ["cat /tmp/file.txt"] + }] +} diff --git a/test/fixtures/provisioner-file/file.json b/test/fixtures/provisioner-file/file.json new file mode 100644 index 000000000..e8287abb9 --- /dev/null +++ b/test/fixtures/provisioner-file/file.json @@ -0,0 +1,22 @@ +{ + "builders": [{ + "type": "amazon-ebs", + "ami_name": "packer-test {{timestamp}}", + "instance_type": "m1.small", + "region": "us-east-1", + "ssh_username": "ubuntu", + "source_ami": "ami-0568456c", + "tags": { + "packer-test": "true" + } + }], + + "provisioners": [{ + "type": "file", + "source": "file.txt", + "destination": "/tmp/file.txt" + }, { + "type": "shell", + "inline": ["cat /tmp/file.txt"] + }] +} diff --git a/test/fixtures/provisioner-file/file.txt b/test/fixtures/provisioner-file/file.txt new file mode 100644 index 000000000..e8a85b0cd --- /dev/null +++ b/test/fixtures/provisioner-file/file.txt @@ -0,0 +1 @@ +24901 miles diff --git a/test/provisioner_file.bats b/test/provisioner_file.bats new file mode 100755 index 000000000..dafe7771a --- /dev/null +++ b/test/provisioner_file.bats @@ -0,0 +1,34 @@ +#!/usr/bin/env bats +# +# This tests the amazon-ebs builder. The teardown function will automatically +# delete any AMIs with a tag of `packer-test` being equal to "true" so +# be sure any test cases set this. + +load test_helper +fixtures provisioner-file + +setup() { + cd $FIXTURE_ROOT +} + +teardown() { + aws_ami_cleanup +} + +@test "file provisioner: single file" { + run packer build $FIXTURE_ROOT/file.json + [ "$status" -eq 0 ] + [[ "$output" == *"24901 miles"* ]] +} + +@test "file provisioner: directory (no trailing slash)" { + run packer build $FIXTURE_ROOT/dir_no_trailing.json + [ "$status" -eq 0 ] + [[ "$output" == *"337 miles"* ]] +} + +@test "file provisioner: directory (with trailing slash)" { + run packer build $FIXTURE_ROOT/dir_with_trailing.json + [ "$status" -eq 0 ] + [[ "$output" == *"337 miles"* ]] +}