@@ -47,15 +47,91 @@ describe("cloudchamber curl", () => {
4747
4848 OPTIONS
4949 -H, --header Add headers in the form of --header <name>:<value> [array]
50- -D , --data Add a JSON body to the request [string]
50+ -d , --data Add a JSON body to the request [string]
5151 -X, --method [string] [default: \\"GET\\"]
5252 -s, --silent Only output response [boolean]
5353 -v, --verbose Show version number [boolean]
5454 --use-stdin, --stdin Equivalent of using --data-binary @- in curl [boolean]"
5555 ` ) ;
5656 } ) ;
5757
58- it ( "should be able to use data flag" , async ( ) => {
58+ it ( "can send data with -d/--data" , async ( ) => {
59+ setIsTTY ( false ) ;
60+ setWranglerConfig ( { } ) ;
61+ msw . use (
62+ http . post ( "*/deployments/v2" , async ( { request } ) => {
63+ // verify we are hitting the expected url
64+ expect ( request . url ) . toEqual ( baseRequestUrl + "deployments/v2" ) ;
65+ // and that the request has the expected content
66+ expect ( await request . json ( ) ) . toEqual ( {
67+ image : "hello:world" ,
68+ location : "sfo06" ,
69+ ssh_public_key_ids : [ ] ,
70+ environment_variables : [
71+ {
72+ name : "HELLO" ,
73+ value : "WORLD" ,
74+ } ,
75+ {
76+ name : "YOU" ,
77+ value : "CONQUERED" ,
78+ } ,
79+ ] ,
80+ vcpu : 3 ,
81+ memory_mib : 400 ,
82+ network : {
83+ assign_ipv4 : "predefined" ,
84+ } ,
85+ } ) ;
86+ return HttpResponse . json ( MOCK_DEPLOYMENTS_COMPLEX [ 0 ] ) ;
87+ } )
88+ ) ;
89+
90+ // We need to stringify this for cross-platform compatibility
91+ const deployment = JSON . stringify ( {
92+ image : "hello:world" ,
93+ location : "sfo06" ,
94+ ssh_public_key_ids : [ ] ,
95+ environment_variables : [
96+ { name : "HELLO" , value : "WORLD" } ,
97+ { name : "YOU" , value : "CONQUERED" } ,
98+ ] ,
99+ vcpu : 3 ,
100+ memory_mib : 400 ,
101+ network : { assign_ipv4 : "predefined" } ,
102+ } ) ;
103+
104+ await runWrangler (
105+ "cloudchamber curl /deployments/v2 -X POST -d '" + deployment + "'"
106+ ) ;
107+ expect ( std . err ) . toMatchInlineSnapshot ( `""` ) ;
108+ expect ( std . out ) . toMatchInlineSnapshot ( `
109+ "{
110+ \\"id\\": \\"1\\",
111+ \\"type\\": \\"default\\",
112+ \\"created_at\\": \\"123\\",
113+ \\"account_id\\": \\"123\\",
114+ \\"vcpu\\": 4,
115+ \\"memory\\": \\"400MB\\",
116+ \\"memory_mib\\": 400,
117+ \\"version\\": 1,
118+ \\"image\\": \\"hello\\",
119+ \\"location\\": {
120+ \\"name\\": \\"sfo06\\",
121+ \\"enabled\\": true
122+ },
123+ \\"network\\": {
124+ \\"mode\\": \\"public\\",
125+ \\"ipv4\\": \\"1.1.1.1\\"
126+ },
127+ \\"placements_ref\\": \\"http://ref\\",
128+ \\"node_group\\": \\"metal\\"
129+ }
130+ "
131+ ` ) ;
132+ } ) ;
133+
134+ it ( "supports deprecated -D flag" , async ( ) => {
59135 setIsTTY ( false ) ;
60136 setWranglerConfig ( { } ) ;
61137 msw . use (
0 commit comments