-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37f17a0
commit deb443b
Showing
3 changed files
with
140 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { TestCallback, TestInfo } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
import * as path from 'path' | ||
import * as fs from 'fs' | ||
|
||
let index = 0; | ||
function getPath(index : number, subName ?: string) : string | ||
{ | ||
const rootPath = path.join(__dirname, 'persistence' + index.toString()); | ||
if(subName) | ||
return path.join(rootPath, subName); | ||
else | ||
return rootPath; | ||
} | ||
|
||
export function starter(info : TestInfo, isValid : TestCallback, callback : (server : v2.WebDAVServer, folder : string, file : string, fileTemp : string) => void) : void | ||
{ | ||
const currentIndex = ++index; | ||
|
||
const root = getPath(currentIndex); | ||
const folder = getPath(currentIndex, 'data'); | ||
const file = getPath(currentIndex, 'save.json'); | ||
const fileTemp = getPath(currentIndex, 'save.tmp.json'); | ||
|
||
const server = info.startServer({ | ||
autoSave: { | ||
treeFilePath: file, | ||
tempTreeFilePath: fileTemp | ||
} | ||
}) | ||
server.rootFileSystem().addSubTree(v2.RequestContext.createExternal(server), { | ||
'emptyFolder1': v2.ResourceType.Directory, | ||
'folder1': { | ||
'emptyFolder2': v2.ResourceType.Directory, | ||
'file2': v2.ResourceType.File, | ||
'folder2': { | ||
'emptyFolder3': v2.ResourceType.Directory, | ||
'file3': v2.ResourceType.File | ||
} | ||
}, | ||
'file1': v2.ResourceType.File | ||
}, (e) => { | ||
if(e) return isValid(false, 'Cannot call "addSubTree(...)".', e); | ||
|
||
fs.rmdir(folder, () => { | ||
fs.unlink(file, () => { | ||
fs.unlink(fileTemp, () => { | ||
fs.mkdir(root, (e) => { | ||
callback(server, folder, file, fileTemp); | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
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,61 @@ | ||
import { Test, TestCallback } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
import { starter } from './.createPersistenceContext' | ||
import * as fs from 'fs' | ||
|
||
function prob(server : v2.WebDAVServer, isValid : TestCallback, path : string | v2.Path, expectedType : v2.ResourceType, callback : () => void) : void | ||
{ | ||
const ctx = server.createExternalContext(); | ||
server.getResource(ctx, path, (e, r) => { | ||
if(e) | ||
return isValid(false, 'Could not find the resource ' + path, e); | ||
|
||
r.type((e, type) => { | ||
if(e) | ||
return isValid(false, 'Error with the resource ' + path, e); | ||
if(type !== expectedType) | ||
return isValid(false, 'Wrong type for the resource ' + path); | ||
|
||
callback(); | ||
}) | ||
}) | ||
} | ||
|
||
export default ((info, isValid) => | ||
{ | ||
info.init(1); | ||
|
||
starter(info, isValid, (server, folder, file, fileTmp) => { | ||
info.req({ | ||
url: 'http://localhost:' + server.options.port + '/file1', | ||
method: 'PUT', | ||
body: 'This is my content!' | ||
}, () => { | ||
setTimeout(() => { | ||
const server2 = info.startServer(server.options); | ||
server2.autoLoad((e) => { | ||
isValid(!e, 'Could not autoLoad the supposed saved server state.', e); | ||
|
||
prob(server2, isValid, '/folder1', v2.ResourceType.Directory, () => { | ||
prob(server2, isValid, '/folder1/emptyFolder2', v2.ResourceType.Directory, () => { | ||
prob(server2, isValid, '/folder1/file2', v2.ResourceType.File, () => { | ||
prob(server2, isValid, '/folder1/folder2', v2.ResourceType.Directory, () => { | ||
prob(server2, isValid, '/folder1/folder2/emptyFolder3', v2.ResourceType.Directory, () => { | ||
prob(server2, isValid, '/folder1/folder2/file3', v2.ResourceType.File, () => { | ||
prob(server2, isValid, '/emptyFolder1', v2.ResourceType.Directory, () => { | ||
prob(server2, isValid, '/file1', v2.ResourceType.File, () => { | ||
isValid(true); | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}, 1000); | ||
}) | ||
}) | ||
|
||
}) as Test; |
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,24 @@ | ||
import { Test } from '../Type' | ||
import { v2 } from '../../../../lib/index.js' | ||
import { starter } from './.createPersistenceContext' | ||
import * as fs from 'fs' | ||
|
||
export default ((info, isValid) => | ||
{ | ||
info.init(1); | ||
|
||
starter(info, isValid, (server, folder, file, fileTmp) => { | ||
info.req({ | ||
url: 'http://localhost:' + server.options.port + '/file1', | ||
method: 'PUT', | ||
body: 'This is my content!' | ||
}, () => { | ||
setTimeout(() => { | ||
fs.exists(file, (exists) => { | ||
isValid(exists, 'The save file is not created.'); | ||
}) | ||
}, 1000); | ||
}) | ||
}) | ||
|
||
}) as Test; |