This repository has been archived by the owner on Jul 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more tests + testability improvements
- Loading branch information
1 parent
a380050
commit 3ac9cec
Showing
4 changed files
with
92 additions
and
23 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
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,22 @@ | ||
path = require 'path' | ||
|
||
module.exports = | ||
listStorageBuckets: (fs, dir, cb) -> | ||
fs.readdir dir, (err, dirList) -> | ||
if err | ||
console.error err | ||
cb? err, null | ||
else | ||
try | ||
files = dirList?.map (file) -> | ||
copyLock = ".#{file}.copy.lock" | ||
deleteLock = ".#{file}.delete.lock" | ||
stat = fs.statSync path.join(dir, file) | ||
if stat?.isDirectory() | ||
name: file | ||
created: stat.birthtime | ||
isLocked: copyLock in dirList or deleteLock in dirList | ||
.filter (file) -> file? | ||
cb? null, files | ||
catch ex | ||
cb? ex, null |
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,5 @@ | ||
assert = require 'assert' | ||
td = require 'testdouble' | ||
storage = require '../../src/coffee/storage.coffee' | ||
|
||
describe 'Storage', -> |
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,60 @@ | ||
assert = require 'assert' | ||
td = require 'testdouble' | ||
lib = require '../../../src/coffee/storage/lib.coffee' | ||
|
||
describe 'Storage/Lib', -> | ||
describe 'listStorageBuckets', -> | ||
it 'should callback with an error when there was a problem listing files in the dir', -> | ||
fs = td.object ['readdir'] | ||
cb = td.function() | ||
td.when(fs.readdir 'mydir').thenCallback('err', null) | ||
lib.listStorageBuckets fs, 'mydir', cb | ||
td.verify cb 'err', null | ||
it 'should callback with an error when there was a problem retrieving file stats', -> | ||
fs = td.object ['readdir', 'statSync'] | ||
cb = td.function() | ||
td.when(fs.readdir 'mydir').thenCallback( null, ['dir1', '.dir1.delete.lock']) | ||
td.when(fs.statSync 'mydir/dir1').thenThrow 'An Error' | ||
lib.listStorageBuckets fs, 'mydir', cb | ||
td.verify cb 'An Error', null | ||
it 'should retrieve stats for each file', -> | ||
fs = td.object ['readdir', 'statSync'] | ||
cb = td.function() | ||
td.when(fs.readdir 'mydir').thenCallback( null, ['file1', 'file2']) | ||
lib.listStorageBuckets fs, 'mydir', cb | ||
td.verify fs.statSync('mydir/file1'), times:1 | ||
td.verify fs.statSync('mydir/file2'), times:1 | ||
it 'should return stats for directories only', -> | ||
fs = td.object ['readdir', 'statSync'] | ||
cb = td.function() | ||
td.when(fs.readdir 'mydir').thenCallback( null, ['dir1', 'file2']) | ||
td.when(fs.statSync 'mydir/dir1').thenReturn isDirectory:(-> true), birthtime: 'sometime' | ||
td.when(fs.statSync 'mydir/file2').thenReturn isDirectory: -> false | ||
lib.listStorageBuckets fs, 'mydir', cb | ||
td.verify cb null, [ | ||
name: 'dir1' | ||
created: 'sometime' | ||
isLocked: false | ||
] | ||
it 'should set the isLocked property to true for directories which are locked by a copy lock', -> | ||
fs = td.object ['readdir', 'statSync'] | ||
cb = td.function() | ||
td.when(fs.readdir 'mydir').thenCallback( null, ['dir1', '.dir1.copy.lock']) | ||
td.when(fs.statSync 'mydir/dir1').thenReturn isDirectory:(-> true), birthtime: 'sometime' | ||
lib.listStorageBuckets fs, 'mydir', cb | ||
td.verify cb null, [ | ||
name: 'dir1' | ||
created: 'sometime' | ||
isLocked: true | ||
] | ||
it 'should set the isLocked property to true for directories which are locked by a delete lock', -> | ||
fs = td.object ['readdir', 'statSync'] | ||
cb = td.function() | ||
td.when(fs.readdir 'mydir').thenCallback( null, ['dir1', '.dir1.delete.lock']) | ||
td.when(fs.statSync 'mydir/dir1').thenReturn isDirectory:(-> true), birthtime: 'sometime' | ||
lib.listStorageBuckets fs, 'mydir', cb | ||
td.verify cb null, [ | ||
name: 'dir1' | ||
created: 'sometime' | ||
isLocked: true | ||
] |