1
// -*- Mode: Go; indent-tabs-mode: t -*-
4
* Copyright (C) 2014-2015 Canonical Ltd
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 3 as
8
* published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
25
"launchpad.net/snappy/helpers"
30
type FileLockTestSuite struct {
33
var _ = Suite(&FileLockTestSuite{})
35
func (ts *FileLockTestSuite) TestFileLock(c *C) {
36
lockfile := filepath.Join(c.MkDir(), "lock")
38
c.Assert(helpers.FileExists(lockfile), Equals, false)
40
lock := NewFileLock(lockfile)
41
c.Assert(lock, Not(IsNil))
42
c.Assert(lock.Filename, Equals, lockfile)
43
c.Assert(lock.realFile, IsNil)
46
c.Assert(err, Equals, ErrNotLocked)
48
// can only test non-blocking in a single process.
49
err = lock.Lock(false)
52
c.Assert(helpers.FileExists(lockfile), Equals, true)
53
c.Assert(lock.Filename, Equals, lockfile)
54
c.Assert(lock.realFile, Not(IsNil))
56
err = lock.Lock(false)
57
c.Assert(err, Equals, ErrAlreadyLocked)
62
c.Assert(helpers.FileExists(lockfile), Equals, false)
63
c.Assert(lock.Filename, Equals, "")
64
c.Assert(lock.realFile, IsNil)