This repository has been archived by the owner on Feb 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supports status, install, upgrade and delete actions. Closes #103
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Installed: Available: | ||
apk-tools-2.8.1-r1 < 2.8.1-r2 | ||
outdated_package-1.1.0-r1 < 1.2.0-r1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env bats | ||
|
||
. test/helpers.sh | ||
|
||
apk() { . $BORK_SOURCE_DIR/types/apk.sh "$@"; } | ||
|
||
@test "apk status returns FAILED_PRECONDITION when apk is missing" { | ||
respond_to 'which apk' 'return 1' | ||
run apk status something | ||
echo "# status: ${status}" | ||
echo '# output:'; echo "${output}" | sed -re 's/^/# /' | ||
(( status == STATUS_FAILED_PRECONDITION )) | ||
} | ||
|
||
@test "apk status returns MISSING when package is not installed" { | ||
respond_to 'apk info --installed missing_package_is_missing' \ | ||
'return 1' | ||
|
||
run apk status missing_package_is_missing | ||
(( status == STATUS_MISSING )) | ||
} | ||
|
||
@test "apk status returns OK when packge is installed and current" { | ||
respond_to 'apk info --installed current_package' \ | ||
'echo current_package' | ||
|
||
run apk status current_package | ||
(( status == STATUS_OK )) | ||
} | ||
|
||
@test "apk status returns OUTDATED when package is installed but outdated" { | ||
respond_to "apk version" "cat ${fixtures}/apk-version.txt" | ||
|
||
run apk status outdated_package | ||
(( status == STATUS_OUTDATED )) | ||
} | ||
|
||
@test "apk install runs 'add pkg'" { | ||
run apk install missing_package_is_missing | ||
(( status == 0 )) | ||
run baked_output | ||
[[ ${output} == 'sudo apk add missing_package_is_missing' ]] | ||
} | ||
|
||
@test "apk upgrade runs 'add pkg'" { | ||
run apk upgrade outdated_package | ||
(( status == 0 )) | ||
run baked_output | ||
[[ ${output} == 'sudo apk add outdated_package' ]] | ||
} | ||
|
||
@test "apk delete runs 'del pkg'" { | ||
run apk delete current_package | ||
(( status == 0 )) | ||
run baked_output | ||
[[ ${output} == 'sudo apk del current_package' ]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
action=$1 | ||
name=$2 | ||
shift 2 | ||
|
||
case "${action}" in | ||
desc) | ||
printf '%s\n' \ | ||
'asserts presence of packages installed via apk (Alpine Package Manager)' \ | ||
'* apk packge-name (install/upgrade given package)' | ||
;; | ||
status) | ||
needs_exec "apk" || return "${STATUS_FAILED_PRECONDITION}" | ||
|
||
bake apk info --installed "${name}" || return "${STATUS_MISSING}" | ||
! bake apk version | egrep "^${name}-\d" || return "${STATUS_OUTDATED}" | ||
return "${STATUS_OK}" | ||
;; | ||
install|upgrade) | ||
bake sudo apk add "${name}" | ||
;; | ||
delete) | ||
bake sudo apk del "${name}" | ||
;; | ||
*) return 1 ;; | ||
esac |