--- /dev/null
+#!/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" ]
+}