From a8f8902cd39a5b6ac2d41b14cce643c33e562ea4 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Thu, 14 Mar 2024 15:45:54 -0400 Subject: [PATCH] test: remove directory The test directory contains artifacts from the project's past which are never used nowadays. All those remains are therefore removed with this commit, and we can replace that directory's contents with more up-to-date contents. --- test/README.md | 74 ------------ test/builder_googlecompute.bats | 36 ------ test/builder_hyperone.bats | 48 -------- test/builder_lxc.bats | 106 ------------------ test/cli.bats | 36 ------ test/communicator_ssh.bats | 30 ----- test/fixtures/amazon-ebs/ami_region_copy.json | 15 --- test/fixtures/amazon-ebs/minimal.json | 13 --- .../builder-googlecompute/minimal.json | 16 --- test/fixtures/builder-hyperone/chroot.json | 30 ----- test/fixtures/builder-hyperone/minimal.json | 18 --- .../builder-hyperone/new-syntax.pkr.hcl | 29 ----- test/fixtures/builder-linode/minimal.json | 28 ----- test/fixtures/builder-lxc/minimal.json | 31 ----- .../communicator-ssh/local-tunnel.json | 21 ---- .../communicator-ssh/remote-tunnel.json | 22 ---- test/fixtures/provisioner-file/dir/file.txt | 1 - .../provisioner-file/dir_no_trailing.json | 22 ---- .../dir_no_trailing_sftp.json | 23 ---- .../provisioner-file/dir_with_trailing.json | 22 ---- .../dir_with_trailing_sftp.json | 23 ---- test/fixtures/provisioner-file/file.json | 22 ---- test/fixtures/provisioner-file/file.txt | 1 - test/fixtures/provisioner-file/file_sftp.json | 23 ---- test/fixtures/provisioner-shell/inline.json | 21 ---- test/fixtures/provisioner-shell/script.json | 18 --- test/fixtures/provisioner-shell/script.sh | 3 - test/fixtures/provisioner-shell/scripts.json | 20 ---- test/provisioner_file.bats | 53 --------- test/provisioner_shell.bats | 36 ------ test/test_helper.bash | 52 --------- 31 files changed, 893 deletions(-) delete mode 100644 test/README.md delete mode 100755 test/builder_googlecompute.bats delete mode 100755 test/builder_hyperone.bats delete mode 100644 test/builder_lxc.bats delete mode 100755 test/cli.bats delete mode 100644 test/communicator_ssh.bats delete mode 100644 test/fixtures/amazon-ebs/ami_region_copy.json delete mode 100644 test/fixtures/amazon-ebs/minimal.json delete mode 100644 test/fixtures/builder-googlecompute/minimal.json delete mode 100644 test/fixtures/builder-hyperone/chroot.json delete mode 100644 test/fixtures/builder-hyperone/minimal.json delete mode 100644 test/fixtures/builder-hyperone/new-syntax.pkr.hcl delete mode 100644 test/fixtures/builder-linode/minimal.json delete mode 100644 test/fixtures/builder-lxc/minimal.json delete mode 100644 test/fixtures/communicator-ssh/local-tunnel.json delete mode 100644 test/fixtures/communicator-ssh/remote-tunnel.json delete mode 100644 test/fixtures/provisioner-file/dir/file.txt delete mode 100644 test/fixtures/provisioner-file/dir_no_trailing.json delete mode 100644 test/fixtures/provisioner-file/dir_no_trailing_sftp.json delete mode 100644 test/fixtures/provisioner-file/dir_with_trailing.json delete mode 100644 test/fixtures/provisioner-file/dir_with_trailing_sftp.json delete mode 100644 test/fixtures/provisioner-file/file.json delete mode 100644 test/fixtures/provisioner-file/file.txt delete mode 100644 test/fixtures/provisioner-file/file_sftp.json delete mode 100644 test/fixtures/provisioner-shell/inline.json delete mode 100644 test/fixtures/provisioner-shell/script.json delete mode 100755 test/fixtures/provisioner-shell/script.sh delete mode 100644 test/fixtures/provisioner-shell/scripts.json delete mode 100755 test/provisioner_file.bats delete mode 100755 test/provisioner_shell.bats delete mode 100644 test/test_helper.bash diff --git a/test/README.md b/test/README.md deleted file mode 100644 index 1c8949f1f..000000000 --- a/test/README.md +++ /dev/null @@ -1,74 +0,0 @@ -# Packer Black-Box Tests - -This folder contains tests that test Packer using a black-box approach: -`packer` is executed directly (with whatever is on the PATH) and certain -results are expected. - -Tests are run using [Bats](https://github.com/sstephenson/bats), and therefore -Bash is required to run any tests. - -**Warning:** Many of these tests run using cloud infrastructure, and therefore have -a real-world cost associated with running the tests. Be aware of that prior -to running the tests. Additionally, many tests will leave left-over artifacts -(AMIs) that you'll have to manually clean up. - -## Running Tests - -### Required Software - -Before running the tests, you'll need the following installed. If you're -running on macOS, most of these are available with `brew`: - -* [Bats](https://github.com/sstephenson/bats) - -* [AWS cli](http://aws.amazon.com/cli/) for AWS tests as well as most - of the components. - -* [gcutil](https://developers.google.com/compute/docs/gcutil/#install) for - Google Compute Engine tests. - -* [h1-cli](https://github.com/hyperonecom/h1-client-go) for HyperOne tests. - -### Configuring Tests - -**For tests that require AWS credentials:** - -Set the following self-explanatory environmental variables: - -* `AWS_ACCESS_KEY_ID` -* `AWS_SECRET_ACCESS_KEY` - -**For tests that test Google Compute Engine:** - -Set the following environmental variables: - -* `GC_BUCKET_NAME` -* `GC_ACCOUNT_FILE` -* `GC_PROJECT_ID` - -**For tests that test HyperOne:** - -Set the following environmental variables: - -* `HYPERONE_TOKEN` -* `HYPERONE_PROJECT` - -You have to be authenticated within the `h1` tool (use `h1 login`). - -### Running - -These tests are meant to be run _one file at a time_. There are some -test files (such as the amazon-chroot builder test) that simply won't -run except in special environments, so running all test files will probably -never work. - -If you're working on Packer and want to test that your change didn't -adversely affect something, try running only the test that is related to -your change. - -``` -$ bats builder_amazon_ebs.bats -``` - -Note: Working directory doesn't matter. You can call the bats test file -from any directory. diff --git a/test/builder_googlecompute.bats b/test/builder_googlecompute.bats deleted file mode 100755 index 1051bb99a..000000000 --- a/test/builder_googlecompute.bats +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bats -# -# This tests the googlecompute builder. The teardown function will -# delete any images with the text "packerbats" within the name. - -load test_helper -fixtures builder-googlecompute - -# Required parameters -: ${GC_ACCOUNT_FILE:?} -: ${GC_PROJECT_ID:?} -command -v gcloud >/dev/null 2>&1 || { - echo "'gcloud' must be installed" >&2 - exit 1 -} - -USER_VARS="${USER_VARS} -var account_file=${GC_ACCOUNT_FILE}" -USER_VARS="${USER_VARS} -var project_id=${GC_PROJECT_ID}" - -# This tests if GCE has an image that contains the given parameter. -gc_has_image() { - gcloud compute --format='table[no-heading](name)' --project=${GC_PROJECT_ID} images list \ - | grep $1 | wc -l -} - -teardown() { - gcloud compute --format='table[no-heading](name)' --project=${GC_PROJECT_ID} images list \ - | grep packerbats \ - | xargs -n1 gcloud compute --project=${GC_PROJECT_ID} images delete -} - -@test "googlecompute: build minimal.json" { - run packer build ${USER_VARS} $FIXTURE_ROOT/minimal.json - [ "$status" -eq 0 ] - [ "$(gc_has_image "packerbats-minimal")" -eq 1 ] -} diff --git a/test/builder_hyperone.bats b/test/builder_hyperone.bats deleted file mode 100755 index 66ae5e3fe..000000000 --- a/test/builder_hyperone.bats +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bats -# -# This tests the hyperone builder. The teardown function will -# delete any images with the text "packerbats" within the name. - -load test_helper -fixtures builder-hyperone - -# Required parameters -: ${HYPERONE_TOKEN:?} -: ${HYPERONE_PROJECT:?} -command -v h1 >/dev/null 2>&1 || { - echo "'h1' must be installed" >&2 - exit 1 -} - -USER_VARS="${USER_VARS} -var token=${HYPERONE_TOKEN}" -USER_VARS="${USER_VARS} -var project=${HYPERONE_PROJECT}" - -hyperone_has_image() { - h1 image list --project-select=${HYPERONE_PROJECT} --query "[?tag.${2}=='${3}']" --output=tsv | grep $1 -c -} - -teardown() { - h1 image list --project-select=${HYPERONE_PROJECT} --output=tsv \ - | grep packerbats \ - | awk '{print $1}' \ - | xargs -n1 h1 image delete --project-select=${HYPERONE_PROJECT} --yes --image -} - -@test "hyperone: build minimal.json" { - run packer build ${USER_VARS} $FIXTURE_ROOT/minimal.json - [ "$status" -eq 0 ] - [ "$(hyperone_has_image "packerbats-minimal" "key" "value")" -eq 1 ] -} - -@test "hyperone: build new-syntax.pkr.hcl" { - run packer build ${USER_VARS} $FIXTURE_ROOT/new-syntax.pkr.hcl - [ "$status" -eq 0 ] - [ "$(hyperone_has_image "packerbats-hcl" "key" "value")" -eq 1 ] -} - - -@test "hyperone: build chroot.json" { - run packer build ${USER_VARS} $FIXTURE_ROOT/chroot.json - [ "$status" -eq 0 ] - [ "$(hyperone_has_image "packerbats-chroot" "key2" "value2")" -eq 1 ] -} diff --git a/test/builder_lxc.bats b/test/builder_lxc.bats deleted file mode 100644 index 7173d0f7d..000000000 --- a/test/builder_lxc.bats +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env bats -# -# This tests the lxc builder by creating minimal containers and checking that -# custom lxc container configuration files are successfully applied. The -# teardown function will delete any images in the output-lxc-* folders along -# with the auto-generated lxc container configuration files and hook scripts. - -#load test_helper -#fixtures builder-lxc -FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/builder-lxc" - -have_command() { - command -v "$1" >/dev/null 2>&1 -} - -# Required parameters -have_command lxc-create || { - echo "'lxc-create' must be installed via the lxc (or lxc1 for ubuntu >=16.04) package" >&2 - exit 1 -} - -DESTROY_HOOK_SCRIPT=$FIXTURE_ROOT/destroy-hook.sh -DESTROY_HOOK_LOG=$FIXTURE_ROOT/destroy-hook.log -printf > "$DESTROY_HOOK_SCRIPT" ' -echo "$LXC_NAME" > "%s" -' "$DESTROY_HOOK_LOG" -chmod +x "$DESTROY_HOOK_SCRIPT" - -INIT_CONFIG=$FIXTURE_ROOT/lxc.custom.conf -printf > "$INIT_CONFIG" ' -lxc.hook.destroy = %s -' "$DESTROY_HOOK_SCRIPT" - -teardown() { - for f in "$INIT_CONFIG" "$DESTROY_HOOK_SCRIPT" "$DESTROY_HOOK_LOG"; do - [ -e "$f" ] && rm -f "$f" - done - - rm -rf output-lxc-* -} - -assert_build() { - local template_name="$1" - shift - - local build_status=0 - - run packer build -var template_name="$template_name" "$@" - - [ "$status" -eq 0 ] || { - echo "${template_name} build exited badly: $status" >&2 - echo "$output" >&2 - build_status="$status" - } - - for expected in "output-lxc-${template_name}"/{rootfs.tar.gz,lxc-config}; do - [ -f "$expected" ] || { - echo "missing expected artifact '${expected}'" >&2 - build_status=1 - } - done - - return $build_status -} - -assert_container_name() { - local container_name="$1" - - [ -f "$DESTROY_HOOK_LOG" ] || { - echo "missing expected lxc.hook.destroy logfile '$DESTROY_HOOK_LOG'" - return 1 - } - - read -r lxc_name < "$DESTROY_HOOK_LOG" - - [ "$lxc_name" = "$container_name" ] -} - -@test "lxc: build centos minimal.json" { - have_command yum || skip "'yum' must be installed to build centos containers" - local container_name=packer-lxc-centos - assert_build centos -var init_config="$INIT_CONFIG" \ - -var container_name="$container_name" \ - $FIXTURE_ROOT/minimal.json - assert_container_name "$container_name" -} - -@test "lxc: build trusty minimal.json" { - have_command debootstrap || skip "'debootstrap' must be installed to build ubuntu containers" - local container_name=packer-lxc-ubuntu - assert_build ubuntu -var init_config="$INIT_CONFIG" \ - -var container_name="$container_name" \ - -var template_parameters="SUITE=trusty" \ - $FIXTURE_ROOT/minimal.json - assert_container_name "$container_name" -} - -@test "lxc: build debian minimal.json" { - have_command debootstrap || skip "'debootstrap' must be installed to build debian containers" - local container_name=packer-lxc-debian - assert_build debian -var init_config="$INIT_CONFIG" \ - -var container_name="$container_name" \ - -var template_parameters="SUITE=jessie" \ - $FIXTURE_ROOT/minimal.json - assert_container_name "$container_name" -} diff --git a/test/cli.bats b/test/cli.bats deleted file mode 100755 index 0284dd3e3..000000000 --- a/test/cli.bats +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bats -# -# This tests the basic CLI functionality of Packer. It makes no network -# requests and should be very fast. - -load test_helper - -@test "cli: packer should show help" { - run packer - [ "$status" -eq 1 ] - [[ "$output" == *"usage: packer"* ]] -} - -@test "cli: packer version" { - run packer version - [ "$status" -eq 0 ] - [[ "$output" == *"Packer v"* ]] - - run packer -v - [ "$status" -eq 1 ] - [[ "$output" =~ ([0-9]+\.[0-9]+) ]] - - run packer --version - [ "$status" -eq 1 ] - [[ "$output" =~ ([0-9]+\.[0-9]+) ]] -} - -@test "cli: packer version show help" { - run packer version -h - [ "$status" -eq 0 ] - [[ "$output" == *"Packer v"* ]] - - run packer version --help - [ "$status" -eq 0 ] - [[ "$output" == *"Packer v"* ]] -} diff --git a/test/communicator_ssh.bats b/test/communicator_ssh.bats deleted file mode 100644 index eb466c9c3..000000000 --- a/test/communicator_ssh.bats +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bats -# -# This tests the ssh communicator using AWS 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 -verify_aws_cli -fixtures communicator-ssh - -setup() { - cd $FIXTURE_ROOT -} - -teardown() { - aws_ami_cleanup -} - -@test "shell provisioner: local port tunneling" { - run packer build $FIXTURE_ROOT/local-tunnel.json - [ "$status" -eq 0 ] - [[ "$output" == *"Connection to localhost port 10022 [tcp/*] succeeded"* ]] -} - -@test "shell provisioner: remote port tunneling" { - run packer build $FIXTURE_ROOT/remote-tunnel.json - [ "$status" -eq 0 ] - MY_LOCAL_IP=$(curl -s https://ifconfig.co/) - [[ "$output" == *"$MY_LOCAL_IP"* ]] -} diff --git a/test/fixtures/amazon-ebs/ami_region_copy.json b/test/fixtures/amazon-ebs/ami_region_copy.json deleted file mode 100644 index 6f591b6bd..000000000 --- a/test/fixtures/amazon-ebs/ami_region_copy.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "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", - "packer-id": "ami_region_copy" - }, - "ami_regions": ["us-west-1", "us-west-2"] - }] -} diff --git a/test/fixtures/amazon-ebs/minimal.json b/test/fixtures/amazon-ebs/minimal.json deleted file mode 100644 index bfe7cab63..000000000 --- a/test/fixtures/amazon-ebs/minimal.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "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" - } - }] -} diff --git a/test/fixtures/builder-googlecompute/minimal.json b/test/fixtures/builder-googlecompute/minimal.json deleted file mode 100644 index 95dd99254..000000000 --- a/test/fixtures/builder-googlecompute/minimal.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "variables": { - "account_file": null, - "project_id": null - }, - - "builders": [{ - "type": "googlecompute", - "account_file": "{{user `account_file`}}", - "project_id": "{{user `project_id`}}", - - "image_name": "packerbats-minimal-{{timestamp}}", - "source_image": "debian-7-wheezy-v20141108", - "zone": "us-central1-a" - }] -} diff --git a/test/fixtures/builder-hyperone/chroot.json b/test/fixtures/builder-hyperone/chroot.json deleted file mode 100644 index ccf7a8be5..000000000 --- a/test/fixtures/builder-hyperone/chroot.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "variables": { - "token": null, - "project": null - }, - "builders": [{ - "token": "{{ user `token` }}", - "project": "{{ user `project` }}", - "type": "hyperone", - "source_image": "ubuntu", - "disk_size": 10, - "vm_type": "a1.nano", - "chroot_disk": true, - "chroot_command_wrapper": "sudo {{.Command}}", - "pre_mount_commands": [ - "parted {{.Device}} mklabel msdos mkpart primary 1M 100% set 1 boot on print", - "mkfs.ext4 {{.Device}}1" - ], - "post_mount_commands": [ - "apt-get update", - "apt-get install debootstrap", - "debootstrap --arch amd64 bionic {{.MountPath}}" - ], - "image_name": "packerbats-chroot-{{timestamp}}", - "image_tags": { - "key2":"value2" - } - }], - "provisioners": [] -} diff --git a/test/fixtures/builder-hyperone/minimal.json b/test/fixtures/builder-hyperone/minimal.json deleted file mode 100644 index eb5411de6..000000000 --- a/test/fixtures/builder-hyperone/minimal.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "variables": { - "token": null, - "project": null - }, - "builders": [{ - "token": "{{ user `token` }}", - "project": "{{ user `project` }}", - "type": "hyperone", - "source_image": "ubuntu", - "disk_size": 10, - "vm_type": "a1.nano", - "image_name": "packerbats-minimal-{{timestamp}}", - "image_tags": { - "key":"value" - } - }] -} diff --git a/test/fixtures/builder-hyperone/new-syntax.pkr.hcl b/test/fixtures/builder-hyperone/new-syntax.pkr.hcl deleted file mode 100644 index 14e8d7e6f..000000000 --- a/test/fixtures/builder-hyperone/new-syntax.pkr.hcl +++ /dev/null @@ -1,29 +0,0 @@ -variable "token" { - type = string -} - -variable "project" { - type = string -} - -source "hyperone" "new-syntax" { - token = var.token - project = var.project - source_image = "debian" - disk_size = 10 - vm_type = "a1.nano" - image_name = "packerbats-hcl-{{timestamp}}" - image_tags = { - key="value" - } -} - -build { - sources = [ - "source.hyperone.new-syntax" - ] - - provisioner "shell" { - inline = ["sleep 5"] - } -} \ No newline at end of file diff --git a/test/fixtures/builder-linode/minimal.json b/test/fixtures/builder-linode/minimal.json deleted file mode 100644 index 400cfa63a..000000000 --- a/test/fixtures/builder-linode/minimal.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "variables": { - "linode_token": "{{env `LINODE_TOKEN`}}" - }, - "builders": [ - { - "type": "linode", - "linode_token": "{{user `linode_token`}}", - - "region": "us-central", - "swap_size": 256, - "image": "linode/debian9", - "instance_type": "g6-nanode-1", - "instance_label": "packerbats-minimal-{{timestamp}}", - - "image_label": "packerbats-minimal-image-{{timestamp}}", - "image_description": "packerbats", - - "ssh_username": "root" - } - ], - "provisioners": [ - { - "type": "shell", - "inline": ["echo Hello > /root/message.txt"] - } - ] - } diff --git a/test/fixtures/builder-lxc/minimal.json b/test/fixtures/builder-lxc/minimal.json deleted file mode 100644 index 997e48cfd..000000000 --- a/test/fixtures/builder-lxc/minimal.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "variables": { - "template_name": "debian", - "template_parameters": "SUITE=jessie", - "container_name": "packer-lxc", - "set_var": "hello" - }, - "provisioners": [ - { - "type": "shell", - "inline": [ - "if [ \"$SET_VAR\" != \"{{user `set_var`}}\" ]; then", - " echo \"Got unexpected value '$SET_VAR' for SET_VAR\" 1>&2", - " exit 1", - "fi" - ] - } - ], - "builders": [ - { - "type": "lxc", - "name": "lxc-{{user `template_name`}}", - "template_name": "{{user `template_name`}}", - "container_name": "{{user `container_name`}}", - "create_options": [ "-f", "{{user `init_config`}}" ], - "attach_options": [ "--clear-env", "--set-var", "SET_VAR={{user `set_var`}}" ], - "config_file": "/usr/share/lxc/config/{{user `template_name`}}.common.conf", - "template_environment_vars": [ "{{user `template_parameters`}}" ] - } - ] -} diff --git a/test/fixtures/communicator-ssh/local-tunnel.json b/test/fixtures/communicator-ssh/local-tunnel.json deleted file mode 100644 index 2db4ebcac..000000000 --- a/test/fixtures/communicator-ssh/local-tunnel.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "builders": [{ - "type": "amazon-ebs", - "ami_name": "packer-test {{timestamp}}", - "instance_type": "m1.small", - "region": "us-east-1", - "ssh_username": "ubuntu", - "ssh_local_tunnels": ["10022:localhost:22"], - "source_ami": "ami-0568456c", - "tags": { - "packer-test": "true" - } - }], - - "provisioners": [{ - "type": "shell-local", - "inline": [ - "echo | nc -G 5 -w 5 -v localhost 10022 2>&1" - ] - }] -} diff --git a/test/fixtures/communicator-ssh/remote-tunnel.json b/test/fixtures/communicator-ssh/remote-tunnel.json deleted file mode 100644 index 8f69be84a..000000000 --- a/test/fixtures/communicator-ssh/remote-tunnel.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "builders": [{ - "type": "amazon-ebs", - "ami_name": "packer-test {{timestamp}}", - "instance_type": "t2.micro", - "region": "us-east-1", - "ssh_username": "ubuntu", - "ssh_remote_tunnels": ["8443:ifconfig.co:443"], - "source_ami": "ami-0111e8c43a763eb71", - "tags": { - "packer-test": "true" - } - }], - "provisioners": [{ - "inline": [ - "curl -kvs --connect-to ifconfig.co:443:localhost:8443 https://ifconfig.co/" - ], - "type": "shell" - } - ] - } - \ No newline at end of file diff --git a/test/fixtures/provisioner-file/dir/file.txt b/test/fixtures/provisioner-file/dir/file.txt deleted file mode 100644 index 806dddba5..000000000 --- a/test/fixtures/provisioner-file/dir/file.txt +++ /dev/null @@ -1 +0,0 @@ -337 miles diff --git a/test/fixtures/provisioner-file/dir_no_trailing.json b/test/fixtures/provisioner-file/dir_no_trailing.json deleted file mode 100644 index e48a2f160..000000000 --- a/test/fixtures/provisioner-file/dir_no_trailing.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "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_no_trailing_sftp.json b/test/fixtures/provisioner-file/dir_no_trailing_sftp.json deleted file mode 100644 index 283751698..000000000 --- a/test/fixtures/provisioner-file/dir_no_trailing_sftp.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "builders": [{ - "type": "amazon-ebs", - "ami_name": "packer-test {{timestamp}}", - "instance_type": "t2.micro", - "region": "us-east-1", - "ssh_username": "ec2-user", - "ssh_file_transfer_method": "sftp", - "source_ami": "ami-8da458e6", - "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 deleted file mode 100644 index bf5f75415..000000000 --- a/test/fixtures/provisioner-file/dir_with_trailing.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "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/dir_with_trailing_sftp.json b/test/fixtures/provisioner-file/dir_with_trailing_sftp.json deleted file mode 100644 index f26365434..000000000 --- a/test/fixtures/provisioner-file/dir_with_trailing_sftp.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "builders": [{ - "type": "amazon-ebs", - "ami_name": "packer-test {{timestamp}}", - "instance_type": "t2.micro", - "region": "us-east-1", - "ssh_username": "ec2-user", - "ssh_file_transfer_method": "sftp", - "source_ami": "ami-8da458e6", - "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 deleted file mode 100644 index e8287abb9..000000000 --- a/test/fixtures/provisioner-file/file.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "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 deleted file mode 100644 index e8a85b0cd..000000000 --- a/test/fixtures/provisioner-file/file.txt +++ /dev/null @@ -1 +0,0 @@ -24901 miles diff --git a/test/fixtures/provisioner-file/file_sftp.json b/test/fixtures/provisioner-file/file_sftp.json deleted file mode 100644 index 19a8a98b8..000000000 --- a/test/fixtures/provisioner-file/file_sftp.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "builders": [{ - "type": "amazon-ebs", - "ami_name": "packer-test {{timestamp}}", - "instance_type": "t2.micro", - "region": "us-east-1", - "ssh_username": "ec2-user", - "ssh_file_transfer_method": "sftp", - "source_ami": "ami-8da458e6", - "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-shell/inline.json b/test/fixtures/provisioner-shell/inline.json deleted file mode 100644 index 25afae166..000000000 --- a/test/fixtures/provisioner-shell/inline.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "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": "shell", - "inline": [ - "bash -c 'echo HELLO I AM `whoami`'", - "echo AND ANOTHER" - ] - }] -} diff --git a/test/fixtures/provisioner-shell/script.json b/test/fixtures/provisioner-shell/script.json deleted file mode 100644 index dc8ad509e..000000000 --- a/test/fixtures/provisioner-shell/script.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "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": "shell", - "script": "script.sh" - }] -} diff --git a/test/fixtures/provisioner-shell/script.sh b/test/fixtures/provisioner-shell/script.sh deleted file mode 100755 index e4e504ff9..000000000 --- a/test/fixtures/provisioner-shell/script.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -echo HELLO I AM DOG diff --git a/test/fixtures/provisioner-shell/scripts.json b/test/fixtures/provisioner-shell/scripts.json deleted file mode 100644 index 290c6f5ad..000000000 --- a/test/fixtures/provisioner-shell/scripts.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "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": "shell", - "scripts": [ - "script.sh" - ] - }] -} diff --git a/test/provisioner_file.bats b/test/provisioner_file.bats deleted file mode 100755 index 3c8469897..000000000 --- a/test/provisioner_file.bats +++ /dev/null @@ -1,53 +0,0 @@ -#!/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 -verify_aws_cli -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"* ]] -} - -@test "file provisioner: single file through sftp" { - run packer build $FIXTURE_ROOT/file_sftp.json - [ "$status" -eq 0 ] - [[ "$output" == *"24901 miles"* ]] -} - -@test "file provisioner: directory through sftp (no trailing slash)" { - run packer build $FIXTURE_ROOT/dir_no_trailing_sftp.json - [ "$status" -eq 0 ] - [[ "$output" == *"337 miles"* ]] -} - -@test "file provisioner: directory through sftp (with trailing slash)" { - run packer build $FIXTURE_ROOT/dir_with_trailing_sftp.json - [ "$status" -eq 0 ] - [[ "$output" == *"337 miles"* ]] -} diff --git a/test/provisioner_shell.bats b/test/provisioner_shell.bats deleted file mode 100755 index 016c209b0..000000000 --- a/test/provisioner_shell.bats +++ /dev/null @@ -1,36 +0,0 @@ -#!/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 -verify_aws_cli -fixtures provisioner-shell - -setup() { - cd $FIXTURE_ROOT -} - -teardown() { - aws_ami_cleanup -} - -@test "shell provisioner: inline scripts" { - run packer build $FIXTURE_ROOT/inline.json - [ "$status" -eq 0 ] - [[ "$output" == *"HELLO I AM ubuntu"* ]] - [[ "$output" == *"AND ANOTHER"* ]] -} - -@test "shell provisioner: script" { - run packer build $FIXTURE_ROOT/script.json - [ "$status" -eq 0 ] - [[ "$output" == *"HELLO I AM DOG"* ]] -} - -@test "shell provisioner: scripts" { - run packer build $FIXTURE_ROOT/scripts.json - [ "$status" -eq 0 ] - [[ "$output" == *"HELLO I AM DOG"* ]] -} diff --git a/test/test_helper.bash b/test/test_helper.bash deleted file mode 100644 index a9dbc38eb..000000000 --- a/test/test_helper.bash +++ /dev/null @@ -1,52 +0,0 @@ -# Let's verify that the tools we need are installed -verify_aws_cli() { - declare -a required=(aws) - for cmd in "${required[@]}"; do - command -v $cmd >/dev/null 2>&1 || { - echo "'$cmd' must be installed" >&2 - exit 1 - } - done -} - -#-------------------------------------------------------------------- -# Bats modification -#-------------------------------------------------------------------- -# This allows us to override a function in Bash -save_function() { - local ORIG_FUNC=$(declare -f $1) - local NEWNAME_FUNC="$2${ORIG_FUNC#$1}" - eval "$NEWNAME_FUNC" -} - -# Override the run function so that we always output the output -save_function run old_run -run() { - old_run $@ - - # Output the command we ran - echo "Executing: " $@ - - # "$output" gets rid of newlines. This will bring them back. - for line in "${lines[@]}"; do - echo $line - done -} - -#-------------------------------------------------------------------- -# Helper functions -#-------------------------------------------------------------------- -# This sets the directory for fixtures by specifying the name of -# the folder with fixtures. -fixtures() { - FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/$1" -} - -# This deletes any AMIs with a tag "packer-test" of "true" -aws_ami_cleanup() { - local region=${1:-us-east-1} - aws ec2 describe-images --region ${region} --owners self --output text \ - --filters 'Name=tag:packer-test,Values=true' \ - --query 'Images[*].ImageId' \ - | xargs -n1 aws ec2 deregister-image --region ${region} --image-id -}