Skip to content

Commit

Permalink
Implement --json in versions list commands (#5412)
Browse files Browse the repository at this point in the history
  • Loading branch information
RamIdeas committed Mar 28, 2024
1 parent c90dd6b commit 3e5a932
Show file tree
Hide file tree
Showing 10 changed files with 563 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-mayflies-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

feature: adds the `--json` option to `wrangler deployments list --experimental-versions`, `wrangler deployments status --experimental-versions`, `wrangler versions list --experimental-versions` and `wrangler versions view --experimental-versions` which will format the output as clean JSON. The ` --experimental-versions` flag is still required for these commands.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ describe("deployments list", () => {

describe("without wrangler.toml", () => {
test("fails with no args", async () => {
const result = runWrangler(
"deployments list --experimental-gradual-rollouts"
);
const result = runWrangler("deployments list --experimental-versions");

await expect(result).rejects.toMatchInlineSnapshot(
`[Error: You need to provide a name of your worker. Either pass it as a cli arg with \`--name <name>\` or in your config file as \`name = "<name>"\`]`
Expand All @@ -33,7 +31,7 @@ describe("deployments list", () => {

test("prints deployments to stdout", async () => {
const result = runWrangler(
"deployments list --name test-name --experimental-gradual-rollouts"
"deployments list --name test-name --experimental-versions"
);

await expect(result).resolves.toBeUndefined();
Expand All @@ -47,7 +45,7 @@ describe("deployments list", () => {
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(90%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Expand All @@ -61,7 +59,7 @@ describe("deployments list", () => {
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(80%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Expand All @@ -75,7 +73,7 @@ describe("deployments list", () => {
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(70%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Expand All @@ -89,7 +87,7 @@ describe("deployments list", () => {
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(60%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Expand All @@ -99,15 +97,107 @@ describe("deployments list", () => {

expect(std.err).toMatchInlineSnapshot(`""`);
});

test("prints deployments to stdout as --json", async () => {
const result = runWrangler(
"deployments list --name test-name --json --experimental-versions"
);

await expect(result).resolves.toBeUndefined();

expect(std.out).toMatchInlineSnapshot(`
"[
{
\\"id\\": \\"Galaxy-Class-test-name\\",
\\"source\\": \\"api\\",
\\"strategy\\": \\"percentage\\",
\\"author_email\\": \\"Jean-Luc-Picard@federation.org\\",
\\"created_on\\": \\"2021-01-04T00:00:00.000000Z\\",
\\"annotations\\": {
\\"workers/triggered_by\\": \\"rollback\\",
\\"workers/rollback_from\\": \\"MOCK-DEPLOYMENT-ID-2222\\"
},
\\"versions\\": [
{
\\"version_id\\": \\"10000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 10
},
{
\\"version_id\\": \\"20000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 90
}
]
},
{
\\"id\\": \\"Galaxy-Class-test-name\\",
\\"source\\": \\"wrangler\\",
\\"strategy\\": \\"percentage\\",
\\"author_email\\": \\"Jean-Luc-Picard@federation.org\\",
\\"created_on\\": \\"2021-01-01T00:00:00.000000Z\\",
\\"annotations\\": {
\\"workers/triggered_by\\": \\"upload\\"
},
\\"versions\\": [
{
\\"version_id\\": \\"10000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 20
},
{
\\"version_id\\": \\"20000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 80
}
]
},
{
\\"id\\": \\"Intrepid-Class-test-name\\",
\\"source\\": \\"wrangler\\",
\\"strategy\\": \\"percentage\\",
\\"author_email\\": \\"Kathryn-Janeway@federation.org\\",
\\"created_on\\": \\"2021-02-02T00:00:00.000000Z\\",
\\"annotations\\": {
\\"workers/triggered_by\\": \\"rollback\\",
\\"workers/rollback_from\\": \\"MOCK-DEPLOYMENT-ID-1111\\",
\\"workers/message\\": \\"Rolled back for this version\\"
},
\\"versions\\": [
{
\\"version_id\\": \\"10000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 30
},
{
\\"version_id\\": \\"20000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 70
}
]
},
{
\\"id\\": \\"3mEgaU1T-Intrepid-someThing-test-name\\",
\\"source\\": \\"wrangler\\",
\\"strategy\\": \\"percentage\\",
\\"author_email\\": \\"Kathryn-Janeway@federation.org\\",
\\"created_on\\": \\"2021-02-03T00:00:00.000000Z\\",
\\"versions\\": [
{
\\"version_id\\": \\"10000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 40
},
{
\\"version_id\\": \\"20000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 60
}
]
}
]
"
`);
});
});

describe("with wrangler.toml", () => {
beforeEach(writeWranglerToml);

test("prints deployments to stdout", async () => {
const result = runWrangler(
"deployments list --experimental-gradual-rollouts"
);
const result = runWrangler("deployments list --experimental-versions");

await expect(result).resolves.toBeUndefined();

Expand All @@ -120,7 +210,7 @@ describe("deployments list", () => {
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(90%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Expand All @@ -134,7 +224,7 @@ describe("deployments list", () => {
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(80%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Expand All @@ -148,7 +238,7 @@ describe("deployments list", () => {
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(70%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Expand All @@ -162,7 +252,7 @@ describe("deployments list", () => {
Created: 2021-01-01T00:00:00.000Z
Tag: -
Message: -
(60%) 20000000-0000-0000-0000-000000000000
Created: 2021-01-01T00:00:00.000Z
Tag: -
Expand All @@ -172,5 +262,99 @@ describe("deployments list", () => {

expect(std.err).toMatchInlineSnapshot(`""`);
});

test("prints deployments to stdout as --json", async () => {
const result = runWrangler(
"deployments list --json --experimental-versions"
);

await expect(result).resolves.toBeUndefined();

expect(std.out).toMatchInlineSnapshot(`
"[
{
\\"id\\": \\"Galaxy-Class-test-name\\",
\\"source\\": \\"api\\",
\\"strategy\\": \\"percentage\\",
\\"author_email\\": \\"Jean-Luc-Picard@federation.org\\",
\\"created_on\\": \\"2021-01-04T00:00:00.000000Z\\",
\\"annotations\\": {
\\"workers/triggered_by\\": \\"rollback\\",
\\"workers/rollback_from\\": \\"MOCK-DEPLOYMENT-ID-2222\\"
},
\\"versions\\": [
{
\\"version_id\\": \\"10000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 10
},
{
\\"version_id\\": \\"20000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 90
}
]
},
{
\\"id\\": \\"Galaxy-Class-test-name\\",
\\"source\\": \\"wrangler\\",
\\"strategy\\": \\"percentage\\",
\\"author_email\\": \\"Jean-Luc-Picard@federation.org\\",
\\"created_on\\": \\"2021-01-01T00:00:00.000000Z\\",
\\"annotations\\": {
\\"workers/triggered_by\\": \\"upload\\"
},
\\"versions\\": [
{
\\"version_id\\": \\"10000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 20
},
{
\\"version_id\\": \\"20000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 80
}
]
},
{
\\"id\\": \\"Intrepid-Class-test-name\\",
\\"source\\": \\"wrangler\\",
\\"strategy\\": \\"percentage\\",
\\"author_email\\": \\"Kathryn-Janeway@federation.org\\",
\\"created_on\\": \\"2021-02-02T00:00:00.000000Z\\",
\\"annotations\\": {
\\"workers/triggered_by\\": \\"rollback\\",
\\"workers/rollback_from\\": \\"MOCK-DEPLOYMENT-ID-1111\\",
\\"workers/message\\": \\"Rolled back for this version\\"
},
\\"versions\\": [
{
\\"version_id\\": \\"10000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 30
},
{
\\"version_id\\": \\"20000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 70
}
]
},
{
\\"id\\": \\"3mEgaU1T-Intrepid-someThing-test-name\\",
\\"source\\": \\"wrangler\\",
\\"strategy\\": \\"percentage\\",
\\"author_email\\": \\"Kathryn-Janeway@federation.org\\",
\\"created_on\\": \\"2021-02-03T00:00:00.000000Z\\",
\\"versions\\": [
{
\\"version_id\\": \\"10000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 40
},
{
\\"version_id\\": \\"20000000-0000-0000-0000-000000000000\\",
\\"percentage\\": 60
}
]
}
]
"
`);
});
});
});

0 comments on commit 3e5a932

Please sign in to comment.