Skip to content

Commit

Permalink
add tests for the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
bcumming committed Sep 30, 2024
1 parent 92f4afe commit d976849
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cli/repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ int repo_create(const repo_create_args& args, const global_settings& settings) {
auto x = create_repository(*path);
if (!x) {
spdlog::error("{}", x.error());
return 1;
}
return 0;
}
Expand Down
155 changes: 155 additions & 0 deletions test/integration/cli.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
function setup() {
bats_install_path=$(realpath ./install)
export BATS_LIB_PATH=$bats_install_path/bats-helpers

bats_load_library bats-support
bats_load_library bats-assert
load ./common

export REPOS=$(realpath ../scratch/repos)
export SQFS_LIB=$(realpath ../scratch/sqfs)

export SRC_PATH=$(realpath ../../)

export PATH="$(realpath ../../install/bin):$PATH"

unset UENV_MOUNT_LIST

# set up location for creation of working repos
export REPO_ROOT=/tmp/uenv-repo
rm -rf $REPO_ROOT
mkdir -p $REPO_ROOT
}

function teardown() {
:
}

@test "noargs" {
run uenv
assert_output --partial "uenv version $(cat $SRC_PATH/VERSION)"
assert_success
}

@test "--version" {
run uenv --version
assert_output "$(cat $SRC_PATH/VERSION)"
assert_success
}

@test "image ls" {
export UENV_REPO_PATH=$REPOS/apptool

run uenv image ls
assert_success
assert_line --index 0 --regexp "^uenv\s+arch\s+system\s+id"
assert_output --regexp "app/42.0:v1\s+zen3\s+arapiles"
assert_output --regexp "app/43.0:v1\s+zen3\s+arapiles"
assert_output --regexp "tool/17.3.2:v1\s+zen3\s+arapiles"

run uenv image ls --no-header
assert_success
refute_line --regexp "^uenv\s+arch\s+system\s+id"
assert_line --regexp "app/42.0:v1\s+zen3\s+arapiles"
assert_line --regexp "app/43.0:v1\s+zen3\s+arapiles"
assert_line --regexp "tool/17.3.2:v1\s+zen3\s+arapiles"

run uenv image ls --no-header app
assert_success
assert_line --partial "app/42.0:v1"
assert_line --partial "app/43.0:v1"
refute_line --partial "tool/17.3.2:v1"

run uenv image ls --no-header app/43.0
assert_success
refute_line --partial "app/42.0:v1"
assert_line --partial "app/43.0:v1"
refute_line --partial "tool/17.3.2:v1"

run uenv image ls --no-header tool
assert_success
refute_line --partial "app/42.0:v1"
refute_line --partial "app/43.0:v1"
assert_line --partial "tool/17.3.2:v1"

run uenv image ls wombat
assert_success
assert_output "no matching uenv"

# empty output if --no-header is used and there are no matches
run uenv image ls wombat --no-header
assert_success
assert_output ""

# unset the UENV_REPO_PATH variable and use the --repo flag instead
unset UENV_REPO_PATH=$REPOS/apptool

run uenv --repo=/wombat image ls --no-header
assert_failure
assert_output --partial "the repository /wombat does not exist"

run uenv --repo=$REPOS/apptool image ls --no-header
assert_success
assert_line --partial "app/42.0:v1"
assert_line --partial "app/43.0:v1"
assert_line --partial "tool/17.3.2:v1"
}

@test "repo status" {
export RP=$REPOS/apptool

#
# check the different methods for providing the repo location
#

# using UENV_REPO_PATH env variable
UENV_REPO_PATH=$RP run uenv repo status
assert_success
assert_line --index 0 "the repository at $RP is read-write"

# using --repo flag to uenv
run uenv --repo=$RP repo status
assert_success
assert_line --index 0 "the repository at $RP is read-write"

# as a positional argument to the repo status command itself
run uenv repo status $RP
assert_success
assert_line --index 0 "the repository at $RP is read-write"

# no error for a path that does not exist
run uenv repo status /wombat
assert_success
assert_line --index 0 "no repository at /wombat"

# TODO:
# - check a read-only repo
# - check an invalid repo
}

@test "repo create" {
# using UENV_REPO_PATH env variable
RP=$(mktemp -d $REPO_ROOT/create-XXXXXX)
run uenv repo create $RP
assert_success
assert [ -d $RP ]
assert [ -e $RP/index.db ]
run sqlite3 $RP/index.db .dump
assert_line --partial "CREATE TABLE images"
assert_line --partial "CREATE TABLE uenv"
assert_line --partial "CREATE TABLE tags"
assert_line --partial "CREATE VIEW records AS"

# create a repo in the same location
# this should be an error
run uenv repo create $RP
assert_failure
assert_line --partial "unable to create repository"

# try to create a uenv in a read-only path
RP=$REPO_ROOT/ro
mkdir --mode=-w $RP
run uenv repo create $RP/test
assert_failure
assert_line --partial "Permission denied"
}

0 comments on commit d976849

Please sign in to comment.