Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 0b459fa

Browse files
committed
add remaining tests for .ls .lsReadableStream and .lsPullStream
1 parent 9b2fb0f commit 0b459fa

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed

src/files.js

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,5 +787,166 @@ module.exports = (common) => {
787787
})
788788
})
789789
})
790+
791+
describe('.lsReadableStream', () => {
792+
before((done) => {
793+
const content = (name) => ({
794+
path: `test-folder/${name}`,
795+
content: directory.files[name]
796+
})
797+
798+
const emptyDir = (name) => ({ path: `test-folder/${name}` })
799+
800+
const dirs = [
801+
content('pp.txt'),
802+
content('holmes.txt'),
803+
content('jungle.txt'),
804+
content('alice.txt'),
805+
emptyDir('empty-folder'),
806+
content('files/hello.txt'),
807+
content('files/ipfs.txt'),
808+
emptyDir('files/empty')
809+
]
810+
811+
ipfs.files.add(dirs, (err, res) => {
812+
expect(err).to.not.exist()
813+
const root = res[res.length - 1]
814+
815+
expect(root.path).to.equal('test-folder')
816+
expect(root.hash).to.equal(directory.cid)
817+
done()
818+
})
819+
})
820+
821+
it('with a base58 encoded CID', (done) => {
822+
const cid = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
823+
const stream = ipfs.lsReadableStream(cid)
824+
825+
stream.pipe(concat((files) => {
826+
expect(files).to.eql([
827+
{ depth: 1,
828+
name: 'alice.txt',
829+
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/alice.txt',
830+
size: 11696,
831+
hash: 'QmZyUEQVuRK3XV7L9Dk26pg6RVSgaYkiSTEdnT2kZZdwoi',
832+
type: 'file' },
833+
{ depth: 1,
834+
name: 'empty-folder',
835+
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/empty-folder',
836+
size: 4,
837+
hash: 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn',
838+
type: 'dir' },
839+
{ depth: 1,
840+
name: 'files',
841+
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files',
842+
size: 183,
843+
hash: 'QmZ25UfTqXGz9RsEJFg7HUAuBcmfx5dQZDXQd2QEZ8Kj74',
844+
type: 'dir' },
845+
{ depth: 1,
846+
name: 'holmes.txt',
847+
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/holmes.txt',
848+
size: 582072,
849+
hash: 'QmR4nFjTu18TyANgC65ArNWp5Yaab1gPzQ4D8zp7Kx3vhr',
850+
type: 'file' },
851+
{ depth: 1,
852+
name: 'jungle.txt',
853+
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/jungle.txt',
854+
size: 2305,
855+
hash: 'QmT6orWioMiSqXXPGsUi71CKRRUmJ8YkuueV2DPV34E9y9',
856+
type: 'file' },
857+
{ depth: 1,
858+
name: 'pp.txt',
859+
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/pp.txt',
860+
size: 4551,
861+
hash: 'QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn',
862+
type: 'file' }
863+
])
864+
done()
865+
}))
866+
})
867+
})
868+
869+
describe('.lsPullStream', () => {
870+
before((done) => {
871+
const content = (name) => ({
872+
path: `test-folder/${name}`,
873+
content: directory.files[name]
874+
})
875+
876+
const emptyDir = (name) => ({ path: `test-folder/${name}` })
877+
878+
const dirs = [
879+
content('pp.txt'),
880+
content('holmes.txt'),
881+
content('jungle.txt'),
882+
content('alice.txt'),
883+
emptyDir('empty-folder'),
884+
content('files/hello.txt'),
885+
content('files/ipfs.txt'),
886+
emptyDir('files/empty')
887+
]
888+
889+
ipfs.files.add(dirs, (err, res) => {
890+
expect(err).to.not.exist()
891+
const root = res[res.length - 1]
892+
893+
expect(root.path).to.equal('test-folder')
894+
expect(root.hash).to.equal(directory.cid)
895+
done()
896+
})
897+
})
898+
899+
it('with a base58 encoded CID', (done) => {
900+
const cid = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
901+
const stream = ipfs.lsPullStream(cid)
902+
903+
pull(
904+
stream,
905+
pull.collect((err, files) => {
906+
expect(err).to.not.exist()
907+
908+
expect(files).to.eql([
909+
{ depth: 1,
910+
name: 'alice.txt',
911+
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/alice.txt',
912+
size: 11696,
913+
hash: 'QmZyUEQVuRK3XV7L9Dk26pg6RVSgaYkiSTEdnT2kZZdwoi',
914+
type: 'file' },
915+
{ depth: 1,
916+
name: 'empty-folder',
917+
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/empty-folder',
918+
size: 4,
919+
hash: 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn',
920+
type: 'dir' },
921+
{ depth: 1,
922+
name: 'files',
923+
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files',
924+
size: 183,
925+
hash: 'QmZ25UfTqXGz9RsEJFg7HUAuBcmfx5dQZDXQd2QEZ8Kj74',
926+
type: 'dir' },
927+
{ depth: 1,
928+
name: 'holmes.txt',
929+
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/holmes.txt',
930+
size: 582072,
931+
hash: 'QmR4nFjTu18TyANgC65ArNWp5Yaab1gPzQ4D8zp7Kx3vhr',
932+
type: 'file' },
933+
{ depth: 1,
934+
name: 'jungle.txt',
935+
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/jungle.txt',
936+
size: 2305,
937+
hash: 'QmT6orWioMiSqXXPGsUi71CKRRUmJ8YkuueV2DPV34E9y9',
938+
type: 'file' },
939+
{ depth: 1,
940+
name: 'pp.txt',
941+
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/pp.txt',
942+
size: 4551,
943+
hash: 'QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn',
944+
type: 'file' }
945+
])
946+
done()
947+
})
948+
)
949+
})
950+
})
790951
})
791952
}

0 commit comments

Comments
 (0)