File: builder_hyperone.bats

package info (click to toggle)
packer 1.6.6%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 33,156 kB
  • sloc: sh: 1,154; python: 619; makefile: 251; ruby: 205; xml: 97
file content (48 lines) | stat: -rwxr-xr-x 1,436 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/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 ]
}