From 42212d41b0fe9f86c20b65b415fa8ddd319d6e85 Mon Sep 17 00:00:00 2001 From: Flavio Castelli Date: Fri, 3 Mar 2017 21:22:44 +0100 Subject: Test coverage for pool sync --- libvirt/pool_sync_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 libvirt/pool_sync_test.go diff --git a/libvirt/pool_sync_test.go b/libvirt/pool_sync_test.go new file mode 100644 index 00000000..630ae2a4 --- /dev/null +++ b/libvirt/pool_sync_test.go @@ -0,0 +1,46 @@ +package libvirt + +import ( + "testing" +) + +func TestAcquireLock(t *testing.T) { + ps := NewLibVirtPoolSync() + + ps.AcquireLock("test") + + _, found := ps.PoolLocks["test"] + + if !found { + t.Errorf("lock not found") + } +} + +func TestReleaseLock(t *testing.T) { + ps := NewLibVirtPoolSync() + + ps.AcquireLock("test") + + _, found := ps.PoolLocks["test"] + if !found { + t.Errorf("lock not found") + } + + ps.ReleaseLock("test") + _, found = ps.PoolLocks["test"] + if !found { + t.Errorf("lock not found") + } +} + +func TestReleaseNotExistingLock(t *testing.T) { + ps := NewLibVirtPoolSync() + + ps.ReleaseLock("test") + _, found := ps.PoolLocks["test"] + if found { + t.Errorf("lock found") + } + // moreover there should be no runtime error because + // we are not trying to unlock a not-locked mutex +} -- cgit v1.2.3