Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
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
Stefane Fermigier
jio
Commits
ddf61098
Commit
ddf61098
authored
Aug 23, 2017
by
Vincent Bechu
Committed by
Vincent Bechu
Aug 30, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[test] Add scenarii to test and update saferepair storage to pass them
parent
5d6e60dd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
368 additions
and
307 deletions
+368
-307
examples/scenario.js
examples/scenario.js
+359
-296
examples/scenario_officejs.js
examples/scenario_officejs.js
+0
-8
src/jio.storage/saferepairstorage.js
src/jio.storage/saferepairstorage.js
+4
-3
test/tests.html
test/tests.html
+5
-0
No files found.
examples/scenario.js
View file @
ddf61098
/*global console, btoa, Blob*/
/*global console, btoa, Blob
, RSVP
*/
/*jslint nomen: true, maxlen: 200*/
(
function
(
window
,
QUnit
,
jIO
,
rJS
)
{
"
use strict
"
;
...
...
@@ -8,225 +8,71 @@
ok
=
QUnit
.
ok
,
stop
=
QUnit
.
stop
,
start
=
QUnit
.
start
,
deepEqual
=
QUnit
.
deepEqual
;
module
=
QUnit
.
module
,
deepEqual
=
QUnit
.
deepEqual
,
global
=
{
defer
:
RSVP
.
defer
()};
rJS
(
window
)
.
ready
(
function
(
g
)
{
///////////////////////////
// Local storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// type: "document",
// document_id: "/",
// sub_storage: {
// type: "zip",
// sub_storage: {
// type: "local"
// }
// }
// }
// }
// });
///////////////////////////
// Memory storage
///////////////////////////
return
g
.
run
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
union
"
,
storage_list
:
[{
type
:
"
memory
"
}]
}
}
});
///////////////////////////
// WebSQL storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// "type": "websql",
// "database": "test"
// }
// }
// });
///////////////////////////
// IndexedDB storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// "type": "indexeddb",
// "database": "test"
// }
// }
// });
///////////////////////////
// DAV storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// type: "drivetojiomapping",
// sub_storage: {
// "type": "dav",
// "url": "DAVURL",
// "basic_login": btoa("LOGIN:PASSWD")
// }
// }
// }
// });
///////////////////////////
// Dropbox storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// type: "drivetojiomapping",
// sub_storage: {
// "type": "dropbox",
// "access_token" : "TOKEN",
// "root" : "dropbox"
// }
// }
// }
// });
///////////////////////////
// Qiniu storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// "type": "qiniu",
// "bucket": "BUCKET",
// "access_key": "ACCESSKEY",
// "secret_key": "SECRETKEY"
// }
// }
// });
///////////////////////////
// Replicate storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// type: "replicate",
// local_sub_storage: {
// type: "memory"
// },
// remote_sub_storage: {
// "type": "memory"
// }
// }
// }
// });
///////////////////////////
// Crypt storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// type: "crypt",
// key: {"alg": "A256GCM", "ext": true,
// "k": "seeaLzpu8dHG07bO2ANH2GywbTqs_zrs4Vq8zmtYeE4",
// "key_ops": ["encrypt", "decrypt"], "kty": "oct"},
// sub_storage: {
// type: "indexeddb",
// database: "test427"
// }
// }
// }
// });
.
ready
(
function
()
{
global
.
gadget
=
this
;
global
.
defer
.
resolve
();
})
.
declareMethod
(
'
run
'
,
function
(
jio_options
)
{
test
(
'
Test "
'
+
jio_options
.
type
+
'
"scenario
'
,
function
()
{
var
jio
;
stop
();
expect
(
14
);
try
{
jio
=
jIO
.
createJIO
(
jio_options
);
}
catch
(
error
)
{
console
.
error
(
error
.
stack
);
console
.
error
(
error
);
throw
error
;
}
var
jio
;
// Try to fetch inexistent document
jio
.
get
(
"
inexistent
"
)
.
fail
(
function
(
error
)
{
console
.
error
(
error
);
if
(
error
.
status_code
!==
404
)
{
throw
error
;
}
equal
(
error
.
status_code
,
404
,
"
404 if inexistent
"
);
try
{
jio
=
jIO
.
createJIO
(
jio_options
);
}
catch
(
error
)
{
console
.
error
(
error
.
stack
);
console
.
error
(
error
);
throw
error
;
}
// Post a document without ID
return
jio
.
post
({
"
title
"
:
"
I don't have ID éà&
\n
"
});
})
.
then
(
function
(
doc_id
)
{
ok
(
doc_id
,
"
Document without ID created (
"
+
doc_id
+
"
)
"
);
// Fetch the newly created document
return
RSVP
.
all
([
jio
.
get
(
doc_id
),
doc_id
]);
})
.
then
(
function
(
result_list
)
{
var
doc
=
result_list
[
0
],
doc_id
=
result_list
[
1
];
deepEqual
(
doc
,
{
"
title
"
:
"
I don't have ID éà&
\n
"
},
"
Document correctly fetched
"
);
// Remove the doc
return
jio
.
remove
(
doc_id
);
})
.
then
(
function
(
doc_id
)
{
ok
(
doc_id
,
"
Document removed
"
);
// Create some documents to check allDocs
return
RSVP
.
all
([
jio
.
put
(
"
id1
"
,
{
"
title
"
:
"
1 ID
"
,
"
int_index
"
:
1
}),
jio
.
put
(
"
id2
"
,
{
"
title
"
:
"
2 ID
"
,
"
int_index
"
:
2
}),
jio
.
put
(
"
id3
"
,
{
"
title
"
:
"
3 ID
"
,
"
int_index
"
:
3
})
]);
})
.
then
(
function
(
all_doc_id
)
{
equal
(
all_doc_id
[
0
],
"
id1
"
,
"
Document 1 correctly created
"
);
equal
(
all_doc_id
[
1
],
"
id2
"
,
"
Document 2 correctly created
"
);
equal
(
all_doc_id
[
2
],
"
id3
"
,
"
Document 3 correctly created
"
);
// Try to fetch inexistent document
jio
.
get
(
"
inexistent
"
)
.
fail
(
function
(
error
)
{
console
.
error
(
error
);
if
(
error
.
status_code
!==
404
)
{
throw
error
;
}
equal
(
error
.
status_code
,
404
,
"
404 if inexistent
"
);
// Post a document without ID
return
jio
.
post
({
"
title
"
:
"
I don't have ID éà&
\n
"
});
})
.
then
(
function
(
doc_id
)
{
ok
(
doc_id
,
"
Document without ID created (
"
+
doc_id
+
"
)
"
);
// Fetch the newly created document
return
RSVP
.
all
([
jio
.
get
(
doc_id
),
doc_id
]);
})
.
then
(
function
(
result_list
)
{
var
doc
=
result_list
[
0
],
doc_id
=
result_list
[
1
];
deepEqual
(
doc
,
{
"
title
"
:
"
I don't have ID éà&
\n
"
},
"
Document correctly fetched
"
);
// Remove the doc
return
jio
.
remove
(
doc_id
);
})
.
then
(
function
(
doc_id
)
{
ok
(
doc_id
,
"
Document removed
"
);
// Create some documents to check allDocs
return
RSVP
.
all
([
jio
.
put
(
"
id1
"
,
{
"
title
"
:
"
1 ID
"
,
"
int_index
"
:
1
}),
jio
.
put
(
"
id2
"
,
{
"
title
"
:
"
2 ID
"
,
"
int_index
"
:
2
}),
jio
.
put
(
"
id3
"
,
{
"
title
"
:
"
3 ID
"
,
"
int_index
"
:
3
})
]);
})
.
then
(
function
(
all_doc_id
)
{
equal
(
all_doc_id
[
0
],
"
id1
"
,
"
Document 1 correctly created
"
);
equal
(
all_doc_id
[
1
],
"
id2
"
,
"
Document 2 correctly created
"
);
equal
(
all_doc_id
[
2
],
"
id3
"
,
"
Document 3 correctly created
"
);
// // Default allDocs call
// return jio.allDocs();
...
...
@@ -248,94 +94,311 @@
// }
// }, "default allDocs OK");
// Filter the result
console
.
log
(
"
START ALLDOCS
"
);
return
jio
.
allDocs
({
query
:
'
title: "2 ID"
'
,
select_list
:
[
"
int_index
"
]
});
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[{
doc
:
{},
id
:
"
id2
"
,
value
:
{
int_index
:
2
}
}],
total_rows
:
1
}
},
"
filter allDocs OK
"
);
// XXX Check include docs, sort, limit, select
})
.
then
(
function
()
{
return
jio
.
getAttachment
(
"
inexistent
"
,
"
enclosure
"
)
.
fail
(
function
(
error
)
{
equal
(
error
.
status_code
,
404
,
"
404 if inexistent
"
);
console
.
log
(
error
);
});
})
.
then
(
function
()
{
return
jio
.
put
(
"
foo❤/test.txt
"
,
{});
})
.
then
(
function
()
{
return
jio
.
putAttachment
(
"
foo❤/test.txt
"
,
"
enclosure
"
,
new
Blob
([
"
fooé
\n
bar测试四😈
"
],
{
type
:
"
text/plain
"
})
);
})
.
then
(
function
()
{
ok
(
true
,
"
Attachment stored
"
);
return
jio
.
getAttachment
(
"
foo❤/test.txt
"
,
"
enclosure
"
);
})
.
then
(
function
(
blob
)
{
return
jIO
.
util
.
readBlobAsText
(
blob
);
})
.
then
(
function
(
result
)
{
equal
(
result
.
target
.
result
,
"
fooé
\n
bar测试四😈
"
,
"
Attachment correctly fetched
"
);
return
jio
.
get
(
"
foo❤/test.txt
"
);
})
.
then
(
function
(
doc
)
{
deepEqual
(
doc
,
{},
"
Document correctly fetched
"
);
return
jio
.
allAttachments
(
"
foo❤/test.txt
"
);
})
.
then
(
function
(
doc
)
{
deepEqual
(
doc
,
{
enclosure
:
{}
},
"
Attachment list correctly fetched
"
);
return
jio
.
removeAttachment
(
"
foo❤/test.txt
"
,
"
enclosure
"
);
})
// Filter the result
console
.
log
(
"
START ALLDOCS
"
);
return
jio
.
allDocs
({
query
:
'
title: "2 ID"
'
,
select_list
:
[
"
int_index
"
]
});
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[{
doc
:
{},
id
:
"
id2
"
,
value
:
{
int_index
:
2
}
}],
total_rows
:
1
}
},
"
filter allDocs OK
"
);
.
then
(
function
()
{
ok
(
"
Attachment removed
"
);
})
// XXX Check include docs, sort, limit, select
})
.
then
(
function
()
{
return
jio
.
repair
();
})
.
then
(
function
()
{
return
jio
.
getAttachment
(
"
inexistent
"
,
"
enclosure
"
)
.
fail
(
function
(
error
)
{
equal
(
error
.
status_code
,
404
,
"
404 if inexistent
"
);
console
.
log
(
error
);
});
})
.
then
(
function
()
{
return
jio
.
put
(
"
foo❤/test.txt
"
,
{});
})
.
then
(
function
()
{
return
jio
.
putAttachment
(
"
foo❤/test.txt
"
,
"
enclosure
"
,
new
Blob
([
"
fooé
\n
bar测试四😈
"
],
{
type
:
"
text/plain
"
})
);
})
.
then
(
function
()
{
ok
(
true
,
"
Attachment stored
"
);
return
jio
.
getAttachment
(
"
foo❤/test.txt
"
,
"
enclosure
"
);
})
.
then
(
function
(
blob
)
{
return
jIO
.
util
.
readBlobAsText
(
blob
);
})
.
then
(
function
(
result
)
{
equal
(
result
.
target
.
result
,
"
fooé
\n
bar测试四😈
"
,
"
Attachment correctly fetched
"
);
return
jio
.
get
(
"
foo❤/test.txt
"
);
})
.
then
(
function
(
doc
)
{
deepEqual
(
doc
,
{},
"
Document correctly fetched
"
);
return
jio
.
allAttachments
(
"
foo❤/test.txt
"
);
})
.
then
(
function
(
doc
)
{
deepEqual
(
doc
,
{
enclosure
:
{}
},
"
Attachment list correctly fetched
"
);
return
jio
.
removeAttachment
(
"
foo❤/test.txt
"
,
"
enclosure
"
);
})
.
then
(
function
()
{
ok
(
"
Attachment removed
"
);
})
.
then
(
function
()
{
return
jio
.
repair
();
})
.
fail
(
function
(
error
)
{
console
.
error
(
"
---
"
);
console
.
error
(
error
.
stack
);
console
.
error
(
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
.
fail
(
function
(
error
)
{
console
.
error
(
"
---
"
);
console
.
error
(
error
.
stack
);
console
.
error
(
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
module
(
"
scenario
"
);
///////////////////////////
// Memory storage
///////////////////////////
test
(
'
Test Memory Storage scenario
'
,
function
()
{
stop
();
expect
(
14
);
return
global
.
defer
.
promise
.
then
(
function
()
{
return
global
.
gadget
.
run
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
union
"
,
storage_list
:
[{
type
:
"
memory
"
}]
}
}
});
});
});
});
///////////////////////////
// Local storage
///////////////////////////
test
(
'
Test Local Storage scenario
'
,
function
()
{
stop
();
expect
(
14
);
return
global
.
defer
.
promise
.
then
(
function
()
{
return
global
.
gadget
.
run
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
document
"
,
document_id
:
"
/
"
,
sub_storage
:
{
type
:
"
zip
"
,
sub_storage
:
{
type
:
"
local
"
}
}
}
}
});
});
});
///////////////////////////
// WebSQL storage
///////////////////////////
test
(
'
Test WebSQL Storage scenario
'
,
function
()
{
stop
();
expect
(
14
);
return
global
.
defer
.
promise
.
then
(
function
()
{
return
global
.
gadget
.
run
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
"
type
"
:
"
websql
"
,
"
database
"
:
"
test
"
}
}
});
});
});
///////////////////////////
// IndexedDB storage
///////////////////////////
test
(
'
Test IndexedDB Storage scenario
'
,
function
()
{
stop
();
expect
(
14
);
return
global
.
defer
.
promise
.
then
(
function
()
{
return
global
.
gadget
.
run
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
"
type
"
:
"
indexeddb
"
,
"
database
"
:
"
test
"
}
}
});
});
});
///////////////////////////
// DAV storage
///////////////////////////
test
(
'
Test DAV Storage scenario
'
,
function
()
{
stop
();
expect
(
14
);
return
global
.
defer
.
promise
.
then
(
function
()
{
return
global
.
gadget
.
run
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
drivetojiomapping
"
,
sub_storage
:
{
"
type
"
:
"
dav
"
,
"
url
"
:
"
DAVURL
"
,
"
basic_login
"
:
btoa
(
"
LOGIN:PASSWD
"
)
}
}
}
});
});
});
///////////////////////////
// Dropbox storage
///////////////////////////
test
(
'
Test Dropbox Storage scenario
'
,
function
()
{
stop
();
expect
(
14
);
return
global
.
defer
.
promise
.
then
(
function
()
{
return
global
.
gadget
.
run
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
drivetojiomapping
"
,
sub_storage
:
{
"
type
"
:
"
dropbox
"
,
"
access_token
"
:
"
TOKEN
"
,
"
root
"
:
"
dropbox
"
}
}
}
});
});
});
///////////////////////////
// Qiniu storage
///////////////////////////
/*
test('Test Qiniu Storage scenario', function () {
stop();
expect(14);
return global.defer.promise
.then(function () {
return global.gadget.run({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
"type": "qiniu",
"bucket": "BUCKET",
"access_key": "ACCESSKEY",
"secret_key": "SECRETKEY"
}
}
});
});
});
*/
///////////////////////////
// Replicate storage
///////////////////////////
test
(
'
Test Replicate Storage scenario
'
,
function
()
{
stop
();
expect
(
14
);
return
global
.
defer
.
promise
.
then
(
function
()
{
return
global
.
gadget
.
run
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
replicate
"
,
local_sub_storage
:
{
type
:
"
memory
"
},
remote_sub_storage
:
{
"
type
"
:
"
memory
"
}
}
}
});
});
});
///////////////////////////
// Crypt storage
///////////////////////////
test
(
'
Test Crypt Storage scenario
'
,
function
()
{
stop
();
expect
(
14
);
return
global
.
defer
.
promise
.
then
(
function
()
{
return
global
.
gadget
.
run
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
crypt
"
,
key
:
{
"
alg
"
:
"
A256GCM
"
,
"
ext
"
:
true
,
"
k
"
:
"
seeaLzpu8dHG07bO2ANH2GywbTqs_zrs4Vq8zmtYeE4
"
,
"
key_ops
"
:
[
"
encrypt
"
,
"
decrypt
"
],
"
kty
"
:
"
oct
"
},
sub_storage
:
{
type
:
"
indexeddb
"
,
database
:
"
test427
"
}
}
}
});
});
});
}(
window
,
QUnit
,
jIO
,
rJS
));
}(
window
,
QUnit
,
jIO
,
rJS
,
RSVP
));
examples/scenario_officejs.js
View file @
ddf61098
...
...
@@ -12,13 +12,8 @@
module
=
QUnit
.
module
,
ATTACHMENT
=
'
data
'
,
i
,
<<<<<<<
HEAD
name_list
=
[
'
get
'
,
'
post
'
,
'
put
'
,
'
buildQuery
'
,
=======
name_list
=
[
'
get
'
,
'
post
'
,
'
put
'
,
'
remove
'
,
'
buildQuery
'
,
>>>>>>>
7
ed9424
...
Scenario
:
init
officejs
scenario
'
putAttachment
'
,
'
getAttachment
'
,
'
allAttachments
'
];
///////////////////////////////////////////////////////
// Fake Storage
///////////////////////////////////////////////////////
...
...
@@ -154,11 +149,8 @@
check_remote_attachment_creation
:
true
,
check_remote_attachment_deletion
:
true
,
check_local_deletion
:
false
,
<<<<<<<
HEAD
parallel_operation_amount
:
10
,
parallel_operation_attachment_amount
:
10
,
=======
>>>>>>>
7
ed9424
...
Scenario
:
init
officejs
scenario
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
...
...
src/jio.storage/saferepairstorage.js
View file @
ddf61098
/*jslint nomen: true*/
(
function
(
jIO
)
{
/*jslint indent:2,maxlen:80,nomen:true*/
/*global jIO, RSVP*/
(
function
(
jIO
,
RSVP
)
{
"
use strict
"
;
/**
...
...
@@ -88,4 +89,4 @@
jIO
.
addStorage
(
'
saferepair
'
,
SafeRepairStorage
);
}(
jIO
));
}(
jIO
,
RSVP
));
test/tests.html
View file @
ddf61098
...
...
@@ -53,6 +53,11 @@
<script
src=
"jio.storage/zipstorage.tests.js"
></script>
<script
src=
"jio.storage/gdrivestorage.tests.js"
></script>
<script
src=
"jio.storage/websqlstorage.tests.js"
></script>
<script
src=
"../node_modules/renderjs/dist/renderjs-latest.js"
></script>
<script
src=
"../examples/scenario.js"
></script>
<script
src=
"../examples/scenario_officejs.js"
></script>
<!--script src="../lib/jquery/jquery.min.js"></script>
<script src="../src/jio.storage/xwikistorage.js"></script>
<script src="jio.storage/xwikistorage.tests.js"></script-->
...
...
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