@@ -2,7 +2,7 @@ import { Storage } from "@google-cloud/storage";
22import { setupServer } from "msw/node" ;
33import { ReadableStream } from "node:stream/web" ;
44import { getImage } from "../../../testcontainers/src/utils/test-helper" ;
5- import { CloudStorageEmulatorContainer , StartedCloudStorageEmulatorContainer } from "./cloudstorage-emulator-container" ;
5+ import { CloudStorageEmulatorContainer } from "./cloudstorage-emulator-container" ;
66
77const IMAGE = getImage ( __dirname , 1 ) ;
88
@@ -47,30 +47,38 @@ describe.sequential("CloudStorageEmulatorContainer", { timeout: 240_000 }, () =>
4747 server . close ( ) ;
4848 } ) ;
4949
50- // cloud-storage {
5150 it ( "should work using default version" , async ( ) => {
52- await using cloudstorageEmulatorContainer = await new CloudStorageEmulatorContainer ( IMAGE ) . start ( ) ;
51+ // cloudstorageExample {
52+ await using container = await new CloudStorageEmulatorContainer ( IMAGE ) . start ( ) ;
53+
54+ const storage = new Storage ( {
55+ projectId : "test-project" ,
56+ apiEndpoint : container . getExternalUrl ( ) ,
57+ } ) ;
58+
59+ await storage . createBucket ( "test-bucket" ) ;
60+ const [ buckets ] = await storage . getBuckets ( ) ;
5361
54- await checkCloudStorage ( cloudstorageEmulatorContainer ) ;
62+ expect ( buckets [ 0 ] . name ) . toBe ( "test-bucket" ) ;
63+ // }
5564 } ) ;
56- // }
5765
5866 it ( "should use the provided external URL" , async ( ) => {
59- await using cloudstorageEmulatorContainer = await new CloudStorageEmulatorContainer ( IMAGE )
67+ await using container = await new CloudStorageEmulatorContainer ( IMAGE )
6068 . withExternalURL ( "http://cdn.company.local" )
6169 . start ( ) ;
6270
63- expect ( cloudstorageEmulatorContainer ) . toBeDefined ( ) ;
64- expect ( cloudstorageEmulatorContainer . getExternalUrl ( ) ) . toBe ( "http://cdn.company.local" ) ;
71+ expect ( container ) . toBeDefined ( ) ;
72+ expect ( container . getExternalUrl ( ) ) . toBe ( "http://cdn.company.local" ) ;
6573 } ) ;
6674
6775 it ( "should be able update the external URL of running instance" , async ( ) => {
68- await using cloudstorageEmulatorContainer = await new CloudStorageEmulatorContainer ( IMAGE )
76+ await using container = await new CloudStorageEmulatorContainer ( IMAGE )
6977 . withExternalURL ( "http://cdn.company.local" )
7078 . start ( ) ;
7179
72- expect ( cloudstorageEmulatorContainer ) . toBeDefined ( ) ;
73- expect ( cloudstorageEmulatorContainer . getExternalUrl ( ) ) . toBe ( "http://cdn.company.local" ) ;
80+ expect ( container ) . toBeDefined ( ) ;
81+ expect ( container . getExternalUrl ( ) ) . toBe ( "http://cdn.company.local" ) ;
7482
7583 const executedRequests : Request [ ] = [ ] ;
7684
@@ -82,13 +90,13 @@ describe.sequential("CloudStorageEmulatorContainer", { timeout: 240_000 }, () =>
8290 }
8391 } ) ;
8492
85- await cloudstorageEmulatorContainer . updateExternalUrl ( "http://files.company.local" ) ;
93+ await container . updateExternalUrl ( "http://files.company.local" ) ;
8694
8795 expect ( executedRequests ) . toHaveLength ( 1 ) ;
8896
8997 const [ requestInfo ] = executedRequests ;
9098
91- const expectedRequestUrl = cloudstorageEmulatorContainer . getEmulatorEndpoint ( ) + "/_internal/config" ;
99+ const expectedRequestUrl = container . getEmulatorEndpoint ( ) + "/_internal/config" ;
92100 expect ( requestInfo . url ) . toContain ( expectedRequestUrl ) ;
93101 expect ( requestInfo . method ) . toBe ( "PUT" ) ;
94102
@@ -97,7 +105,7 @@ describe.sequential("CloudStorageEmulatorContainer", { timeout: 240_000 }, () =>
97105 const requestBodyAsJson = JSON . parse ( requestBody ) ;
98106 expect ( requestBodyAsJson ) . toEqual ( expect . objectContaining ( { externalUrl : "http://files.company.local" } ) ) ;
99107
100- expect ( cloudstorageEmulatorContainer . getExternalUrl ( ) ) . toBe ( "http://files.company.local" ) ;
108+ expect ( container . getExternalUrl ( ) ) . toBe ( "http://files.company.local" ) ;
101109 } ) ;
102110
103111 it ( "should use emulator endpoint as default external URL" , async ( ) => {
@@ -127,23 +135,4 @@ describe.sequential("CloudStorageEmulatorContainer", { timeout: 240_000 }, () =>
127135 expect ( container . getExternalUrl ( ) ) . toBe ( undefined ) ;
128136 expect ( ( await fetch ( `${ container . getEmulatorEndpoint ( ) } /_internal/healthcheck` ) ) . status ) . toBe ( 200 ) ;
129137 } ) ;
130-
131- async function checkCloudStorage ( cloudstorageEmulatorContainer : StartedCloudStorageEmulatorContainer ) {
132- expect ( cloudstorageEmulatorContainer ) . toBeDefined ( ) ;
133-
134- const cloudStorageClient = new Storage ( {
135- projectId : "test-project" ,
136- apiEndpoint : cloudstorageEmulatorContainer . getExternalUrl ( ) ,
137- } ) ;
138- expect ( cloudStorageClient ) . toBeDefined ( ) ;
139-
140- const createdBucket = await cloudStorageClient . createBucket ( "test-bucket" ) ;
141- expect ( createdBucket ) . toBeDefined ( ) ;
142-
143- const [ buckets ] = await cloudStorageClient . getBuckets ( ) ;
144- expect ( buckets ) . toBeDefined ( ) ;
145- expect ( buckets ) . toHaveLength ( 1 ) ;
146- const [ firstBucket ] = buckets ;
147- expect ( firstBucket . name ) . toBe ( "test-bucket" ) ;
148- }
149138} ) ;
0 commit comments