Skip to content
This repository has been archived by the owner on Feb 14, 2021. It is now read-only.

Commit

Permalink
Add support for apk
Browse files Browse the repository at this point in the history
Supports status, install, upgrade and delete actions.

Closes #103
  • Loading branch information
jitakirin authored and mattly committed Jan 26, 2018
1 parent fd71a70 commit 1a18e18
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/fixtures/apk-version.txt
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
57 changes: 57 additions & 0 deletions test/type-apk.bats
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' ]]
}
27 changes: 27 additions & 0 deletions types/apk.sh
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

0 comments on commit 1a18e18

Please sign in to comment.