-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
610 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": minor | ||
--- | ||
|
||
feature: Implement `wrangler versions list` and `wrangler versions view` commands behind the `--experimental-gradual-rollouts` flag. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
packages/wrangler/src/__tests__/versions/versions.list.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { normalizeOutput } from "../../../e2e/helpers/normalize"; | ||
import { mockAccountId, mockApiToken } from "../helpers/mock-account-id"; | ||
import { mockConsoleMethods } from "../helpers/mock-console"; | ||
import { msw, mswListVersions } from "../helpers/msw"; | ||
import { runInTempDir } from "../helpers/run-in-tmp"; | ||
import { runWrangler } from "../helpers/run-wrangler"; | ||
import writeWranglerToml from "../helpers/write-wrangler-toml"; | ||
|
||
describe("versions list", () => { | ||
mockAccountId(); | ||
mockApiToken(); | ||
runInTempDir(); | ||
const std = mockConsoleMethods(); | ||
|
||
beforeEach(() => { | ||
msw.use(mswListVersions); | ||
}); | ||
|
||
describe("without wrangler.toml", () => { | ||
test("fails with no args", async () => { | ||
const result = runWrangler( | ||
"versions list --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).rejects.toMatchInlineSnapshot( | ||
`[Error: You need to provide a name when deploying a worker. Either pass it as a cli arg with \`--name <name>\` or in your config file as \`name = "<name>"\`]` | ||
); | ||
|
||
expect(std.out).toMatchInlineSnapshot(`""`); | ||
|
||
expect(normalizeOutput(std.err)).toMatchInlineSnapshot( | ||
`"X [ERROR] You need to provide a name when deploying a worker. Either pass it as a cli arg with \`--name <name>\` or in your config file as \`name = \\"<name>\\"\`"` | ||
); | ||
}); | ||
|
||
test("prints versions to stdout", async () => { | ||
const result = runWrangler( | ||
"versions list --name test-name --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).resolves.toBeUndefined(); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
"Version ID: 40000000-0000-0000-0000-000000000000 | ||
Created: 1/1/2021, 12:00:00 AM | ||
Author: Jean-Luc-Picard@federation.org | ||
Source: Upload | ||
Tag: - | ||
Message: - | ||
Version ID: 30000000-0000-0000-0000-000000000000 | ||
Created: 2/2/2021, 12:00:00 AM | ||
Author: Kathryn-Janeway@federation.org | ||
Source: Rollback | ||
Tag: - | ||
Message: Rolled back for this version | ||
Version ID: 20000000-0000-0000-0000-000000000000 | ||
Created: 2/3/2021, 12:00:00 AM | ||
Author: Kathryn-Janeway@federation.org | ||
Source: Wrangler 🤠 | ||
Tag: - | ||
Message: - | ||
Version ID: 10000000-0000-0000-0000-000000000000 | ||
Created: 1/4/2021, 12:00:00 AM | ||
Author: Jean-Luc-Picard@federation.org | ||
Source: Rollback | ||
Tag: - | ||
Message: - | ||
" | ||
`); | ||
|
||
expect(std.err).toMatchInlineSnapshot(`""`); | ||
}); | ||
}); | ||
|
||
describe("with wrangler.toml", () => { | ||
beforeEach(writeWranglerToml); | ||
|
||
test("prints versions to stdout", async () => { | ||
const result = runWrangler( | ||
"versions list --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).resolves.toBeUndefined(); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
"Version ID: 40000000-0000-0000-0000-000000000000 | ||
Created: 1/1/2021, 12:00:00 AM | ||
Author: Jean-Luc-Picard@federation.org | ||
Source: Upload | ||
Tag: - | ||
Message: - | ||
Version ID: 30000000-0000-0000-0000-000000000000 | ||
Created: 2/2/2021, 12:00:00 AM | ||
Author: Kathryn-Janeway@federation.org | ||
Source: Rollback | ||
Tag: - | ||
Message: Rolled back for this version | ||
Version ID: 20000000-0000-0000-0000-000000000000 | ||
Created: 2/3/2021, 12:00:00 AM | ||
Author: Kathryn-Janeway@federation.org | ||
Source: Wrangler 🤠 | ||
Tag: - | ||
Message: - | ||
Version ID: 10000000-0000-0000-0000-000000000000 | ||
Created: 1/4/2021, 12:00:00 AM | ||
Author: Jean-Luc-Picard@federation.org | ||
Source: Rollback | ||
Tag: - | ||
Message: - | ||
" | ||
`); | ||
|
||
expect(std.err).toMatchInlineSnapshot(`""`); | ||
}); | ||
}); | ||
}); |
200 changes: 200 additions & 0 deletions
200
packages/wrangler/src/__tests__/versions/versions.view.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
import { normalizeOutput } from "../../../e2e/helpers/normalize"; | ||
import { mockAccountId, mockApiToken } from "../helpers/mock-account-id"; | ||
import { mockConsoleMethods } from "../helpers/mock-console"; | ||
import { msw, mswGetVersion } from "../helpers/msw"; | ||
import { runInTempDir } from "../helpers/run-in-tmp"; | ||
import { runWrangler } from "../helpers/run-wrangler"; | ||
import writeWranglerToml from "../helpers/write-wrangler-toml"; | ||
|
||
describe("versions view", () => { | ||
mockAccountId(); | ||
mockApiToken(); | ||
runInTempDir(); | ||
const std = mockConsoleMethods(); | ||
|
||
beforeEach(() => { | ||
msw.use(mswGetVersion); | ||
}); | ||
|
||
describe("without wrangler.toml", () => { | ||
test("fails with no args", async () => { | ||
const result = runWrangler( | ||
"versions view --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).rejects.toMatchInlineSnapshot( | ||
`[Error: Not enough non-option arguments: got 0, need at least 1]` | ||
); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
" | ||
wrangler versions view <version-id> | ||
View the details of a specific version of your Worker [beta] | ||
Positionals: | ||
version-id The Worker Version ID to view [string] [required] | ||
Flags: | ||
-j, --experimental-json-config Experimental: Support wrangler.json [boolean] | ||
-c, --config Path to .toml configuration file [string] | ||
-e, --env Environment to use for operations and .env files [string] | ||
-h, --help Show help [boolean] | ||
-v, --version Show version number [boolean] | ||
Options: | ||
--name Name of the worker [string]" | ||
`); | ||
|
||
expect(normalizeOutput(std.err)).toMatchInlineSnapshot( | ||
`"X [ERROR] Not enough non-option arguments: got 0, need at least 1"` | ||
); | ||
}); | ||
|
||
test("fails with --name arg only", async () => { | ||
const result = runWrangler( | ||
"versions view --name test-name --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).rejects.toMatchInlineSnapshot( | ||
`[Error: Not enough non-option arguments: got 0, need at least 1]` | ||
); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
" | ||
wrangler versions view <version-id> | ||
View the details of a specific version of your Worker [beta] | ||
Positionals: | ||
version-id The Worker Version ID to view [string] [required] | ||
Flags: | ||
-j, --experimental-json-config Experimental: Support wrangler.json [boolean] | ||
-c, --config Path to .toml configuration file [string] | ||
-e, --env Environment to use for operations and .env files [string] | ||
-h, --help Show help [boolean] | ||
-v, --version Show version number [boolean] | ||
Options: | ||
--name Name of the worker [string]" | ||
`); | ||
|
||
expect(normalizeOutput(std.err)).toMatchInlineSnapshot( | ||
`"X [ERROR] Not enough non-option arguments: got 0, need at least 1"` | ||
); | ||
}); | ||
|
||
test("fails with positional version-id arg only", async () => { | ||
const result = runWrangler( | ||
"versions view 10000000-0000-0000-0000-000000000000 --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).rejects.toMatchInlineSnapshot( | ||
`[Error: You need to provide a name when deploying a worker. Either pass it as a cli arg with \`--name <name>\` or in your config file as \`name = "<name>"\`]` | ||
); | ||
|
||
expect(std.out).toMatchInlineSnapshot(`""`); | ||
|
||
expect(normalizeOutput(std.err)).toMatchInlineSnapshot( | ||
`"X [ERROR] You need to provide a name when deploying a worker. Either pass it as a cli arg with \`--name <name>\` or in your config file as \`name = \\"<name>\\"\`"` | ||
); | ||
}); | ||
|
||
test("succeeds with positional version-id arg and --name arg", async () => { | ||
const result = runWrangler( | ||
"versions view 10000000-0000-0000-0000-000000000000 --name test-name --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).resolves.toBeUndefined(); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
"Version ID: 10000000-0000-0000-0000-000000000000 | ||
Created: 1/1/2021, 12:00:00 AM | ||
Author: Jean-Luc-Picard@federation.org | ||
Source: Upload | ||
Tag: - | ||
Message: - | ||
" | ||
`); | ||
|
||
expect(normalizeOutput(std.err)).toMatchInlineSnapshot(`""`); | ||
}); | ||
}); | ||
|
||
describe("with wrangler.toml", () => { | ||
beforeEach(writeWranglerToml); | ||
|
||
test("fails with no args", async () => { | ||
const result = runWrangler( | ||
"versions view --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).rejects.toMatchInlineSnapshot( | ||
`[Error: Not enough non-option arguments: got 0, need at least 1]` | ||
); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
" | ||
wrangler versions view <version-id> | ||
View the details of a specific version of your Worker [beta] | ||
Positionals: | ||
version-id The Worker Version ID to view [string] [required] | ||
Flags: | ||
-j, --experimental-json-config Experimental: Support wrangler.json [boolean] | ||
-c, --config Path to .toml configuration file [string] | ||
-e, --env Environment to use for operations and .env files [string] | ||
-h, --help Show help [boolean] | ||
-v, --version Show version number [boolean] | ||
Options: | ||
--name Name of the worker [string]" | ||
`); | ||
|
||
expect(normalizeOutput(std.err)).toMatchInlineSnapshot( | ||
`"X [ERROR] Not enough non-option arguments: got 0, need at least 1"` | ||
); | ||
}); | ||
|
||
test("succeeds with positional version-id arg only", async () => { | ||
const result = runWrangler( | ||
"versions view 10000000-0000-0000-0000-000000000000 --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).resolves.toBeUndefined(); | ||
|
||
expect(std.out).toMatchInlineSnapshot(` | ||
"Version ID: 10000000-0000-0000-0000-000000000000 | ||
Created: 1/1/2021, 12:00:00 AM | ||
Author: Jean-Luc-Picard@federation.org | ||
Source: Upload | ||
Tag: - | ||
Message: - | ||
" | ||
`); | ||
|
||
expect(normalizeOutput(std.err)).toMatchInlineSnapshot(`""`); | ||
}); | ||
|
||
test("fails with non-existent version-id", async () => { | ||
const result = runWrangler( | ||
"versions view ffffffff-ffff-ffff-ffff-ffffffffffff --experimental-gradual-rollouts" | ||
); | ||
|
||
await expect(result).rejects.toMatchInlineSnapshot( | ||
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions/ffffffff-ffff-ffff-ffff-ffffffffffff) failed.]` | ||
); | ||
|
||
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(` | ||
"X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions/00000000-0000-0000-0000-000000000000) failed. | ||
If you think this is a bug, please open an issue at: | ||
https://github.com/cloudflare/workers-sdk/issues/new/choose" | ||
`); | ||
|
||
expect(normalizeOutput(std.err)).toMatchInlineSnapshot(`""`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.