1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
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
|