2
2
/* eslint max-nested-callbacks: ["error", 8] */
3
3
'use strict'
4
4
5
- const { Buffer } = require ( 'buffer' )
6
5
const chai = require ( 'chai' )
7
6
chai . use ( require ( 'dirty-chai' ) )
8
7
const assert = chai . assert
9
8
const expect = chai . expect
10
9
const all = require ( 'async-iterator-all' )
10
+ const { utf8Encoder } = require ( '../src/utils' )
11
11
12
12
const Key = require ( 'interface-datastore' ) . Key
13
13
const MemoryStore = require ( 'interface-datastore' ) . MemoryDatastore
@@ -18,7 +18,7 @@ describe('MountStore', () => {
18
18
it ( 'put - no mount' , async ( ) => {
19
19
const m = new MountStore ( [ ] )
20
20
try {
21
- await m . put ( new Key ( 'hello' ) , Buffer . from ( 'foo' ) )
21
+ await m . put ( new Key ( 'hello' ) , utf8Encoder . encode ( 'foo' ) )
22
22
assert ( false , 'Failed to throw error on no mount' )
23
23
} catch ( err ) {
24
24
expect ( err ) . to . be . an ( 'Error' )
@@ -31,7 +31,7 @@ describe('MountStore', () => {
31
31
prefix : new Key ( 'cool' )
32
32
} ] )
33
33
try {
34
- await m . put ( new Key ( '/fail/hello' ) , Buffer . from ( 'foo' ) )
34
+ await m . put ( new Key ( '/fail/hello' ) , utf8Encoder . encode ( 'foo' ) )
35
35
assert ( false , 'Failed to throw error on wrong mount' )
36
36
} catch ( err ) {
37
37
expect ( err ) . to . be . an ( 'Error' )
@@ -45,7 +45,7 @@ describe('MountStore', () => {
45
45
prefix : new Key ( 'cool' )
46
46
} ] )
47
47
48
- const val = Buffer . from ( 'hello' )
48
+ const val = utf8Encoder . encode ( 'hello' )
49
49
await m . put ( new Key ( '/cool/hello' ) , val )
50
50
const res = await mds . get ( new Key ( '/hello' ) )
51
51
expect ( res ) . to . eql ( val )
@@ -58,7 +58,7 @@ describe('MountStore', () => {
58
58
prefix : new Key ( 'cool' )
59
59
} ] )
60
60
61
- const val = Buffer . from ( 'hello' )
61
+ const val = utf8Encoder . encode ( 'hello' )
62
62
await mds . put ( new Key ( '/hello' ) , val )
63
63
const res = await m . get ( new Key ( '/cool/hello' ) )
64
64
expect ( res ) . to . eql ( val )
@@ -71,7 +71,7 @@ describe('MountStore', () => {
71
71
prefix : new Key ( 'cool' )
72
72
} ] )
73
73
74
- const val = Buffer . from ( 'hello' )
74
+ const val = utf8Encoder . encode ( 'hello' )
75
75
await mds . put ( new Key ( '/hello' ) , val )
76
76
const exists = await m . has ( new Key ( '/cool/hello' ) )
77
77
expect ( exists ) . to . eql ( true )
@@ -84,7 +84,7 @@ describe('MountStore', () => {
84
84
prefix : new Key ( 'cool' )
85
85
} ] )
86
86
87
- const val = Buffer . from ( 'hello' )
87
+ const val = utf8Encoder . encode ( 'hello' )
88
88
await m . put ( new Key ( '/cool/hello' ) , val )
89
89
await m . delete ( new Key ( '/cool/hello' ) )
90
90
let exists = await m . has ( new Key ( '/cool/hello' ) )
@@ -100,7 +100,7 @@ describe('MountStore', () => {
100
100
prefix : new Key ( 'cool' )
101
101
} ] )
102
102
103
- const val = Buffer . from ( 'hello' )
103
+ const val = utf8Encoder . encode ( 'hello' )
104
104
await m . put ( new Key ( '/cool/hello' ) , val )
105
105
const res = await all ( m . query ( { prefix : '/cool' } ) )
106
106
expect ( res ) . to . eql ( [ { key : new Key ( '/cool/hello' ) , value : val } ] )
0 commit comments