|
| 1 | +/* eslint-env mocha */ |
| 2 | +/* globals apiClients */ |
| 3 | +'use strict' |
| 4 | + |
| 5 | +const expect = require('chai').expect |
| 6 | +const isNode = require('detect-node') |
| 7 | +const fs = require('fs') |
| 8 | + |
| 9 | +const path = require('path') |
| 10 | +const streamEqual = require('stream-equal') |
| 11 | + |
| 12 | +let testfile |
| 13 | +let testfileBig |
| 14 | + |
| 15 | +if (isNode) { |
| 16 | + testfile = fs.readFileSync(path.join(__dirname, '/../testfile.txt')) |
| 17 | + testfileBig = fs.createReadStream(path.join(__dirname, '/../15mb.random'), { bufferSize: 128 }) |
| 18 | +} else { |
| 19 | + testfile = require('raw!../testfile.txt') |
| 20 | +} |
| 21 | + |
| 22 | +describe('.get', () => { |
| 23 | + it('get with no compression args', (done) => { |
| 24 | + apiClients.a |
| 25 | + .get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { |
| 26 | + expect(err).to.not.exist |
| 27 | + |
| 28 | + let buf = '' |
| 29 | + res |
| 30 | + .on('error', (err) => { |
| 31 | + expect(err).to.not.exist |
| 32 | + }) |
| 33 | + .on('data', (data) => { |
| 34 | + buf += data |
| 35 | + }) |
| 36 | + .on('end', () => { |
| 37 | + expect(buf).to.contain(testfile.toString()) |
| 38 | + done() |
| 39 | + }) |
| 40 | + }) |
| 41 | + }) |
| 42 | + |
| 43 | + it('get with archive true', (done) => { |
| 44 | + apiClients.a |
| 45 | + .get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', true, (err, res) => { |
| 46 | + expect(err).to.not.exist |
| 47 | + |
| 48 | + let buf = '' |
| 49 | + res |
| 50 | + .on('error', (err) => { |
| 51 | + expect(err).to.not.exist |
| 52 | + }) |
| 53 | + .on('data', (data) => { |
| 54 | + buf += data |
| 55 | + }) |
| 56 | + .on('end', () => { |
| 57 | + expect(buf).to.contain(testfile.toString()) |
| 58 | + done() |
| 59 | + }) |
| 60 | + }) |
| 61 | + }) |
| 62 | + |
| 63 | + it('get with compression level', (done) => { |
| 64 | + apiClients.a |
| 65 | + .get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', true, 1, (err, res) => { |
| 66 | + expect(err).to.not.exist |
| 67 | + |
| 68 | + let buf = '' |
| 69 | + res |
| 70 | + .on('error', (err) => { |
| 71 | + expect(err).to.not.exist |
| 72 | + }) |
| 73 | + .on('data', (data) => { |
| 74 | + buf += data |
| 75 | + }) |
| 76 | + .on('end', () => { |
| 77 | + expect(buf).to.contain(testfile.toString()) |
| 78 | + done() |
| 79 | + }) |
| 80 | + }) |
| 81 | + }) |
| 82 | + |
| 83 | + it.skip('get BIG file', (done) => { |
| 84 | + if (!isNode) { |
| 85 | + return done() |
| 86 | + } |
| 87 | + |
| 88 | + apiClients.a.get('Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq', (err, res) => { |
| 89 | + expect(err).to.not.exist |
| 90 | + |
| 91 | + // Do not blow out the memory of nodejs :) |
| 92 | + streamEqual(res, testfileBig, (err, equal) => { |
| 93 | + expect(err).to.not.exist |
| 94 | + expect(equal).to.be.true |
| 95 | + done() |
| 96 | + }) |
| 97 | + }) |
| 98 | + }) |
| 99 | + |
| 100 | + describe('promise', () => { |
| 101 | + it.skip('get', (done) => { |
| 102 | + return apiClients.a.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') |
| 103 | + .then((res) => { |
| 104 | + let buf = '' |
| 105 | + res |
| 106 | + .on('error', (err) => { |
| 107 | + throw err |
| 108 | + }) |
| 109 | + .on('data', (data) => { |
| 110 | + buf += data |
| 111 | + }) |
| 112 | + .on('end', () => { |
| 113 | + expect(buf).to.contain(testfile.toString()) |
| 114 | + done() |
| 115 | + }) |
| 116 | + }) |
| 117 | + }) |
| 118 | + }) |
| 119 | +}) |
0 commit comments