-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test that a failed file lock closes the file
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2015 Tim Heckman. All rights reserved. | ||
// Copyright 2018 The Gofrs. All rights reserved. | ||
// Use of this source code is governed by the BSD 3-Clause | ||
// license that can be found in the LICENSE file. | ||
|
||
package flock | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func Test(t *testing.T) { | ||
tmpFileFh, err := ioutil.TempFile(os.TempDir(), "go-flock-") | ||
tmpFileFh.Close() | ||
tmpFile := tmpFileFh.Name() | ||
os.Remove(tmpFile) | ||
|
||
lock := New(tmpFile) | ||
locked, err := lock.TryLock() | ||
if locked == false || err != nil { | ||
t.Fatal("failed to lock") | ||
} | ||
|
||
newLock := New(tmpFile) | ||
locked, err = newLock.TryLock() | ||
if locked != false || err != nil { | ||
t.Fatal("should have failed locking") | ||
} | ||
|
||
if newLock.fh != nil { | ||
t.Fatal("file handle should have been released and be nil") | ||
} | ||
} |