@@ -7,65 +7,48 @@ import { AzuriteContainer } from "./azurite-container";
77const IMAGE = getImage ( __dirname ) ;
88
99describe ( "Azurite" , { timeout : 240_000 } , ( ) => {
10- // uploadAndDownloadBlob {
1110 it ( "should upload and download blob with default credentials" , async ( ) => {
11+ // uploadAndDownloadBlob {
1212 await using container = await new AzuriteContainer ( IMAGE ) . start ( ) ;
1313
1414 const connectionString = container . getConnectionString ( ) ;
15- expect ( connectionString ) . toBeTruthy ( ) ;
16-
1715 const serviceClient = BlobServiceClient . fromConnectionString ( connectionString ) ;
1816 const containerClient = serviceClient . getContainerClient ( "test" ) ;
1917 await containerClient . createIfNotExists ( ) ;
18+
2019 const blobName = "hello.txt" ;
2120 const content = "Hello world!" ;
2221 await containerClient . uploadBlockBlob ( blobName , content , Buffer . byteLength ( content ) ) ;
2322
2423 const blobClient = containerClient . getBlockBlobClient ( blobName ) ;
25- const downloadResponse = await blobClient . download ( 0 , undefined ) ;
26-
27- const readable = downloadResponse . readableStreamBody as NodeJS . ReadableStream ;
28- expect ( readable ) . toBeTruthy ( ) ;
29-
30- readable . setEncoding ( "utf8" ) ;
31- let data = "" ;
32- for await ( const chunk of readable ) {
33- data += chunk ;
34- }
35-
36- expect ( data ) . toBe ( content ) ;
24+ const downloadBuffer = await blobClient . downloadToBuffer ( ) ;
25+ expect ( downloadBuffer . toString ( ) ) . toBe ( content ) ;
26+ // }
3727 } ) ;
38- // }
3928
40- // sendAndReceiveQueue {
4129 it ( "should add to queue with default credentials" , async ( ) => {
30+ // sendAndReceiveQueue {
4231 await using container = await new AzuriteContainer ( IMAGE ) . start ( ) ;
4332
4433 const connectionString = container . getConnectionString ( ) ;
45- expect ( connectionString ) . toBeTruthy ( ) ;
46-
4734 const serviceClient = QueueServiceClient . fromConnectionString ( connectionString ) ;
4835 const queueName = "test-queue" ;
4936 await serviceClient . createQueue ( queueName ) ;
5037
38+ const messageText = "Hello world!" ;
5139 const queueClient = serviceClient . getQueueClient ( queueName ) ;
52-
53- const message = "Hello world!" ;
54- await queueClient . sendMessage ( message ) ;
40+ await queueClient . sendMessage ( messageText ) ;
5541
5642 const messages = await queueClient . receiveMessages ( ) ;
57- expect ( messages . receivedMessageItems ) . toHaveLength ( 1 ) ;
58- expect ( messages . receivedMessageItems [ 0 ] . messageText ) . toBe ( message ) ;
43+ expect ( messages . receivedMessageItems ) . toMatchObject ( [ { messageText } ] ) ;
44+ // }
5945 } ) ;
60- // }
6146
62- // createAndInsertOnTable {
6347 it ( "should add to table with default credentials" , async ( ) => {
48+ // createAndInsertOnTable {
6449 await using container = await new AzuriteContainer ( IMAGE ) . start ( ) ;
6550
6651 const connectionString = container . getConnectionString ( ) ;
67- expect ( connectionString ) . toBeTruthy ( ) ;
68-
6952 const tableName = "person" ;
7053 const tableClient = TableClient . fromConnectionString ( connectionString , tableName , {
7154 allowInsecureConnection : true ,
@@ -79,16 +62,14 @@ describe("Azurite", { timeout: 240_000 }, () => {
7962 } ;
8063 await tableClient . createEntity ( entity ) ;
8164
82- const e1 = await tableClient . listEntities ( ) . next ( ) ;
83- expect ( e1 . value ) . toBeTruthy ( ) ;
84- expect ( e1 . value . name ) . toBe ( entity . name ) ;
65+ const nextEntity = await tableClient . listEntities ( ) . next ( ) ;
66+ expect ( nextEntity . value ) . toEqual ( expect . objectContaining ( entity ) ) ;
67+ // }
8568 } ) ;
86- // }
8769
88- // customCredentials {
8970 it ( "should be able to specify accountName and accountKey" , async ( ) => {
71+ // customCredentials {
9072 const accountName = "test-account" ;
91- // Account key must be base64 encoded
9273 const accountKey = Buffer . from ( "test-key" ) . toString ( "base64" ) ;
9374
9475 await using container = await new AzuriteContainer ( IMAGE )
@@ -98,6 +79,7 @@ describe("Azurite", { timeout: 240_000 }, () => {
9879
9980 const credentials = new StorageSharedKeyCredential ( accountName , accountKey ) ;
10081 const serviceClient = new BlobServiceClient ( container . getBlobEndpoint ( ) , credentials ) ;
82+ // }
10183
10284 const blobContainerName = "test" ;
10385 const containerClient = serviceClient . getContainerClient ( blobContainerName ) ;
@@ -107,13 +89,13 @@ describe("Azurite", { timeout: 240_000 }, () => {
10789 expect ( blobContainer . value ) . toBeTruthy ( ) ;
10890 expect ( blobContainer . value . name ) . toBe ( blobContainerName ) ;
10991 } ) ;
110- // }
11192
112- // customPorts {
11393 it ( "should be able to specify custom ports" , async ( ) => {
94+ // customPorts {
11495 const blobPort = 13000 ;
11596 const queuePort = 14000 ;
11697 const tablePort = 15000 ;
98+
11799 await using container = await new AzuriteContainer ( IMAGE )
118100 . withBlobPort ( { container : 10001 , host : blobPort } )
119101 . withQueuePort ( { container : 10002 , host : queuePort } )
@@ -123,6 +105,7 @@ describe("Azurite", { timeout: 240_000 }, () => {
123105 expect ( container . getBlobPort ( ) ) . toBe ( blobPort ) ;
124106 expect ( container . getQueuePort ( ) ) . toBe ( queuePort ) ;
125107 expect ( container . getTablePort ( ) ) . toBe ( tablePort ) ;
108+ // }
126109
127110 const connectionString = container . getConnectionString ( ) ;
128111 expect ( connectionString ) . toContain ( "13000" ) ;
@@ -133,17 +116,15 @@ describe("Azurite", { timeout: 240_000 }, () => {
133116 const containerClient = serviceClient . getContainerClient ( "test" ) ;
134117 await containerClient . createIfNotExists ( ) ;
135118 } ) ;
136- // }
137119
138- // inMemoryPersistence {
139120 it ( "should be able to use in-memory persistence" , async ( ) => {
121+ // inMemoryPersistence {
140122 await using container = await new AzuriteContainer ( IMAGE ) . withInMemoryPersistence ( ) . start ( ) ;
123+
141124 const blobName = "hello.txt" ;
142125
143126 {
144127 const connectionString = container . getConnectionString ( ) ;
145- expect ( connectionString ) . toBeTruthy ( ) ;
146-
147128 const serviceClient = BlobServiceClient . fromConnectionString ( connectionString ) ;
148129 const containerClient = serviceClient . getContainerClient ( "test" ) ;
149130 await containerClient . createIfNotExists ( ) ;
@@ -158,14 +139,12 @@ describe("Azurite", { timeout: 240_000 }, () => {
158139
159140 {
160141 const connectionString = container . getConnectionString ( ) ;
161- expect ( connectionString ) . toBeTruthy ( ) ;
162-
163142 const serviceClient = BlobServiceClient . fromConnectionString ( connectionString ) ;
164143 const containerClient = serviceClient . getContainerClient ( "test" ) ;
165144 const blobClient = containerClient . getBlockBlobClient ( blobName ) ;
166145 const blobExistsAfterRestart = await blobClient . exists ( ) ;
167146 expect ( blobExistsAfterRestart ) . toBeFalsy ( ) ;
168147 }
148+ // }
169149 } ) ;
170- // }
171150} ) ;
0 commit comments