| 1 | # SPDX-FileCopyrightText: Copyright The Lima Authors |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | load "../helpers/load" |
| 5 | |
| 6 | INSTANCE=bats-dummy |
| 7 | CLONE=clone |
| 8 | NOTEXIST=notexist |
| 9 | |
| 10 | local_setup_file() { |
| 11 | local inst |
| 12 | for inst in "$CLONE" "$NOTEXIST"; do |
| 13 | limactl unprotect "$inst" || : |
| 14 | limactl delete --force "$inst" || : |
| 15 | done |
| 16 | } |
| 17 | |
| 18 | @test 'protecting a non-existing instance fails' { |
| 19 | run_e -1 limactl protect "${NOTEXIST}" |
| 20 | assert_fatal "failed to inspect instance \`${NOTEXIST}\`…" |
| 21 | } |
| 22 | |
| 23 | @test 'protecting the dummy instance succeeds' { |
| 24 | run_e -0 limactl protect "$INSTANCE" |
| 25 | assert_info "Protected \`${INSTANCE}\`" |
| 26 | assert_file_exists "${LIMA_HOME}/${INSTANCE}/protected" |
| 27 | } |
| 28 | |
| 29 | @test 'protecting it again shows a warning, but succeeds' { |
| 30 | run_e -0 limactl protect "$INSTANCE" |
| 31 | assert_warning "Instance \`${INSTANCE}\` is already protected. Skipping." |
| 32 | assert_file_exists "${LIMA_HOME}/${INSTANCE}/protected" |
| 33 | } |
| 34 | |
| 35 | @test 'cloning a protected instance creates an unprotected clone' { |
| 36 | run_e -0 limactl clone --yes "$INSTANCE" "$CLONE" |
| 37 | # TODO there is currently no output from the clone command, which feels wrong |
| 38 | refute_output |
| 39 | assert_file_not_exists "${LIMA_HOME}/${CLONE}/protected" |
| 40 | } |
| 41 | |
| 42 | @test 'deleting the unprotected clone instance succeeds' { |
| 43 | run_e -0 limactl delete --force "$CLONE" |
| 44 | assert_info "Deleted \`${CLONE}\`…" |
| 45 | } |
| 46 | |
| 47 | @test 'deleting protected dummy instance fails' { |
| 48 | run_e -1 limactl delete --force "$INSTANCE" |
| 49 | assert_fatal "failed to delete instance \`${INSTANCE}\`: instance is protected…" |
| 50 | assert_file_exists "$LIMA_HOME/$INSTANCE/protected" |
| 51 | } |
| 52 | |
| 53 | @test 'unprotecting the dummy instance succeeds' { |
| 54 | run_e -0 limactl unprotect "$INSTANCE" |
| 55 | assert_info "Unprotected \`${INSTANCE}\`" |
| 56 | assert_file_not_exists "$LIMA_HOME/$INSTANCE/protected" |
| 57 | } |
| 58 | |
| 59 | @test 'unprotecting it again shows a warning, but succeeds' { |
| 60 | run_e -0 limactl unprotect "$INSTANCE" |
| 61 | assert_warning "Instance \`${INSTANCE}\` isn't protected. Skipping." |
| 62 | assert_file_not_exists "$LIMA_HOME/$INSTANCE/protected" |
| 63 | } |
| 64 | |
| 65 | @test 'deleting unprotected dummy instance succeeds' { |
| 66 | run_e -0 limactl delete --force "$INSTANCE" |
| 67 | assert_info "Deleted \`${INSTANCE}\`…" |
| 68 | } |