github.com/angdraug/packer@v1.3.2/test/builder_googlecompute.bats (about) 1 #!/usr/bin/env bats 2 # 3 # This tests the googlecompute builder. The teardown function will 4 # delete any images with the text "packerbats" within the name. 5 6 load test_helper 7 fixtures builder-googlecompute 8 9 # Required parameters 10 : ${GC_ACCOUNT_FILE:?} 11 : ${GC_PROJECT_ID:?} 12 command -v gcloud >/dev/null 2>&1 || { 13 echo "'gcloud' must be installed" >&2 14 exit 1 15 } 16 17 USER_VARS="${USER_VARS} -var account_file=${GC_ACCOUNT_FILE}" 18 USER_VARS="${USER_VARS} -var project_id=${GC_PROJECT_ID}" 19 20 # This tests if GCE has an image that contains the given parameter. 21 gc_has_image() { 22 gcloud compute --format='table[no-heading](name)' --project=${GC_PROJECT_ID} images list \ 23 | grep $1 | wc -l 24 } 25 26 teardown() { 27 gcloud compute --format='table[no-heading](name)' --project=${GC_PROJECT_ID} images list \ 28 | grep packerbats \ 29 | xargs -n1 gcloud compute --project=${GC_PROJECT_ID} images delete 30 } 31 32 @test "googlecompute: build minimal.json" { 33 run packer build ${USER_VARS} $FIXTURE_ROOT/minimal.json 34 [ "$status" -eq 0 ] 35 [ "$(gc_has_image "packerbats-minimal")" -eq 1 ] 36 }