Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
test: fix failing gateway tests with this one simple trick! (#1006)
Browse files Browse the repository at this point in the history
* fix failing tests with this one simple trick!

* adding files to make tests self-contained

* changes requested by VictorBjelkholm #968
  • Loading branch information
ya7ya authored and daviddias committed Sep 8, 2017
1 parent 94cec9b commit 7cae803
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
54 changes: 46 additions & 8 deletions test/gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ const API = require('../../src/http')
const loadFixture = require('aegir/fixtures')
const os = require('os')
const path = require('path')
const fileType = require('file-type')

const bigFile = loadFixture(__dirname, '../../node_modules/interface-ipfs-core/test/fixtures/15mb.random', 'ipfs')
const directoryContent = {
'index.html': loadFixture(__dirname, './test-folder/index.html', 'ipfs'),
'nested-folder/hello.txt': loadFixture(__dirname, './test-folder/nested-folder/hello.txt', 'ipfs'),
'nested-folder/ipfs.txt': loadFixture(__dirname, './test-folder/nested-folder/ipfs.txt', 'ipfs'),
'nested-folder/nested.html': loadFixture(__dirname, './test-folder/nested-folder/nested.html', 'ipfs')
'nested-folder/nested.html': loadFixture(__dirname, './test-folder/nested-folder/nested.html', 'ipfs'),
'cat-folder/cat.jpg': loadFixture(__dirname, './test-folder/cat-folder/cat.jpg', 'ipfs')
}

describe('HTTP Gateway', () => {
Expand All @@ -38,17 +40,17 @@ describe('HTTP Gateway', () => {
}
})

const content = (name) => ({
path: `test-folder/${name}`,
content: directoryContent[name]
})

const emptyDir = (name) => ({ path: `test-folder/${name}` })

series([
(cb) => http.api.start(true, cb),
(cb) => {
gateway = http.api.server.select('Gateway')
const content = (name) => ({
path: `test-folder/${name}`,
content: directoryContent[name]
})

const emptyDir = (name) => ({ path: `test-folder/${name}` })

const expectedRootMultihash = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi'

const dirs = [
Expand Down Expand Up @@ -79,6 +81,32 @@ describe('HTTP Gateway', () => {
expect(file.hash).to.equal(expectedMultihash)
cb()
})
},
(cb) => {
const expectedMultihash = 'QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o'

http.api.node.files.add(Buffer.from('hello world' + '\n'), (err, res) => {
expect(err).to.not.exist()
const file = res[0]
expect(file.path).to.equal(expectedMultihash)
expect(file.hash).to.equal(expectedMultihash)
cb()
})
},
(cb) => {
const expectedMultihash = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ'

let dir = [
content('cat-folder/cat.jpg')
]

http.api.node.files.add(dir, (err, res) => {
expect(err).to.not.exist()
const file = res[1]
expect(file.path).to.equal('test-folder/cat-folder')
expect(file.hash).to.equal(expectedMultihash)
cb()
})
}
], done)
})
Expand Down Expand Up @@ -142,6 +170,11 @@ describe('HTTP Gateway', () => {
}, (res) => {
expect(res.statusCode).to.equal(200)
expect(res.headers['content-type']).to.equal('image/jpeg')

let fileSignature = fileType(res.rawPayload)
expect(fileSignature.mime).to.equal('image/jpeg')
expect(fileSignature.ext).to.equal('jpg')

done()
})
})
Expand All @@ -155,6 +188,11 @@ describe('HTTP Gateway', () => {
}, (res) => {
expect(res.statusCode).to.equal(200)
expect(res.headers['content-type']).to.equal('text/html; charset=utf-8')

// check if the cat picture is in the payload as a way to check
// if this is an index of this directory
let listedFile = res.payload.match(/\/ipfs\/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ\/cat\.jpg/g)
expect(listedFile).to.have.lengthOf(1)
done()
})
})
Expand Down
Binary file added test/gateway/test-folder/cat-folder/cat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7cae803

Please sign in to comment.