1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-24 03:35:38 +03:00
aports/testing/apt-dater-host/add-some-unit-tests-called-via-make-check.patch

95 lines
2 KiB
Diff

From a52c54d9b918f7683315e5206fd5e8d62f36b589 Mon Sep 17 00:00:00 2001
From: Henrik Riomar <henrik.riomar@gmail.com>
Date: Wed, 15 Mar 2017 06:38:05 +0100
Subject: [PATCH] apk: add some unit tests, called via "make check"
Upstream-Issue: https://github.com/DE-IBH/apt-dater-host/pull/19
---
apk/Makefile | 3 +++
apk/apt-dater-host | 6 +++++-
apk/test-apt-dater-host | 36 ++++++++++++++++++++++++++++++++++++
3 files changed, 44 insertions(+), 1 deletion(-)
create mode 100755 apk/test-apt-dater-host
diff --git a/apk/Makefile b/apk/Makefile
index 227f366..dfe7d9e 100644
--- a/apk/Makefile
+++ b/apk/Makefile
@@ -1,5 +1,8 @@
clean:
+check:
+ ./test-apt-dater-host
+
install:
install -D -m0755 apt-dater-host \
$(DESTDIR)/usr/bin/apt-dater-host
diff --git a/apk/apt-dater-host b/apk/apt-dater-host
index 2164dea..e0c9b65 100755
--- a/apk/apt-dater-host
+++ b/apk/apt-dater-host
@@ -10,7 +10,7 @@
# Henrik Riomar <henrik.riomar@gmail.com>
#
# Copyright Holder:
-# 2016 (C) Henrik Riomar
+# 2016,2017 (C) Henrik Riomar
#
# License:
# This program is free software; you can redistribute it and/or modify
@@ -212,6 +212,10 @@ case "$1" in
get_kern
;;
+ source-only)
+ # do nothing (used for unit testing)
+ ;;
+
*)
echo Invalid command \'$1\'\!
exit $err
diff --git a/apk/test-apt-dater-host b/apk/test-apt-dater-host
new file mode 100755
index 0000000..eef6d2b
--- /dev/null
+++ b/apk/test-apt-dater-host
@@ -0,0 +1,36 @@
+#!/usr/bin/env bats
+
+source ./apt-dater-host source-only
+
+check_tag()
+{
+ TAG=$1
+ STR=$2
+ [ $(echo $STR | grep -E -v -c "^$TAG:") -eq 0 ]
+}
+
+@test "say_hi()" {
+ result="$(say_hi)"
+ check_tag ADPROTO $result
+ [ "$result" = "ADPROTO: 0.6" ]
+}
+
+@test "get_lsbrel()" {
+ result="$(get_lsbrel)"
+ check_tag LSBREL $result
+}
+
+@test "get_pkg_stat()" {
+ result="$(get_pkg_stat)"
+ check_tag STATUS $result
+}
+
+@test "get_virt()" {
+ result="$(get_virt)"
+ check_tag VIRT $result
+}
+
+@test "get_kern()" {
+ result="$(get_kern)"
+ check_tag KERNELINFO $result
+}
--
2.11.1