Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
eResearch
ProvisionerAPI
Commits
9874d848
Commit
9874d848
authored
May 07, 2018
by
Mike Lynch
Browse files
Test written and passing to import and export a small file hierarchy
parent
657cc73b
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/FilesApp.ts
View file @
9874d848
...
...
@@ -197,5 +197,4 @@ export class FilesExporter extends BaseExporter implements IExporter {
);
}
}
lib/FilesWorkspace.spec.ts
View file @
9874d848
...
...
@@ -14,6 +14,17 @@ const FIXTURE_DIR = "test/fixtures/fileapp1";
const
FIXTURE_FILES
=
"
test/files
"
;
const
FIXTURE_FILE
=
path
.
join
(
FIXTURE_FILES
,
'
green.jpg
'
);
const
OUTPUT
=
"
test/output
"
;
const
FIXTURE_TREE
=
path
.
join
(
FIXTURE_FILES
,
'
small_tree
'
);
const
OUTPUT_TREE
=
path
.
join
(
OUTPUT
,
'
small_tree
'
);
const
SMALL_TREE_FILES
=
[
'
file1.txt
'
,
'
file2.txt
'
,
'
dir2/file3.txt
'
,
'
dir2/dir3/file4.txt
'
,
'
dir2/dir3/file5.txt
'
];
describe
(
'
FilesWorkspace
'
,
function
()
{
this
.
timeout
(
10000
);
...
...
@@ -146,6 +157,31 @@ describe('FilesWorkspace', function() {
});
it
(
"
can import and export a small file tree
"
,
async
function
()
{
const
fa
=
new
FilesApp
(
FIXTURE_ID
,
FIXTURE_DIR
);
const
oid
=
'
object1
'
;
const
fo
=
await
fa
.
create
(
oid
);
// note: quick and dirty code to import the tree so that it can
// be exported.
for
(
var
i
in
SMALL_TREE_FILES
)
{
let
f
=
SMALL_TREE_FILES
[
i
];
let
dir
=
path
.
dirname
(
f
);
let
fn
=
path
.
basename
(
f
);
if
(
dir
)
{
await
fo
.
import_path
(
dir
);
}
let
fcont
=
fs
.
createReadStream
(
path
.
join
(
FIXTURE_TREE
,
f
));
await
fo
.
import_stream
(
f
,
fcont
);
}
await
fs
.
ensureDir
(
OUTPUT_TREE
);
await
fo
.
export_all
(
OUTPUT_TREE
);
for
(
var
i
in
SMALL_TREE_FILES
)
{
let
f
=
SMALL_TREE_FILES
[
i
];
let
tfp
=
path
.
join
(
OUTPUT_TREE
,
f
);
let
tfe
=
await
fs
.
pathExists
(
tfp
);
assert
(
tfe
,
"
exported file exists at
"
+
tfp
);
}
});
...
...
lib/Provisioner.ts
View file @
9874d848
...
...
@@ -7,6 +7,8 @@
import
*
as
stream
from
'
stream
'
;
import
*
as
shortid
from
'
shortid
'
;
import
*
as
path
from
'
path
'
;
import
*
as
fs
from
'
fs-extra
'
;
import
{
promisify
}
from
'
util
'
;
...
...
@@ -65,7 +67,6 @@ export abstract class BaseWorkspace {
// to another.
abstract
import_stream
(
path
:
string
,
data
:
stream
.
Readable
):
Promise
<
string
>
;
abstract
import_path
(
path
:
string
):
Promise
<
string
>
;
abstract
import_action
(
ea
:
ExportAction
):
Promise
<
string
>
;
...
...
@@ -93,6 +94,35 @@ export abstract class BaseWorkspace {
}
abstract
new_exporter
(
eid
:
string
):
IExporter
;
// For import_all: remember that an import of a file system is the
// same as an export of a file system, somehow reuse the exporter
// class from the files stuff.
// export_all loops over the export actions and writes the
// contents into a file system - it should be the same for any
// kind of workspace
async
export_all
(
dest
:
string
):
Promise
<
boolean
>
{
let
ea
=
await
this
.
export_stream
();
const
token
=
ea
.
token
;
do
{
let
fpath
=
path
.
join
(
dest
,
ea
.
path
);
if
(
ea
.
action
==
ActionType
.
Dir
)
{
await
fs
.
ensureDir
(
fpath
);
}
else
if
(
ea
.
action
==
ActionType
.
File
)
{
if
(
ea
.
contents
)
{
let
expstream
=
fs
.
createWriteStream
(
fpath
);
await
ea
.
contents
.
pipe
(
expstream
);
}
else
{
throw
new
Error
(
"
Empty ExportAction
"
);
}
}
ea
=
await
this
.
export_stream
(
token
);
}
while
(
ea
);
return
true
;
}
}
...
...
@@ -104,6 +134,7 @@ export interface IWorkspace {
import_stream
(
path
:
string
,
data
:
stream
.
Readable
):
Promise
<
string
>
;
import_path
(
path
:
string
):
Promise
<
string
>
;
export_stream
(
token
?:
string
):
Promise
<
ExportAction
|
null
>
;
export_all
(
path
:
string
):
Promise
<
boolean
>
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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