Add sr conversions functions to tsp/common.sh 97/88797/6
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Tue, 20 Sep 2016 11:28:41 +0000 (13:28 +0200)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Tue, 3 Jan 2017 15:13:57 +0000 (16:13 +0100)
Add project2sr() and url2sr() to tsp/common.sh
Add tests of url2sr function to test/tct_common.bats

Change-Id: Ib4ecc900f0791578ab13110a28e63d634234f86d
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
test/tsp_common.bats [new file with mode: 0755]
tsp/common.sh

diff --git a/test/tsp_common.bats b/test/tsp_common.bats
new file mode 100755 (executable)
index 0000000..47b8605
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/env bats
+
+. ./tsp/common.sh
+
+@test "url2sr: no args" {
+    RES1="$(url2sr 2>&1)" || RES2="$?"
+    [ -n "$RES1" ]
+    [ "$RES2" -ne 0 ]
+}
+
+@test "url2sr: pre_url" {
+    RES1="$(url2sr http://download.tizen.org/prerelease/tizen/common/tizen-common_20160613.3/tizen-common_20160613.3.20160614.075200/ 2>&1)"
+    [ "$RES1" = "tizen-common_20160613.3.20160614.075200" ]
+}
+
+@test "url2sr: snap_url" {
+    RES1="$(url2sr http://download.tizen.org/snapshots/tizen/common/tizen-common_20160909.2/ 2>&1)"
+    [ "$RES1" = "tizen-common_20160909.2" ]
+}
index 0be6bbd..18f8057 100755 (executable)
@@ -59,3 +59,17 @@ tsrun_target() {
     shift
     TMPDIR="$TMPDIR" TS_SLOTS=1 tsp $@
 }
+
+url2sr() {
+    URL="$1"
+    test -n "$URL" || die "Missing argument: url"
+    RET="${URL%/}"
+    RET="${RET##*/}"
+    echo "$RET"
+}
+
+project2sr() {
+    PROJECT_FILE="$1"
+    test -n "$PROJECT_FILE" || die "Missing argument: project_file"
+    head -n 1 "${PROJECT_FILE}" | tr -d '\n'
+}