1
- import { describe , beforeAll , afterAll } from "vitest" ;
1
+ import {
2
+ describe ,
3
+ beforeAll ,
4
+ afterAll ,
5
+ it ,
6
+ expect ,
7
+ vi ,
8
+ afterEach ,
9
+ } from "vitest" ;
2
10
import driver from "../../src/drivers/azure-storage-blob" ;
3
11
import { testDriver } from "./utils" ;
4
12
import { BlobServiceClient } from "@azure/storage-blob" ;
5
13
import { ChildProcess , exec } from "node:child_process" ;
14
+ import { ContainerClient } from "@azure/storage-blob" ;
6
15
7
16
describe . skip ( "drivers: azure-storage-blob" , ( ) => {
8
17
let azuriteProcess : ChildProcess ;
@@ -17,10 +26,65 @@ describe.skip("drivers: azure-storage-blob", () => {
17
26
afterAll ( ( ) => {
18
27
azuriteProcess . kill ( 9 ) ;
19
28
} ) ;
29
+ afterEach ( ( ) => {
30
+ vi . restoreAllMocks ( ) ;
31
+ } ) ;
20
32
testDriver ( {
21
33
driver : driver ( {
22
34
connectionString : "UseDevelopmentStorage=true" ,
23
35
accountName : "local" ,
24
36
} ) ,
37
+ additionalTests ( ctx ) {
38
+ it ( "natively supports depth in getKeys" , async ( ) => {
39
+ const spy = vi . spyOn ( ContainerClient . prototype , "listBlobsByHierarchy" ) ;
40
+
41
+ await ctx . storage . setItem ( "depth-test/key0" , "boop" ) ;
42
+ await ctx . storage . setItem ( "depth-test/depth0/key1" , "boop" ) ;
43
+ await ctx . storage . setItem ( "depth-test/depth0/depth1/key2" , "boop" ) ;
44
+ await ctx . storage . setItem ( "depth-test/depth0/depth1/key3" , "boop" ) ;
45
+
46
+ expect (
47
+ (
48
+ await ctx . driver . getKeys ( '' , {
49
+ maxDepth : 1 ,
50
+ } )
51
+ ) . sort ( )
52
+ ) . toMatchObject ( [ "depth-test:key0" ] ) ;
53
+
54
+ // assert that the underlying blob storage was only called upto 1 depth
55
+ // to confirm the native filtering was used
56
+ expect ( spy ) . toHaveBeenCalledTimes ( 2 ) ;
57
+ expect ( spy ) . toHaveBeenCalledWith ( ":" , {
58
+ // azure actually mutates `options` and sets `prefix` to
59
+ // `undefined` even though we pass it in as `""`. it seems this
60
+ // assertion works by reference, so we see the mutated value
61
+ prefix : undefined ,
62
+ } ) ;
63
+ expect ( spy ) . toHaveBeenCalledWith ( ":" , {
64
+ prefix : "depth-test:" ,
65
+ } ) ;
66
+
67
+ spy . mockClear ( ) ;
68
+
69
+ expect (
70
+ (
71
+ await ctx . driver . getKeys ( '' , {
72
+ maxDepth : 2 ,
73
+ } )
74
+ ) . sort ( )
75
+ ) . toMatchObject ( [ "depth-test:depth0:key1" , "depth-test:key0" ] ) ;
76
+
77
+ expect ( spy ) . toHaveBeenCalledTimes ( 3 ) ;
78
+ expect ( spy ) . toHaveBeenCalledWith ( ":" , {
79
+ prefix : undefined ,
80
+ } ) ;
81
+ expect ( spy ) . toHaveBeenCalledWith ( ":" , {
82
+ prefix : "depth-test:" ,
83
+ } ) ;
84
+ expect ( spy ) . toHaveBeenCalledWith ( ":" , {
85
+ prefix : "depth-test:depth0:" ,
86
+ } ) ;
87
+ } ) ;
88
+ } ,
25
89
} ) ;
26
90
} ) ;
0 commit comments