@@ -1130,7 +1130,12 @@ describe("wrangler", () => {
1130
1130
requests . count ++ ;
1131
1131
expect ( accountId ) . toEqual ( "some-account-id" ) ;
1132
1132
expect ( namespaceId ) . toEqual ( expectedNamespaceId ) ;
1133
- expect ( JSON . parse ( body as string ) ) . toEqual ( expectedKeyValues ) ;
1133
+ expect ( JSON . parse ( body as string ) ) . toEqual (
1134
+ expectedKeyValues . slice (
1135
+ ( requests . count - 1 ) * 5000 ,
1136
+ requests . count * 5000
1137
+ )
1138
+ ) ;
1134
1139
return null ;
1135
1140
}
1136
1141
) ;
@@ -1150,7 +1155,29 @@ describe("wrangler", () => {
1150
1155
`kv:bulk put --namespace-id some-namespace-id keys.json`
1151
1156
) ;
1152
1157
expect ( requests . count ) . toEqual ( 1 ) ;
1153
- expect ( std . out ) . toMatchInlineSnapshot ( `""` ) ;
1158
+ expect ( std . out ) . toMatchInlineSnapshot ( `"Success!"` ) ;
1159
+ expect ( std . warn ) . toMatchInlineSnapshot ( `""` ) ;
1160
+ expect ( std . err ) . toMatchInlineSnapshot ( `""` ) ;
1161
+ } ) ;
1162
+
1163
+ it ( "should put the key-values in batches of 5000 parsed from a file" , async ( ) => {
1164
+ const keyValues : KeyValue [ ] = new Array ( 12000 ) . fill ( {
1165
+ key : "someKey1" ,
1166
+ value : "someValue1" ,
1167
+ } ) ;
1168
+ writeFileSync ( "./keys.json" , JSON . stringify ( keyValues ) ) ;
1169
+ const requests = mockPutRequest ( "some-namespace-id" , keyValues ) ;
1170
+ await runWrangler (
1171
+ `kv:bulk put --namespace-id some-namespace-id keys.json`
1172
+ ) ;
1173
+ expect ( requests . count ) . toEqual ( 3 ) ;
1174
+ expect ( std . out ) . toMatchInlineSnapshot ( `
1175
+ "Uploaded 0 of 12000.
1176
+ Uploaded 5000 of 12000.
1177
+ Uploaded 10000 of 12000.
1178
+ Uploaded 12000 of 12000.
1179
+ Success!"
1180
+ ` ) ;
1154
1181
expect ( std . warn ) . toMatchInlineSnapshot ( `""` ) ;
1155
1182
expect ( std . err ) . toMatchInlineSnapshot ( `""` ) ;
1156
1183
} ) ;
0 commit comments