Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
gateway initial tests.
  • Loading branch information
ya7ya committed Aug 31, 2017
commit 4292f4e3ddd694a5a5db7a8bad17360df2ae38a0
45 changes: 39 additions & 6 deletions test/gateway/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/* eslint-env mocha */
'use strict'

const fs = require('fs')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const API = require('../../src/http')
// const APIctl = require('ipfs-api')
const ncp = require('ncp').ncp
const path = require('path')
const clean = require('../utils/clean')
Expand All @@ -17,14 +15,18 @@ describe('HTTP GATEWAY', () => {
const repoTests = path.join(__dirname, '../repo-tests-run')

let http = {}
let gateway

before((done) => {
http.api = new API(repoTests)

ncp(repoExample, repoTests, (err) => {
expect(err).to.not.exist()

http.api.start(false, done)
http.api.start(false, () => {
gateway = http.api.server.select('Gateway')
done()
})
})
})

Expand All @@ -36,8 +38,39 @@ describe('HTTP GATEWAY', () => {
})
})

describe('## http-gateway spec tests', () => {
fs.readdirSync(path.join(__dirname, '/spec'))
.forEach((file) => require('./spec/' + file)(http))
describe('/ipfs/* route', () => {
it('returns 400 for request without argument', (done) => {
gateway.inject({
method: 'GET',
url: '/ipfs'
}, (res) => {
expect(res.statusCode).to.equal(400)
expect(res.result.Message).to.be.a('string')
done()
})
})

it('400 for request with invalid argument', (done) => {
gateway.inject({
method: 'GET',
url: '/ipfs/invalid'
}, (res) => {
expect(res.statusCode).to.equal(400)
expect(res.result.Message).to.be.a('string')
done()
})
})

it('valid hash', (done) => {
gateway.inject({
method: 'GET',
url: '/ipfs/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o'
}, (res) => {
expect(res.statusCode).to.equal(200)
expect(res.rawPayload).to.deep.equal(new Buffer('hello world' + '\n'))
expect(res.payload).to.equal('hello world' + '\n')
done()
})
})
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ya7ya there are not "gateway spec tests" you probably just have "tests" :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diasdavid ma bad, I'll fix that,
I'm looking at the gateway_test.go to try to port these tests to js-ipfs .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome! That's perfect @ya7ya :)

})
50 changes: 0 additions & 50 deletions test/gateway/spec/gateway.js

This file was deleted.