Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: apk support #2

Merged
merged 17 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ and some basic information about their usage and options.
### Linux specific:
```
apt: asserts packages installed via apt-get on Debian or Ubuntu Linux
apk: asserts packages installed via apk (Alpine Linux)
yum: asserts packages installed via yum on CentOS or RedHat Linux
```

Expand Down
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
(( 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
echo "$output"
(( 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
echo "$output"
(( 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' ]]
}
28 changes: 28 additions & 0 deletions types/apk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/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}"
version=$(bake apk version)
str_matches "$version" "^${name}-[0-9]+\.[0-9]+" && return "${STATUS_OUTDATED}"
return "${STATUS_OK}"
;;
install|upgrade)
bake sudo apk add "${name}"
;;
delete)
bake sudo apk del "${name}"
;;
*) return 1 ;;
esac