Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jacobsa-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
jacobsa-fuse
Commits
d6e247cc
Commit
d6e247cc
authored
Aug 11, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed several mtime assertions.
parent
a6dd3d21
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
17 deletions
+24
-17
fusetesting/stat.go
fusetesting/stat.go
+15
-11
samples/memfs/memfs_test.go
samples/memfs/memfs_test.go
+9
-6
No files found.
fusetesting/stat.go
View file @
d6e247cc
...
...
@@ -28,28 +28,32 @@ import (
// also that it matches.
func
MtimeIs
(
expected
time
.
Time
)
oglematchers
.
Matcher
{
return
oglematchers
.
NewMatcher
(
func
(
c
interface
{})
error
{
return
mtimeIs
(
c
,
expected
)
},
func
(
c
interface
{})
error
{
return
mtimeIs
Within
(
c
,
expected
,
0
)
},
fmt
.
Sprintf
(
"mtime is %v"
,
expected
))
}
func
mtimeIs
(
c
interface
{},
expected
time
.
Time
)
error
{
// Like MtimeIs, but allows for a tolerance.
func
MtimeIsWithin
(
expected
time
.
Time
,
d
time
.
Duration
)
oglematchers
.
Matcher
{
return
oglematchers
.
NewMatcher
(
func
(
c
interface
{})
error
{
return
mtimeIsWithin
(
c
,
expected
,
d
)
},
fmt
.
Sprintf
(
"mtime is within %v of %v"
,
d
,
expected
))
}
func
mtimeIsWithin
(
c
interface
{},
expected
time
.
Time
,
d
time
.
Duration
)
error
{
fi
,
ok
:=
c
.
(
os
.
FileInfo
)
if
!
ok
{
return
fmt
.
Errorf
(
"which is of type %v"
,
reflect
.
TypeOf
(
c
))
}
// Check ModTime().
if
fi
.
ModTime
()
!=
expected
{
d
:=
fi
.
ModTime
()
.
Sub
(
expected
)
return
fmt
.
Errorf
(
"which has mtime %v, off by %v"
,
fi
.
ModTime
(),
d
)
diff
:=
fi
.
ModTime
()
.
Sub
(
expected
)
absDiff
:=
diff
if
absDiff
<
0
{
absDiff
=
-
absDiff
}
// Check Sys().
if
sysMtime
,
ok
:=
extractMtime
(
fi
.
Sys
());
ok
{
if
sysMtime
!=
expected
{
d
:=
sysMtime
.
Sub
(
expected
)
return
fmt
.
Errorf
(
"which has Sys() mtime %v, off by %v"
,
sysMtime
,
d
)
}
if
!
(
absDiff
<
d
)
{
return
fmt
.
Errorf
(
"which has mtime %v, off by %v"
,
fi
.
ModTime
(),
diff
)
}
return
nil
...
...
samples/memfs/memfs_test.go
View file @
d6e247cc
...
...
@@ -35,6 +35,9 @@ import (
func
TestMemFS
(
t
*
testing
.
T
)
{
RunTests
(
t
)
}
// TODO(jacobsa): Comments.
const
timeSlop
=
5
*
time
.
Millisecond
////////////////////////////////////////////////////////////////////////
// Helpers
////////////////////////////////////////////////////////////////////////
...
...
@@ -125,7 +128,7 @@ func (t *MemFSTest) Mkdir_OneLevel() {
ExpectEq
(
"dir"
,
fi
.
Name
())
ExpectEq
(
0
,
fi
.
Size
())
ExpectEq
(
os
.
ModeDir
|
applyUmask
(
0754
),
fi
.
Mode
())
ExpectThat
(
fi
,
fusetesting
.
MtimeIs
(
createTime
))
ExpectThat
(
fi
,
fusetesting
.
MtimeIs
Within
(
createTime
,
timeSlop
))
ExpectThat
(
fi
,
fusetesting
.
BirthtimeIs
(
createTime
))
ExpectTrue
(
fi
.
IsDir
())
...
...
@@ -181,7 +184,7 @@ func (t *MemFSTest) Mkdir_TwoLevels() {
ExpectEq
(
"dir"
,
fi
.
Name
())
ExpectEq
(
0
,
fi
.
Size
())
ExpectEq
(
os
.
ModeDir
|
applyUmask
(
0754
),
fi
.
Mode
())
ExpectThat
(
fi
,
fusetesting
.
MtimeIs
(
createTime
))
ExpectThat
(
fi
,
fusetesting
.
MtimeIs
Within
(
createTime
,
timeSlop
))
ExpectThat
(
fi
,
fusetesting
.
BirthtimeIs
(
createTime
))
ExpectTrue
(
fi
.
IsDir
())
...
...
@@ -290,7 +293,7 @@ func (t *MemFSTest) CreateNewFile_InRoot() {
ExpectEq
(
"foo"
,
fi
.
Name
())
ExpectEq
(
len
(
contents
),
fi
.
Size
())
ExpectEq
(
applyUmask
(
0400
),
fi
.
Mode
())
ExpectThat
(
fi
,
fusetesting
.
MtimeIs
(
createTime
))
ExpectThat
(
fi
,
fusetesting
.
MtimeIs
Within
(
createTime
,
timeSlop
))
ExpectThat
(
fi
,
fusetesting
.
BirthtimeIs
(
createTime
))
ExpectFalse
(
fi
.
IsDir
())
...
...
@@ -332,7 +335,7 @@ func (t *MemFSTest) CreateNewFile_InSubDir() {
ExpectEq
(
"foo"
,
fi
.
Name
())
ExpectEq
(
len
(
contents
),
fi
.
Size
())
ExpectEq
(
applyUmask
(
0400
),
fi
.
Mode
())
ExpectThat
(
fi
,
fusetesting
.
MtimeIs
(
createTime
))
ExpectThat
(
fi
,
fusetesting
.
MtimeIs
Within
(
createTime
,
timeSlop
))
ExpectThat
(
fi
,
fusetesting
.
BirthtimeIs
(
createTime
))
ExpectFalse
(
fi
.
IsDir
())
...
...
@@ -379,7 +382,7 @@ func (t *MemFSTest) ModifyExistingFile_InRoot() {
ExpectEq
(
"foo"
,
fi
.
Name
())
ExpectEq
(
len
(
"Hello, world!"
),
fi
.
Size
())
ExpectEq
(
applyUmask
(
0600
),
fi
.
Mode
())
ExpectThat
(
fi
,
fusetesting
.
MtimeIs
(
modifyTime
))
ExpectThat
(
fi
,
fusetesting
.
MtimeIs
Within
(
modifyTime
,
timeSlop
))
ExpectThat
(
fi
,
fusetesting
.
BirthtimeIs
(
createTime
))
ExpectFalse
(
fi
.
IsDir
())
...
...
@@ -431,7 +434,7 @@ func (t *MemFSTest) ModifyExistingFile_InSubDir() {
ExpectEq
(
"foo"
,
fi
.
Name
())
ExpectEq
(
len
(
"Hello, world!"
),
fi
.
Size
())
ExpectEq
(
applyUmask
(
0600
),
fi
.
Mode
())
ExpectThat
(
fi
,
fusetesting
.
MtimeIs
(
modifyTime
))
ExpectThat
(
fi
,
fusetesting
.
MtimeIs
Within
(
modifyTime
,
timeSlop
))
ExpectThat
(
fi
,
fusetesting
.
BirthtimeIs
(
createTime
))
ExpectFalse
(
fi
.
IsDir
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment