|
1 | 1 | /* eslint-env mocha */
|
| 2 | +/* eslint max-nested-callbacks: ["error", 8] */ |
2 | 3 | 'use strict'
|
3 | 4 |
|
4 |
| -const expect = require('chai').expect |
| 5 | +const test = require('interface-ipfs-core') |
5 | 6 | const FactoryClient = require('../factory/factory-client')
|
6 |
| -const fs = require('fs') |
7 |
| -const path = require('path') |
8 | 7 |
|
9 |
| -const testfile = fs.readFileSync(path.join(__dirname, '/../data/testfile.txt')) |
| 8 | +let fc |
10 | 9 |
|
11 |
| -describe('.pin', () => { |
12 |
| - let ipfs |
13 |
| - let fc |
14 |
| - |
15 |
| - before(function (done) { |
16 |
| - this.timeout(20 * 1000) // slow CI |
| 10 | +const common = { |
| 11 | + setup: function (callback) { |
17 | 12 | fc = new FactoryClient()
|
18 |
| - fc.spawnNode((err, node) => { |
19 |
| - expect(err).to.not.exist |
20 |
| - ipfs = node |
21 |
| - done() |
22 |
| - }) |
23 |
| - }) |
24 |
| - |
25 |
| - after((done) => { |
26 |
| - fc.dismantle(done) |
27 |
| - }) |
28 |
| - |
29 |
| - it('add file for testing', (done) => { |
30 |
| - const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' |
31 |
| - |
32 |
| - ipfs.files.add(testfile, (err, res) => { |
33 |
| - expect(err).to.not.exist |
34 |
| - |
35 |
| - expect(res).to.have.length(1) |
36 |
| - expect(res[0].hash).to.equal(expectedMultihash) |
37 |
| - expect(res[0].path).to.equal(expectedMultihash) |
38 |
| - done() |
39 |
| - }) |
40 |
| - }) |
41 |
| - |
42 |
| - it('.pin.remove', (done) => { |
43 |
| - ipfs.pin.remove('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {recursive: true}, (err, res) => { |
44 |
| - expect(err).to.not.exist |
45 |
| - expect(res).to.exist |
46 |
| - ipfs.pin.list('direct', (err, res) => { |
47 |
| - expect(err).to.not.exist |
48 |
| - expect(res).to.exist |
49 |
| - expect(res.Keys).to.be.empty |
50 |
| - done() |
51 |
| - }) |
52 |
| - }) |
53 |
| - }) |
54 |
| - |
55 |
| - it('.pin.add', (done) => { |
56 |
| - ipfs.pin.add('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {recursive: false}, (err, res) => { |
57 |
| - expect(err).to.not.exist |
58 |
| - expect(res.Pins[0]).to.be.equal('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') |
59 |
| - done() |
60 |
| - }) |
61 |
| - }) |
62 |
| - |
63 |
| - it('.pin.list', (done) => { |
64 |
| - ipfs.pin.list((err, res) => { |
65 |
| - expect(err).to.not.exist |
66 |
| - expect(res).to.exist |
67 |
| - done() |
68 |
| - }) |
69 |
| - }) |
70 |
| - |
71 |
| - it('.pin.list hash', (done) => { |
72 |
| - ipfs.pin.list({hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'}, (err, res) => { |
73 |
| - expect(err).to.not.exist |
74 |
| - expect(res).to.exist |
75 |
| - done() |
76 |
| - }) |
77 |
| - }) |
78 |
| - |
79 |
| - describe('promise', () => { |
80 |
| - it('.pin.add', () => { |
81 |
| - return ipfs.pin |
82 |
| - .add('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {recursive: false}) |
83 |
| - .then((res) => { |
84 |
| - expect(res.Pins[0]).to.be.equal('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') |
85 |
| - }) |
86 |
| - }) |
87 |
| - |
88 |
| - it('.pin.list', () => { |
89 |
| - return ipfs.pin.list() |
90 |
| - .then((res) => { |
91 |
| - expect(res).to.exist |
92 |
| - }) |
93 |
| - }) |
94 |
| - |
95 |
| - it('.pin.list hash', () => { |
96 |
| - return ipfs.pin.list({ |
97 |
| - hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' |
98 |
| - }) |
99 |
| - .then((res) => { |
100 |
| - expect(res).to.exist |
101 |
| - }) |
102 |
| - }) |
103 |
| - |
104 |
| - it('.pin.remove', () => { |
105 |
| - return ipfs.pin |
106 |
| - .remove('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {recursive: false}) |
107 |
| - .then((res) => { |
108 |
| - expect(res).to.exist |
109 |
| - return ipfs.pin.list('direct') |
110 |
| - }) |
111 |
| - .then((res) => { |
112 |
| - expect(res).to.exist |
113 |
| - expect(res.Keys).to.be.empty |
114 |
| - }) |
115 |
| - }) |
116 |
| - }) |
117 |
| -}) |
| 13 | + callback(null, fc) |
| 14 | + }, |
| 15 | + teardown: function (callback) { |
| 16 | + fc.dismantle(callback) |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +test.pin(common) |
0 commit comments