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