| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | create_dummy_instance() { |
| 7 | local name=$1 |
| 8 | local expr=${2:-} |
| 9 | |
| 10 | |
| 11 | local template="{images: [location: /etc/profile]}" |
| 12 | if [[ -n $expr ]]; then |
| 13 | template="$(limactl yq "$expr" <<<"$template")" |
| 14 | fi |
| 15 | limactl create --name "$name" - <<<"$template" |
| 16 | } |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | ensure_instance() { |
| 23 | local instance=$1 |
| 24 | if [[ -n "${LIMA_BATS_REUSE_INSTANCE:-}" ]]; then |
| 25 | run limactl list --format '{{.Status}}' "$instance" |
| 26 | [[ $status == 0 ]] && [[ $output == "Running" ]] && return |
| 27 | fi |
| 28 | limactl unprotect "$instance" || : |
| 29 | limactl delete --force "$instance" || : |
| 30 | case "$instance" in |
| 31 | bats) limactl start --yes --name "$instance" template:default 3>&- 4>&- ;; |
| 32 | bats-nomount) limactl start --yes --name "$instance" --mount-none template:default 3>&- 4>&- ;; |
| 33 | bats-dummy) create_dummy_instance "$instance" '.disk = "1M"' ;; |
| 34 | *) |
| 35 | echo "ensure_instance: unknown instance name '$instance'" >&2 |
| 36 | return 1 |
| 37 | ;; |
| 38 | esac |
| 39 | } |
| 40 | |
| 41 | |
| 42 | delete_instance() { |
| 43 | local instance=$1 |
| 44 | if [[ -z "${LIMA_BATS_REUSE_INSTANCE:-}" ]]; then |
| 45 | limactl unprotect "$instance" || : |
| 46 | limactl delete --force "$instance" || : |
| 47 | fi |
| 48 | } |