Add test/resource_locking.py.bats 66/79766/15
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Tue, 12 Jul 2016 16:31:35 +0000 (18:31 +0200)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Tue, 6 Dec 2016 15:37:13 +0000 (16:37 +0100)
Change-Id: I7ea1e13702ea17488da6c2c0424db1283d7f4db2
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
test/resource_locking.py.bats [new file with mode: 0755]

diff --git a/test/resource_locking.py.bats b/test/resource_locking.py.bats
new file mode 100755 (executable)
index 0000000..27aa416
--- /dev/null
@@ -0,0 +1,89 @@
+#!/usr/bin/env bats
+
+teardown() {
+    test -z "`ls /var/tmp/uuid-foo* 2>/dev/null`" || rm /var/tmp/uuid-foo* 2>/dev/null
+}
+
+@test "no arguments" {
+    RES="`python tct/resource_locking.py 2>&1`" || RET="$?"
+    [ "$RET" -ne 0 ]
+    [ -n "$RES" ]
+}
+
+@test "missing argument" {
+    RES="`python tct/resource_locking.py --lock 2>&1`" || RET="$?"
+    [ -n "$RES" ]
+}
+
+@test "wrong arguments" {
+    RES="`python tct/resource_locking.py -qwe 2>&1`" || RET="$?"
+    [ -n "$RES" ]
+}
+
+@test "lock" {
+    touch /var/tmp/uuid-foo_1
+    RES="`python tct/resource_locking.py --lock foo`"
+    [ "$RES" = "foo_1" ]
+}
+
+@test "retrylock" {
+    touch /var/tmp/uuid-foo_1
+    RES="`python tct/resource_locking.py --retrylock foo`"
+    [ "$RES" = "foo_1" ]
+}
+
+@test "lock_twice" {
+    touch /var/tmp/uuid-foo_1
+    RES="`python tct/resource_locking.py --lock foo`"
+    [ "$RES" = "foo_1" ]
+    RES="`python tct/resource_locking.py --lock foo`"
+    [ -z "$RES" ]
+}
+
+@test "lock_unlock" {
+    touch /var/tmp/uuid-foo_1
+    RES="`python tct/resource_locking.py --lock foo`"
+    [ "$RES" = "foo_1" ]
+    RES="`python tct/resource_locking.py --unlock foo_1`"
+    [ -z "$RES" ]
+}
+
+@test "lock_order" {
+    touch /var/tmp/uuid-foo_1
+    touch /var/tmp/uuid-foo_2
+    touch /var/tmp/uuid-foo_3
+    echo 3 > /var/tmp/uuid-foo_1.cnt
+    echo 1 > /var/tmp/uuid-foo_2.cnt
+    echo 2 > /var/tmp/uuid-foo_3.cnt
+    RES="`python tct/resource_locking.py --lock foo`"
+    [ "$RES" = "foo_2" ]
+    RES="`python tct/resource_locking.py --lock foo`"
+    [ "$RES" = "foo_3" ]
+    RES="`python tct/resource_locking.py --lock foo`"
+    [ "$RES" = "foo_1" ]
+    RES="`python tct/resource_locking.py --lock foo`"
+    [ -z "$RES" ]
+}
+
+@test "lock_unlockfailed" {
+    touch /var/tmp/uuid-foo_1
+    RES="`python tct/resource_locking.py --lock foo`"
+    [ "$RES" = "foo_1" ]
+    RES="`python tct/resource_locking.py --unlockfailed foo_1`"
+    [ -z "$RES" ]
+    [ "`cat /var/tmp/uuid-foo_1.cnt`" = "11" ]
+}
+
+@test "lock_unlockfailed_with_inc" {
+    touch /var/tmp/uuid-foo_1
+    RES="`python tct/resource_locking.py --lock foo`"
+    [ "$RES" = "foo_1" ]
+    RES="`python tct/resource_locking.py --unlockfailed foo_1 --inc 666`"
+    [ -z "$RES" ]
+    [ "`cat /var/tmp/uuid-foo_1.cnt`" = "667" ]
+}
+
+@test "retrylock_empty" {
+    RES="`python tct/resource_locking.py --retrylock foobar 2>&1`" || RET="$?"
+    [ -n "$RES" ]
+}