Skip to content

Commit 8b87750

Browse files
committed
Rename cloudchamber curl -D option to -d to match real curl
-D is supported as a hidden/deprecated alias
1 parent 6c9b742 commit 8b87750

File tree

2 files changed

+87
-3
lines changed

2 files changed

+87
-3
lines changed

packages/wrangler/src/__tests__/cloudchamber/curl.test.ts

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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(

packages/wrangler/src/cloudchamber/curl.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export function yargsCurl(args: yargs.Argv<CommonYargsOptions>) {
2222
.option("data", {
2323
type: "string",
2424
describe: "Add a JSON body to the request",
25+
alias: "d",
26+
})
27+
.option("data-deprecated", {
28+
type: "string",
29+
hidden: true,
2530
alias: "D",
2631
})
2732
.option("method", {
@@ -67,6 +72,7 @@ async function requestFromCmd(
6772
method: string;
6873
header: (string | number)[] | undefined;
6974
data?: string;
75+
dataDeprecated?: string;
7076
silent?: boolean;
7177
verbose?: boolean;
7278
useStdin?: boolean;
@@ -92,6 +98,8 @@ async function requestFromCmd(
9298
}),
9399
{ "coordinator-request-id": requestId }
94100
);
101+
102+
const data = args.data ?? args.dataDeprecated;
95103
const res = await request(OpenAPI, {
96104
url: args.path,
97105
method: args.method as
@@ -102,7 +110,7 @@ async function requestFromCmd(
102110
| "OPTIONS"
103111
| "HEAD"
104112
| "PATCH",
105-
body: args.data ? JSON.parse(args.data) : undefined,
113+
body: data ? JSON.parse(data) : undefined,
106114
mediaType: "application/json",
107115
headers: headers,
108116
});

0 commit comments

Comments
 (0)