-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #206 from ipfs/go-js-tests
Added JS to G0 tests
- Loading branch information
Showing
4 changed files
with
54 additions
and
3 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
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,44 @@ | ||
'use strict' | ||
|
||
const os = require('os') | ||
const fs = require('fs') | ||
const { build } = require('./schema/results') | ||
const { file } = require('./lib/fixtures') | ||
const run = require('./lib/runner') | ||
const { once } = require('stream-iterators-utils') | ||
const NodeFactory = require('./lib/node-factory') | ||
const util = require('util') | ||
const execute = util.promisify(util.promisify(require('child_process').exec)) | ||
const conf = { tmpPath: os.tmpdir() } | ||
|
||
async function extractJs2Go (ipfs, name, warmup, fileSet, version) { | ||
console.log(fileSet) | ||
//Runner rtunrs the NodeJS ipfs but we need to create the Go ipfs | ||
const nodeFactory = new NodeFactory() | ||
const ipfsGo = await nodeFactory.add('go') | ||
const filePath = await file(fileSet) | ||
const fileStream = fs.createReadStream(filePath) | ||
const peer = ipfs[0] | ||
const inserted = await peer.add(fileStream) | ||
|
||
const peerId = await peer.id() | ||
let command = `export IPFS_PATH=${conf.tmpPath}/ipfs0 && ipfs swarm connect ${peerId.addresses[0]}` | ||
const results = await execute(command, { maxBuffer: 1024 * 1024 * 100 }) | ||
|
||
const start = process.hrtime() | ||
command = `export IPFS_PATH=${conf.tmpPath}/ipfs0 && ipfs cat ${inserted[0].hash}` | ||
await execute(command) | ||
const end = process.hrtime(start) | ||
await nodeFactory.stop('go') | ||
return build({ | ||
name: name, | ||
warmup: warmup, | ||
file: filePath, | ||
meta: { version: version }, | ||
description: 'Extract files from JS to Go IPFS peers', | ||
file_set: fileSet, | ||
duration: { s: end[0], | ||
ms: end[1] / 1000000 } | ||
}) | ||
} | ||
run(extractJs2Go) |