diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-07-03 15:58:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-03 15:58:26 +0200 |
commit | a22a32a0a5507811168e0251a92122cf3e74ef51 (patch) | |
tree | 28f9cd8cfb7b45bf94e5c84b0cb19136c95c6749 /libpod/lock/file/file_lock_test.go | |
parent | bf7d5a9ce8455e4480b5e0ef92b02099f119ee71 (diff) | |
parent | 473d0604546ef472f167ee671fdf1110bf74eb63 (diff) | |
download | podman-a22a32a0a5507811168e0251a92122cf3e74ef51.tar.gz podman-a22a32a0a5507811168e0251a92122cf3e74ef51.tar.bz2 podman-a22a32a0a5507811168e0251a92122cf3e74ef51.zip |
Merge pull request #3437 from giuseppe/fix-nocgo
build: allow to build without cgo on RISC-V
Diffstat (limited to 'libpod/lock/file/file_lock_test.go')
-rw-r--r-- | libpod/lock/file/file_lock_test.go | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/libpod/lock/file/file_lock_test.go b/libpod/lock/file/file_lock_test.go new file mode 100644 index 000000000..6320d6b70 --- /dev/null +++ b/libpod/lock/file/file_lock_test.go @@ -0,0 +1,74 @@ +package file + +import ( + "fmt" + "io/ioutil" + "os" + "os/exec" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +// Test that creating and destroying locks work +func TestCreateAndDeallocate(t *testing.T) { + d, err := ioutil.TempDir("", "filelock") + assert.NoError(t, err) + defer os.RemoveAll(d) + + l, err := OpenFileLock(filepath.Join(d, "locks")) + assert.Error(t, err) + + l, err = CreateFileLock(filepath.Join(d, "locks")) + assert.NoError(t, err) + + lock, err := l.AllocateLock() + assert.NoError(t, err) + + err = l.AllocateGivenLock(lock) + assert.Error(t, err) + + err = l.DeallocateLock(lock) + assert.NoError(t, err) + + err = l.AllocateGivenLock(lock) + assert.NoError(t, err) + + err = l.DeallocateAllLocks() + assert.NoError(t, err) + + err = l.AllocateGivenLock(lock) + assert.NoError(t, err) + + err = l.DeallocateAllLocks() + assert.NoError(t, err) +} + +// Test that creating and destroying locks work +func TestLockAndUnlock(t *testing.T) { + d, err := ioutil.TempDir("", "filelock") + assert.NoError(t, err) + defer os.RemoveAll(d) + + l, err := CreateFileLock(filepath.Join(d, "locks")) + assert.NoError(t, err) + + lock, err := l.AllocateLock() + assert.NoError(t, err) + + err = l.LockFileLock(lock) + assert.NoError(t, err) + + lslocks, err := exec.LookPath("lslocks") + if err == nil { + lockPath := l.getLockPath(lock) + out, err := exec.Command(lslocks, "--json", "-p", fmt.Sprintf("%d", os.Getpid())).CombinedOutput() + assert.NoError(t, err) + + assert.Contains(t, string(out), lockPath) + } + + err = l.UnlockFileLock(lock) + assert.NoError(t, err) +} |