09525d860cdc38e552cc4d377297ac5d3e2b201b
[arvados-workbench2.git] / src / services / collection-files-service / collection-manifest-parser.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { parseKeepManifestText, parseKeepManifestStream, stringifyKeepManifest } from "./collection-manifest-parser";
6
7 describe('parseKeepManifestText', () => {
8     it('should parse text into streams', () => {
9         const manifestText = `. 930625b054ce894ac40596c3f5a0d947+33 0:0:a 0:0:b 0:33:output.txt\n./c d41d8cd98f00b204e9800998ecf8427e+0 0:0:d\n`;
10         const manifest = parseKeepManifestText(manifestText);
11         expect(manifest[0].name).toBe('');
12         expect(manifest[1].name).toBe('/c');
13         expect(manifest.length).toBe(2);
14     });
15 });
16
17 describe('parseKeepManifestStream', () => {
18     const streamText = './c 930625b054ce894ac40596c3f5a0d947+33 0:0:a 0:0:b 0:33:output.txt';
19     const stream = parseKeepManifestStream(streamText);
20
21     it('should parse stream name', () => {
22         expect(stream.name).toBe('/c');
23     });
24     it('should parse stream locators', () => {
25         expect(stream.locators).toEqual(['930625b054ce894ac40596c3f5a0d947+33']);
26     });
27     it('should parse stream files', () => {
28         expect(stream.files).toEqual([
29             { name: 'a', position: '0', size: 0 },
30             { name: 'b', position: '0', size: 0 },
31             { name: 'output.txt', position: '0', size: 33 },
32         ]);
33     });
34 });
35
36 test('stringifyKeepManifest', () => {
37     const manifestText = `. 930625b054ce894ac40596c3f5a0d947+33 0:22:test.txt\n./c/user/results 930625b054ce894ac40596c3f5a0d947+33 0:0:a 0:0:b 0:33:output.txt\n`;
38     const manifest = parseKeepManifestText(manifestText);
39     expect(stringifyKeepManifest(manifest)).toEqual(`. 930625b054ce894ac40596c3f5a0d947+33 0:22:test.txt\n./c/user/results 930625b054ce894ac40596c3f5a0d947+33 0:0:a 0:0:b 0:33:output.txt\n`);
40 });