2013-12-14 14:27:50 -05:00
|
|
|
#!/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
|
2014-11-17 13:06:22 -05:00
|
|
|
: ${GC_ACCOUNT_FILE:?}
|
2013-12-14 14:27:50 -05:00
|
|
|
: ${GC_PROJECT_ID:?}
|
2016-07-30 02:12:41 -04:00
|
|
|
command -v gcloud >/dev/null 2>&1 || {
|
|
|
|
echo "'gcloud' must be installed" >&2
|
2013-12-14 14:27:50 -05:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2014-11-17 13:06:22 -05:00
|
|
|
USER_VARS="${USER_VARS} -var account_file=${GC_ACCOUNT_FILE}"
|
2013-12-14 14:27:50 -05:00
|
|
|
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() {
|
2016-07-30 02:12:41 -04:00
|
|
|
gcloud compute --format='table[no-heading](name)' --project=${GC_PROJECT_ID} images list \
|
2013-12-14 14:40:27 -05:00
|
|
|
| grep $1 | wc -l
|
2013-12-14 14:27:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
2016-07-30 02:12:41 -04:00
|
|
|
gcloud compute --format='table[no-heading](name)' --project=${GC_PROJECT_ID} images list \
|
2013-12-14 14:27:50 -05:00
|
|
|
| grep packerbats \
|
2016-07-30 02:12:41 -04:00
|
|
|
| xargs -n1 gcloud compute --project=${GC_PROJECT_ID} images delete
|
2013-12-14 14:27:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "googlecompute: build minimal.json" {
|
|
|
|
run packer build ${USER_VARS} $FIXTURE_ROOT/minimal.json
|
|
|
|
[ "$status" -eq 0 ]
|
2013-12-14 14:40:27 -05:00
|
|
|
[ "$(gc_has_image "packerbats-minimal")" -eq 1 ]
|
2013-12-14 14:27:50 -05:00
|
|
|
}
|