Skip to content

Commit

Permalink
Merge pull request #206 from ipfs/go-js-tests
Browse files Browse the repository at this point in the history
Added JS to G0 tests
  • Loading branch information
litzenberger authored Jan 23, 2019
2 parents e9879dd + d6fbd0f commit 996530a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
4 changes: 4 additions & 0 deletions runner/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ const testAbstracts = [
name: 'unixFsAddGo',
file: 'local-add.go.js'
},
{
name: 'extractJs2Go',
file: 'extract-js2.go.js'
},
{
name: 'peerTransferBrowser',
file: 'peer-transfer.browser.js'
Expand Down
4 changes: 2 additions & 2 deletions tests/config/go-configs.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
],
"Announce": [],
"NoAnnounce": [],
"API": "/ip4/127.0.0.1/tcp/5001",
"Gateway": "/ip4/127.0.0.1/tcp/8080"
"API": "/ip4/127.0.0.1/tcp/5002",
"Gateway": "/ip4/127.0.0.1/tcp/8081"
}
},
{
Expand Down
5 changes: 4 additions & 1 deletion tests/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ const tests = { 'unixFsAdd': [{
'fileSet': ['OneKBFile', 'OneMBFile'] }],
'unixFsAddGo': [{
'warmup': 'Off',
'fileSet': ['OneKBFile', 'OneMBFile', 'One4MBFile', 'One64MBFile'] } ]
'fileSet': ['OneKBFile', 'OneMBFile', 'One4MBFile', 'One64MBFile'] } ],
'extractJs2Go': [{
'warmup': 'Off',
'fileSet': ['OneKBFile'] } ]
}

const config = {
Expand Down
44 changes: 44 additions & 0 deletions tests/extract-js2.go.js
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)

0 comments on commit 996530a

Please sign in to comment.