-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed
Fetch
not commit transaction when caching data
Improved fetch testing
- Loading branch information
Showing
4 changed files
with
64 additions
and
38 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,8 @@ | ||
#!/usr/bin/bash | ||
|
||
tsx tests/fetch.ts & | ||
PID=$! | ||
|
||
npx zenfs-test tests/setup/cow+fetch.ts $@ | ||
|
||
kill $PID |
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,49 @@ | ||
import { execSync } from 'node:child_process'; | ||
import { appendFileSync, readFileSync } from 'node:fs'; | ||
import { createServer } from 'node:http'; | ||
import { join } from 'node:path'; | ||
import { data, tmp } from './setup.js'; | ||
|
||
// If you change the port please update the setup file as well | ||
const port = 26514; | ||
|
||
const statusCodes = { | ||
ENOENT: 404, | ||
}; | ||
|
||
try { | ||
execSync(`npm exec make-index -- ${data} --output ${tmp}/index.json --quiet`, { stdio: 'inherit' }); | ||
} catch (e: any) { | ||
if (e.signal == 'SIGINT') { | ||
console.log('Aborted whilst creating index.'); | ||
process.exit(0); | ||
} else { | ||
console.error('Index creation failed: ' + e.message); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
const server = createServer((request, response) => { | ||
const { url = '' } = request; | ||
|
||
if (url == '/.ping') { | ||
response.statusCode = 200; | ||
response.end('pong'); | ||
return; | ||
} | ||
|
||
const path = url == '/.index.json' ? join(tmp, 'index.json') : join(data, url.slice(1) || ''); | ||
try { | ||
response.statusCode = 200; | ||
response.end(readFileSync(path)); | ||
} catch (e: any) { | ||
response.statusCode = statusCodes[e.code as keyof typeof statusCodes] || 400; | ||
response.end(); | ||
} | ||
}); | ||
|
||
server.listen(port); | ||
|
||
process.on('beforeExit', () => { | ||
server.close().unref(); | ||
}); |
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