@@ -16,6 +16,7 @@ const index = require('../lib/entry-index')
16
16
17
17
const KEY = 'foo'
18
18
const KEYHASH = index . _hashKey ( KEY )
19
+ const BUCKET = index . _bucketPath ( CACHE , KEY )
19
20
const DIGEST = 'deadbeef'
20
21
const ALGO = 'whatnot'
21
22
@@ -31,8 +32,7 @@ test('basic insertion', function (t) {
31
32
time : entry . time ,
32
33
metadata : 'foo'
33
34
} , 'formatted entry returned' )
34
- const bucket = path . join ( CACHE , 'index' , KEYHASH )
35
- return fs . readFileAsync ( bucket , 'utf8' )
35
+ return fs . readFileAsync ( BUCKET , 'utf8' )
36
36
} ) . then ( data => {
37
37
t . equal ( data [ 0 ] , '{' , 'first entry starts with a {, not \\n' )
38
38
const entry = JSON . parse ( data )
@@ -53,8 +53,7 @@ test('inserts additional entries into existing key', function (t) {
53
53
) . then ( ( ) => (
54
54
index . insert ( CACHE , KEY , DIGEST , { metadata : 2 } )
55
55
) ) . then ( ( ) => {
56
- const bucket = path . join ( CACHE , 'index' , KEYHASH )
57
- return fs . readFileAsync ( bucket , 'utf8' )
56
+ return fs . readFileAsync ( BUCKET , 'utf8' )
58
57
} ) . then ( data => {
59
58
const entries = data . split ( '\n' ) . map ( JSON . parse )
60
59
entries . forEach ( function ( e ) { delete e . time } )
@@ -84,8 +83,7 @@ test('separates entries even if one is corrupted', function (t) {
84
83
return index . insert (
85
84
CACHE , KEY , DIGEST
86
85
) . then ( ( ) => {
87
- const bucket = path . join ( CACHE , 'index' , KEYHASH )
88
- return fs . readFileAsync ( bucket , 'utf8' )
86
+ return fs . readFileAsync ( BUCKET , 'utf8' )
89
87
} ) . then ( data => {
90
88
const entry = JSON . parse ( data . split ( '\n' ) [ 4 ] )
91
89
delete entry . time
@@ -101,8 +99,7 @@ test('optional arbitrary metadata', function (t) {
101
99
return index . insert (
102
100
CACHE , KEY , DIGEST , { metadata : metadata }
103
101
) . then ( ( ) => {
104
- const bucket = path . join ( CACHE , 'index' , KEYHASH )
105
- return fs . readFileAsync ( bucket , 'utf8' )
102
+ return fs . readFileAsync ( BUCKET , 'utf8' )
106
103
} ) . then ( data => {
107
104
const entry = JSON . parse ( data )
108
105
delete entry . time
@@ -119,8 +116,7 @@ test('key case-sensitivity', function (t) {
119
116
index . insert ( CACHE , KEY , DIGEST ) ,
120
117
index . insert ( CACHE , KEY . toUpperCase ( ) , DIGEST )
121
118
) . then ( ( ) => {
122
- const bucket = path . join ( CACHE , 'index' , KEYHASH )
123
- return fs . readFileAsync ( bucket , 'utf8' )
119
+ return fs . readFileAsync ( BUCKET , 'utf8' )
124
120
} ) . then ( data => {
125
121
const entries = data . split ( '\n' ) . map ( JSON . parse ) . sort ( e => (
126
122
e . key === KEY
@@ -148,7 +144,7 @@ test('hash conflict in same bucket', function (t) {
148
144
) . then ( ( ) => (
149
145
index . insert ( CACHE , CONFLICTING , DIGEST )
150
146
) ) . then ( ( ) => {
151
- const bucket = path . join ( CACHE , 'index' , index . _hashKey ( NEWKEY ) )
147
+ const bucket = index . _bucketPath ( CACHE , NEWKEY )
152
148
return fs . readFileAsync ( bucket , 'utf8' )
153
149
} ) . then ( data => {
154
150
const entries = data . split ( '\n' ) . map ( JSON . parse )
@@ -165,11 +161,10 @@ test('hash conflict in same bucket', function (t) {
165
161
166
162
test ( 'path-breaking characters' , function ( t ) {
167
163
const newKey = ';;!registry\nhttps://registry.npmjs.org/back \\ slash@Cool™?'
168
- const newHash = index . _hashKey ( newKey )
169
164
return index . insert (
170
165
CACHE , newKey , DIGEST
171
166
) . then ( ( ) => {
172
- const bucket = path . join ( CACHE , 'index' , newHash )
167
+ const bucket = index . _bucketPath ( CACHE , newKey )
173
168
return fs . readFileAsync ( bucket , 'utf8' )
174
169
} ) . then ( data => {
175
170
const entry = JSON . parse ( data )
@@ -186,11 +181,10 @@ test('extremely long keys', function (t) {
186
181
for ( let i = 0 ; i < 10000 ; i ++ ) {
187
182
newKey += i
188
183
}
189
- const newHash = index . _hashKey ( newKey )
190
184
return index . insert (
191
185
CACHE , newKey , DIGEST
192
186
) . then ( ( ) => {
193
- const bucket = path . join ( CACHE , 'index' , newHash )
187
+ const bucket = index . _bucketPath ( CACHE , newKey )
194
188
return fs . readFileAsync ( bucket , 'utf8' )
195
189
} ) . then ( data => {
196
190
const entry = JSON . parse ( data )
0 commit comments