@@ -112,16 +112,17 @@ describe("cloudchamber create", () => {
112112 -v, --version Show version number [boolean]
113113
114114 OPTIONS
115- --json Return output as clean JSON [boolean] [default: false]
116- --image Image to use for your deployment [string]
117- --location Location on Cloudflare's network where your deployment will run [string]
118- --var Container environment variables [array]
119- --label Deployment labels [array]
120- --all-ssh-keys To add all SSH keys configured on your account to be added to this deployment, set this option to true [boolean]
121- --ssh-key-id ID of the SSH key to add to the deployment [array]
122- --vcpu Number of vCPUs to allocate to this deployment. [number]
123- --memory Amount of memory (GiB, MiB...) to allocate to this deployment. Ex: 4GiB. [string]
124- --ipv4 Include an IPv4 in the deployment [boolean]"
115+ --json Return output as clean JSON [boolean] [default: false]
116+ --image Image to use for your deployment [string]
117+ --location Location on Cloudflare's network where your deployment will run [string]
118+ --var Container environment variables [array]
119+ --label Deployment labels [array]
120+ --all-ssh-keys To add all SSH keys configured on your account to be added to this deployment, set this option to true [boolean]
121+ --ssh-key-id ID of the SSH key to add to the deployment [array]
122+ --instance-type Instance type to allocate to this deployment [choices: \\"dev\\", \\"basic\\", \\"standard\\"]
123+ --vcpu Number of vCPUs to allocate to this deployment. [number]
124+ --memory Amount of memory (GiB, MiB...) to allocate to this deployment. Ex: 4GiB. [string]
125+ --ipv4 Include an IPv4 in the deployment [boolean]"
125126 ` ) ;
126127 } ) ;
127128
@@ -170,6 +171,53 @@ describe("cloudchamber create", () => {
170171 ) ;
171172 } ) ;
172173
174+ it ( "should fail with a nice message when instance type is invalid" , async ( ) => {
175+ setIsTTY ( false ) ;
176+ fs . writeFileSync (
177+ "./wrangler.toml" ,
178+ TOML . stringify ( {
179+ name : "my-container" ,
180+ cloudchamber : {
181+ image : "hello:world" ,
182+ location : "sfo06" ,
183+ instance_type : "invalid" ,
184+ } ,
185+ } ) ,
186+
187+ "utf-8"
188+ ) ;
189+ await expect (
190+ runWrangler ( "cloudchamber create " )
191+ ) . rejects . toThrowErrorMatchingInlineSnapshot (
192+ ` [Error: Processing wrangler.toml configuration:
193+ - "instance_type" should be one of 'dev', 'basic', or 'standard', but got invalid]`
194+ ) ;
195+ } ) ;
196+
197+ it ( "should fail with a nice message when instance type is set with vcpu" , async ( ) => {
198+ setIsTTY ( false ) ;
199+ fs . writeFileSync (
200+ "./wrangler.toml" ,
201+ TOML . stringify ( {
202+ name : "my-container" ,
203+ cloudchamber : {
204+ image : "hello:world" ,
205+ location : "sfo06" ,
206+ vcpu : 2 ,
207+ instance_type : "dev" ,
208+ } ,
209+ } ) ,
210+
211+ "utf-8"
212+ ) ;
213+ await expect (
214+ runWrangler ( "cloudchamber create " )
215+ ) . rejects . toThrowErrorMatchingInlineSnapshot (
216+ ` [Error: Processing wrangler.toml configuration:
217+ - "cloudchamber" configuration should not set either "memory" or "vcpu" with "instance_type"]`
218+ ) ;
219+ } ) ;
220+
173221 it ( "should fail with a nice message when parameters are missing (json)" , async ( ) => {
174222 setIsTTY ( false ) ;
175223 setWranglerConfig ( { } ) ;
@@ -180,6 +228,18 @@ describe("cloudchamber create", () => {
180228 expect ( std . err ) . toMatchInlineSnapshot ( `""` ) ;
181229 } ) ;
182230
231+ it ( "should fail with a nice message when instance type is set with memory (json)" , async ( ) => {
232+ setIsTTY ( false ) ;
233+ setWranglerConfig ( { } ) ;
234+ await runWrangler (
235+ "cloudchamber create --image hello:world --location sfo06 --instance-type dev --memory 400GB --json"
236+ ) ;
237+ expect ( std . out ) . toMatchInlineSnapshot (
238+ `"{\\"error\\":\\"Field /\\"instance_type/\\" is mutually exclusive with /\\"memory/\\" and /\\"vcpu/\\". These fields cannot be set together.\\"}"`
239+ ) ;
240+ expect ( std . err ) . toMatchInlineSnapshot ( `""` ) ;
241+ } ) ;
242+
183243 it ( "should create deployment (detects no interactivity)" , async ( ) => {
184244 setIsTTY ( false ) ;
185245 setWranglerConfig ( { } ) ;
@@ -194,8 +254,31 @@ describe("cloudchamber create", () => {
194254 expect ( std . out ) . toMatchInlineSnapshot ( MOCK_DEPLOYMENTS_COMPLEX_RESPONSE ) ;
195255 } ) ;
196256
257+ it ( "should create deployment with instance type (detects no interactivity)" , async ( ) => {
258+ setIsTTY ( false ) ;
259+ setWranglerConfig ( { } ) ;
260+ mockGetKey ( ) ;
261+ msw . use (
262+ http . post (
263+ "*/deployments/v2" ,
264+ async ( { request } ) => {
265+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
266+ const r = ( await request . json ( ) ) as Record < string , any > ;
267+ expect ( r . instance_type ) . toEqual ( "dev" ) ;
268+ return HttpResponse . json ( { } ) ;
269+ } ,
270+ { once : true }
271+ )
272+ ) ;
273+ expect ( std . err ) . toMatchInlineSnapshot ( `""` ) ;
274+ await runWrangler (
275+ "cloudchamber create --image hello:world --location sfo06 --var HELLO:WORLD --var YOU:CONQUERED --instance-type dev --ipv4 true"
276+ ) ;
277+ expect ( std . out ) . toMatchInlineSnapshot ( `"{}"` ) ;
278+ } ) ;
279+
197280 it ( "properly reads wrangler config" , async ( ) => {
198- // This is very similar to the previous test except config
281+ // This is very similar to the previous tests except config
199282 // is set in wrangler and not overridden by the CLI
200283 setIsTTY ( false ) ;
201284 setWranglerConfig ( {
@@ -216,6 +299,38 @@ describe("cloudchamber create", () => {
216299 expect ( std . err ) . toMatchInlineSnapshot ( `""` ) ;
217300 } ) ;
218301
302+ it ( "properly reads wrangler config for instance type" , async ( ) => {
303+ // This is very similar to the previous tests except config
304+ // is set in wrangler and not overridden by the CLI
305+ setIsTTY ( false ) ;
306+ setWranglerConfig ( {
307+ image : "hello:world" ,
308+ ipv4 : true ,
309+ instance_type : "dev" ,
310+ location : "sfo06" ,
311+ } ) ;
312+ // if values are not read by wrangler, this mock won't work
313+ // since the wrangler command wont get the right parameters
314+ mockGetKey ( ) ;
315+ msw . use (
316+ http . post (
317+ "*/deployments/v2" ,
318+ async ( { request } ) => {
319+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
320+ const r = ( await request . json ( ) ) as Record < string , any > ;
321+ expect ( r . instance_type ) . toEqual ( "dev" ) ;
322+ return HttpResponse . json ( { } ) ;
323+ } ,
324+ { once : true }
325+ )
326+ ) ;
327+ await runWrangler (
328+ "cloudchamber create --var HELLO:WORLD --var YOU:CONQUERED"
329+ ) ;
330+ expect ( std . out ) . toMatchInlineSnapshot ( `"{}"` ) ;
331+ expect ( std . err ) . toMatchInlineSnapshot ( `""` ) ;
332+ } ) ;
333+
219334 it ( "should create deployment indicating ssh keys (detects no interactivity)" , async ( ) => {
220335 setIsTTY ( false ) ;
221336 setWranglerConfig ( {
0 commit comments