github.com/daniellockard/packer@v0.7.6-0.20141210173435-5a9390934716/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_BUCKET_NAME:?} 11 : ${GC_ACCOUNT_FILE:?} 12 : ${GC_PROJECT_ID:?} 13 command -v gcutil >/dev/null 2>&1 || { 14 echo "'gcutil' must be installed" >&2 15 exit 1 16 } 17 18 USER_VARS="-var bucket_name=${GC_BUCKET_NAME}" 19 USER_VARS="${USER_VARS} -var account_file=${GC_ACCOUNT_FILE}" 20 USER_VARS="${USER_VARS} -var project_id=${GC_PROJECT_ID}" 21 22 # This tests if GCE has an image that contains the given parameter. 23 gc_has_image() { 24 gcutil --format=names --project=${GC_PROJECT_ID} listimages \ 25 | grep $1 | wc -l 26 } 27 28 teardown() { 29 gcutil --format=names --project=${GC_PROJECT_ID} listimages \ 30 | grep packerbats \ 31 | xargs -n1 gcutil --project=${GC_PROJECT_ID} deleteimage --force 32 } 33 34 @test "googlecompute: build minimal.json" { 35 run packer build ${USER_VARS} $FIXTURE_ROOT/minimal.json 36 [ "$status" -eq 0 ] 37 [ "$(gc_has_image "packerbats-minimal")" -eq 1 ] 38 }