Skip to content

Commit 86801da

Browse files
committed
test: verify metadata is stored in UnixFS
update test to check metadata (mode/mtime) is properly sent to API and stored in UnixFS structure, retrievable via DAG API
1 parent b0bd0d5 commit 86801da

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

test/files.spec.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import * as dagPB from '@ipld/dag-pb'
44
import { expect } from 'aegir/chai'
55
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
6+
import { UnixFS } from 'ipfs-unixfs'
67
import { factory } from './utils/factory.js'
78
import type { KuboRPCClient } from '../src/index.js'
89

@@ -19,23 +20,35 @@ describe('.add', function () {
1920

2021
after(async function () { return f.clean() })
2122

22-
it('should ignore metadata until https://github.com/ipfs/go-ipfs/issues/6920 is implemented', async function () {
23+
it('should send metadata when provided (affects CID) but not return it until issue #6920 is resolved', async function () {
2324
const data = uint8ArrayFromString('some data')
2425
const result = await ipfs.add(data, {
2526
// @ts-expect-error missing field
2627
mode: 0o600,
2728
mtime: {
2829
secs: 1000,
29-
nsecs: 0
30+
nsecs: 500
3031
}
3132
})
3233

34+
// Metadata is not returned in response yet (issue #6920)
3335
expect(result).to.not.have.property('mode')
3436
expect(result).to.not.have.property('mtime')
3537
expect(result).to.have.property('cid')
3638

3739
const { cid } = result
3840
expect(cid).to.have.property('code', dagPB.code)
39-
expect(cid.toString()).to.equal('QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS')
41+
// CID is different because metadata is now properly sent to the API
42+
expect(cid.toString()).to.equal('QmPDB1sHH2FNqwJm2A6747uf6JUZyEB2cnNFRPz2uzjoDZ')
43+
44+
// Verify metadata is stored in UnixFS structure via DAG API
45+
const dagNode = await ipfs.dag.get(cid)
46+
const pbData = dagNode.value.Data
47+
const unixfs = UnixFS.unmarshal(pbData)
48+
49+
// Verify mode and mtime are stored
50+
expect(unixfs.mode).to.equal(0o600)
51+
expect(unixfs.mtime?.secs).to.equal(1000n)
52+
expect(unixfs.mtime?.nsecs).to.equal(500)
4053
})
4154
})

0 commit comments

Comments
 (0)