@@ -12,7 +12,6 @@ import { runInTempDir } from "./helpers/run-in-tmp";
1212import { runWrangler } from "./helpers/run-wrangler" ;
1313import type {
1414 PutNotificationRequestBody ,
15- R2BucketInfo ,
1615 R2EventableOperation ,
1716 R2EventType ,
1817} from "../r2/helpers" ;
@@ -92,14 +91,15 @@ describe("r2", () => {
9291 Manage R2 buckets
9392
9493 COMMANDS
95- wrangler r2 bucket create <name> Create a new R2 bucket
96- wrangler r2 bucket update Update bucket state
97- wrangler r2 bucket list List R2 buckets
98- wrangler r2 bucket delete <name> Delete an R2 bucket
99- wrangler r2 bucket sippy Manage Sippy incremental migration on an R2 bucket
100- wrangler r2 bucket notification Manage event notification rules for an R2 bucket
101- wrangler r2 bucket domain Manage custom domains for an R2 bucket
102- wrangler r2 bucket dev-url Manage public access via the r2.dev URL for an R2 bucket
94+ wrangler r2 bucket create <name> Create a new R2 bucket
95+ wrangler r2 bucket update Update bucket state
96+ wrangler r2 bucket list List R2 buckets
97+ wrangler r2 bucket info <bucket> Get information about an R2 bucket
98+ wrangler r2 bucket delete <bucket> Delete an R2 bucket
99+ wrangler r2 bucket sippy Manage Sippy incremental migration on an R2 bucket
100+ wrangler r2 bucket notification Manage event notification rules for an R2 bucket
101+ wrangler r2 bucket domain Manage custom domains for an R2 bucket
102+ wrangler r2 bucket dev-url Manage public access via the r2.dev URL for an R2 bucket
103103
104104 GLOBAL FLAGS
105105 -j, --experimental-json-config Experimental: support wrangler.json [boolean]
@@ -128,14 +128,15 @@ describe("r2", () => {
128128 Manage R2 buckets
129129
130130 COMMANDS
131- wrangler r2 bucket create <name> Create a new R2 bucket
132- wrangler r2 bucket update Update bucket state
133- wrangler r2 bucket list List R2 buckets
134- wrangler r2 bucket delete <name> Delete an R2 bucket
135- wrangler r2 bucket sippy Manage Sippy incremental migration on an R2 bucket
136- wrangler r2 bucket notification Manage event notification rules for an R2 bucket
137- wrangler r2 bucket domain Manage custom domains for an R2 bucket
138- wrangler r2 bucket dev-url Manage public access via the r2.dev URL for an R2 bucket
131+ wrangler r2 bucket create <name> Create a new R2 bucket
132+ wrangler r2 bucket update Update bucket state
133+ wrangler r2 bucket list List R2 buckets
134+ wrangler r2 bucket info <bucket> Get information about an R2 bucket
135+ wrangler r2 bucket delete <bucket> Delete an R2 bucket
136+ wrangler r2 bucket sippy Manage Sippy incremental migration on an R2 bucket
137+ wrangler r2 bucket notification Manage event notification rules for an R2 bucket
138+ wrangler r2 bucket domain Manage custom domains for an R2 bucket
139+ wrangler r2 bucket dev-url Manage public access via the r2.dev URL for an R2 bucket
139140
140141 GLOBAL FLAGS
141142 -j, --experimental-json-config Experimental: support wrangler.json [boolean]
@@ -148,9 +149,15 @@ describe("r2", () => {
148149
149150 describe ( "list" , ( ) => {
150151 it ( "should list buckets & check request inputs" , async ( ) => {
151- const expectedBuckets : R2BucketInfo [ ] = [
152- { name : "bucket-1-local-once" , creation_date : "01-01-2001" } ,
153- { name : "bucket-2-local-once" , creation_date : "01-01-2001" } ,
152+ const mockBuckets = [
153+ {
154+ name : "bucket-1-local-once" ,
155+ creation_date : "01-01-2001" ,
156+ } ,
157+ {
158+ name : "bucket-2-local-once" ,
159+ creation_date : "01-01-2001" ,
160+ } ,
154161 ] ;
155162 msw . use (
156163 http . get (
@@ -161,27 +168,65 @@ describe("r2", () => {
161168 expect ( await request . text ( ) ) . toEqual ( "" ) ;
162169 return HttpResponse . json (
163170 createFetchResult ( {
164- buckets : [
165- {
166- name : "bucket-1-local-once" ,
167- creation_date : "01-01-2001" ,
168- } ,
169- {
170- name : "bucket-2-local-once" ,
171- creation_date : "01-01-2001" ,
172- } ,
173- ] ,
171+ buckets : mockBuckets ,
174172 } )
175173 ) ;
176174 } ,
177175 { once : true }
178176 )
179177 ) ;
180- await runWrangler ( "r2 bucket list" ) ;
181178
182- expect ( std . err ) . toMatchInlineSnapshot ( `""` ) ;
183- const buckets = JSON . parse ( std . out ) ;
184- expect ( buckets ) . toEqual ( expectedBuckets ) ;
179+ await runWrangler ( `r2 bucket list` ) ;
180+ expect ( std . out ) . toMatchInlineSnapshot ( `
181+ "Listing buckets...
182+ name: bucket-1-local-once
183+ creation_date: 01-01-2001
184+
185+ name: bucket-2-local-once
186+ creation_date: 01-01-2001"
187+ ` ) ;
188+ } ) ;
189+ } ) ;
190+
191+ describe ( "info" , ( ) => {
192+ it ( "should get information for the given bucket" , async ( ) => {
193+ const bucketName = "my-bucket" ;
194+ const bucketInfo = {
195+ name : bucketName ,
196+ creation_date : "01-01-2001" ,
197+ location : "WNAM" ,
198+ storage_class : "Standard" ,
199+ } ;
200+
201+ msw . use (
202+ http . get (
203+ "*/accounts/:accountId/r2/buckets/:bucketName" ,
204+ async ( { params } ) => {
205+ const { accountId, bucketName : bucketParam } = params ;
206+ expect ( accountId ) . toEqual ( "some-account-id" ) ;
207+ expect ( bucketParam ) . toEqual ( bucketName ) ;
208+ return HttpResponse . json (
209+ createFetchResult ( {
210+ ...bucketInfo ,
211+ } )
212+ ) ;
213+ } ,
214+ { once : true }
215+ ) ,
216+ http . post ( "*/graphql" , async ( ) => {
217+ return HttpResponse . json ( createFetchResult ( { } ) ) ;
218+ } )
219+ ) ;
220+ await runWrangler ( `r2 bucket info ${ bucketName } ` ) ;
221+ expect ( std . out ) . toMatchInlineSnapshot ( `
222+ "Getting info for 'my-bucket'...
223+ name: my-bucket
224+ created: 01-01-2001
225+ location: WNAM
226+ default_storage_class: Standard
227+ object_count: 0
228+ bucket_size: 0 B"
229+ ` ) ;
185230 } ) ;
186231 } ) ;
187232
@@ -475,12 +520,12 @@ binding = \\"testBucket\\""
475520 ) ;
476521 expect ( std . out ) . toMatchInlineSnapshot ( `
477522 "
478- wrangler r2 bucket delete <name >
523+ wrangler r2 bucket delete <bucket >
479524
480525 Delete an R2 bucket
481526
482527 POSITIONALS
483- name The name of the bucket to delete [string] [required]
528+ bucket The name of the bucket to delete [string] [required]
484529
485530 GLOBAL FLAGS
486531 -j, --experimental-json-config Experimental: support wrangler.json [boolean]
@@ -515,12 +560,12 @@ binding = \\"testBucket\\""
515560 ) ;
516561 expect ( std . out ) . toMatchInlineSnapshot ( `
517562 "
518- wrangler r2 bucket delete <name >
563+ wrangler r2 bucket delete <bucket >
519564
520565 Delete an R2 bucket
521566
522567 POSITIONALS
523- name The name of the bucket to delete [string] [required]
568+ bucket The name of the bucket to delete [string] [required]
524569
525570 GLOBAL FLAGS
526571 -j, --experimental-json-config Experimental: support wrangler.json [boolean]
0 commit comments