Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 97 additions & 33 deletions packages/wrangler/src/__tests__/cloudchamber/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,6 @@ import { runWrangler } from "../helpers/run-wrangler";
import { mockAccount, setWranglerConfig } from "./utils";
import type { SSHPublicKeyItem } from "@cloudflare/containers-shared";

const MOCK_DEPLOYMENTS_COMPLEX_RESPONSE = `
"{
\\"id\\": \\"1\\",
\\"type\\": \\"default\\",
\\"created_at\\": \\"123\\",
\\"account_id\\": \\"123\\",
\\"vcpu\\": 4,
\\"memory\\": \\"400MB\\",
\\"memory_mib\\": 400,
\\"version\\": 1,
\\"image\\": \\"hello\\",
\\"location\\": {
\\"name\\": \\"sfo06\\",
\\"enabled\\": true
},
\\"network\\": {
\\"mode\\": \\"public\\",
\\"ipv4\\": \\"1.1.1.1\\"
},
\\"placements_ref\\": \\"http://ref\\",
\\"node_group\\": \\"metal\\"
}"
`;

function mockDeploymentPost() {
msw.use(
http.post(
Expand Down Expand Up @@ -103,7 +79,7 @@ describe("cloudchamber create", () => {
expect(std.out).toMatchInlineSnapshot(`
"wrangler cloudchamber create

Create a new deployment
Create a new deployment [alpha]

GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
Expand Down Expand Up @@ -230,7 +206,32 @@ describe("cloudchamber create", () => {
);
// so testing the actual UI will be harder than expected
// TODO: think better on how to test UI actions
expect(std.out).toMatchInlineSnapshot(MOCK_DEPLOYMENTS_COMPLEX_RESPONSE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look inline to me 🤔

expect(std.out).toMatchInlineSnapshot(`
"
⛅️ wrangler x.x.x
──────────────────
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the changes, the output was valid JSON, was that a req?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I'll find out.

\\"id\\": \\"1\\",
\\"type\\": \\"default\\",
\\"created_at\\": \\"123\\",
\\"account_id\\": \\"123\\",
\\"vcpu\\": 4,
\\"memory\\": \\"400MB\\",
\\"memory_mib\\": 400,
\\"version\\": 1,
\\"image\\": \\"hello\\",
\\"location\\": {
\\"name\\": \\"sfo06\\",
\\"enabled\\": true
},
\\"network\\": {
\\"mode\\": \\"public\\",
\\"ipv4\\": \\"1.1.1.1\\"
},
\\"placements_ref\\": \\"http://ref\\",
\\"node_group\\": \\"metal\\"
}"
`);
});

it("should create deployment with instance type (detects no interactivity)", async () => {
Expand All @@ -253,7 +254,12 @@ describe("cloudchamber create", () => {
await runWrangler(
"cloudchamber create --image hello:world --location sfo06 --var HELLO:WORLD --var YOU:CONQUERED --instance-type lite --ipv4 true"
);
expect(std.out).toMatchInlineSnapshot(`"{}"`);
expect(std.out).toMatchInlineSnapshot(`
"
⛅️ wrangler x.x.x
──────────────────
{}"
`);
});

it("properly reads wrangler config", async () => {
Expand All @@ -274,7 +280,32 @@ describe("cloudchamber create", () => {
await runWrangler(
"cloudchamber create --var HELLO:WORLD --var YOU:CONQUERED"
);
expect(std.out).toMatchInlineSnapshot(MOCK_DEPLOYMENTS_COMPLEX_RESPONSE);
expect(std.out).toMatchInlineSnapshot(`
"
⛅️ wrangler x.x.x
──────────────────
{
\\"id\\": \\"1\\",
\\"type\\": \\"default\\",
\\"created_at\\": \\"123\\",
\\"account_id\\": \\"123\\",
\\"vcpu\\": 4,
\\"memory\\": \\"400MB\\",
\\"memory_mib\\": 400,
\\"version\\": 1,
\\"image\\": \\"hello\\",
\\"location\\": {
\\"name\\": \\"sfo06\\",
\\"enabled\\": true
},
\\"network\\": {
\\"mode\\": \\"public\\",
\\"ipv4\\": \\"1.1.1.1\\"
},
\\"placements_ref\\": \\"http://ref\\",
\\"node_group\\": \\"metal\\"
}"
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});

Expand Down Expand Up @@ -306,7 +337,12 @@ describe("cloudchamber create", () => {
await runWrangler(
"cloudchamber create --var HELLO:WORLD --var YOU:CONQUERED"
);
expect(std.out).toMatchInlineSnapshot(`"{}"`);
expect(std.out).toMatchInlineSnapshot(`
"
⛅️ wrangler x.x.x
──────────────────
{}"
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});

Expand Down Expand Up @@ -349,7 +385,32 @@ describe("cloudchamber create", () => {
await runWrangler(
"cloudchamber create --image hello:world --location sfo06 --var HELLO:WORLD --var YOU:CONQUERED --all-ssh-keys --ipv4"
);
expect(std.out).toMatchInlineSnapshot(MOCK_DEPLOYMENTS_COMPLEX_RESPONSE);
expect(std.out).toMatchInlineSnapshot(`
"
⛅️ wrangler x.x.x
──────────────────
{
\\"id\\": \\"1\\",
\\"type\\": \\"default\\",
\\"created_at\\": \\"123\\",
\\"account_id\\": \\"123\\",
\\"vcpu\\": 4,
\\"memory\\": \\"400MB\\",
\\"memory_mib\\": 400,
\\"version\\": 1,
\\"image\\": \\"hello\\",
\\"location\\": {
\\"name\\": \\"sfo06\\",
\\"enabled\\": true
},
\\"network\\": {
\\"mode\\": \\"public\\",
\\"ipv4\\": \\"1.1.1.1\\"
},
\\"placements_ref\\": \\"http://ref\\",
\\"node_group\\": \\"metal\\"
}"
`);
});

it("can't create deployment due to lack of fields (json)", async () => {
Expand All @@ -364,8 +425,11 @@ describe("cloudchamber create", () => {
// so testing the actual UI will be harder than expected
// TODO: think better on how to test UI actions
expect(std.out).toMatchInlineSnapshot(`
"
If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
`);
"
⛅️ wrangler x.x.x
──────────────────

If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("cloudchamber curl", () => {
expect(helpStd.out).toMatchInlineSnapshot(`
"wrangler cloudchamber curl <path>

Send a request to an arbitrary Cloudchamber endpoint
Send a request to an arbitrary Cloudchamber endpoint [alpha]

POSITIONALS
path [string] [required] [default: \\"/\\"]
Expand Down
18 changes: 12 additions & 6 deletions packages/wrangler/src/__tests__/cloudchamber/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ describe("cloudchamber delete", () => {
expect(std.out).toMatchInlineSnapshot(`
"wrangler cloudchamber delete [deploymentId]

Delete an existing deployment that is running in the Cloudflare edge
Delete an existing deployment that is running in the Cloudflare edge [alpha]

POSITIONALS
deploymentId deployment you want to delete [string]
deploymentId Deployment you want to delete [string]

GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
Expand Down Expand Up @@ -62,7 +62,10 @@ describe("cloudchamber delete", () => {
// TODO: think better on how to test UI actions
expect(std.out).toMatchInlineSnapshot(
`
"{
"
⛅️ wrangler x.x.x
──────────────────
{
\\"id\\": \\"1\\",
\\"type\\": \\"default\\",
\\"created_at\\": \\"123\\",
Expand Down Expand Up @@ -98,8 +101,11 @@ describe("cloudchamber delete", () => {
// so testing the actual UI will be harder than expected
// TODO: think better on how to test UI actions
expect(std.out).toMatchInlineSnapshot(`
"
If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
`);
"
⛅️ wrangler x.x.x
──────────────────

If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
`);
});
});
74 changes: 50 additions & 24 deletions packages/wrangler/src/__tests__/cloudchamber/images.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ describe("cloudchamber image", () => {
expect(std.out).toMatchInlineSnapshot(`
"wrangler cloudchamber registries

Configure registries via Cloudchamber

COMMANDS
wrangler cloudchamber registries configure Configure Cloudchamber to pull from specific registries
wrangler cloudchamber registries credentials [domain] get a temporary password for a specific domain
wrangler cloudchamber registries remove [domain] removes the registry at the given domain
wrangler cloudchamber registries list list registries configured for this account
Configure registries via Cloudchamber [alpha]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this wanted ?

-> % wrangler r2 
wrangler r2

📦 Manage R2 buckets & objects

COMMANDS
  wrangler r2 object  Manage R2 objects
  wrangler r2 bucket  Manage R2 buckets
  wrangler r2 sql     Send queries and manage R2 SQL [open-beta]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I missed a namespace definition here...


GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
Expand Down Expand Up @@ -73,10 +67,13 @@ describe("cloudchamber image", () => {
// so testing the actual UI will be harder than expected
// TODO: think better on how to test UI actions
expect(std.out).toMatchInlineSnapshot(`
"{
\\"domain\\": \\"docker.io\\"
}"
`);
"
⛅️ wrangler x.x.x
──────────────────
Comment on lines +70 to +72
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question about JSON output...

{
\\"domain\\": \\"docker.io\\"
}"
`);
});

it("should create an image registry (no interactivity)", async () => {
Expand All @@ -100,7 +97,12 @@ describe("cloudchamber image", () => {
expect(std.err).toMatchInlineSnapshot(`""`);
// so testing the actual UI will be harder than expected
// TODO: think better on how to test UI actions
expect(std.out).toMatchInlineSnapshot(`"jwt"`);
expect(std.out).toMatchInlineSnapshot(`
"
⛅️ wrangler x.x.x
──────────────────
jwt"
`);
});

it("should remove an image registry (no interactivity)", async () => {
Expand All @@ -118,7 +120,12 @@ describe("cloudchamber image", () => {
);
await runWrangler("cloudchamber registries remove docker.io");
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.out).toMatchInlineSnapshot(`"{}"`);
expect(std.out).toMatchInlineSnapshot(`
"
⛅️ wrangler x.x.x
──────────────────
{}"
`);
});

it("should list registries (no interactivity)", async () => {
Expand All @@ -145,7 +152,10 @@ describe("cloudchamber image", () => {
await runWrangler("cloudchamber registries list");
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.out).toMatchInlineSnapshot(`
"[
"
⛅️ wrangler x.x.x
──────────────────
[
{
\\"public_key\\": \\"\\",
\\"domain\\": \\"docker.io\\"
Expand Down Expand Up @@ -182,8 +192,6 @@ describe("cloudchamber image list", () => {
expect(std.out).toMatchInlineSnapshot(`
"wrangler cloudchamber images list

List images in the Cloudflare managed registry

GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
Expand Down Expand Up @@ -224,7 +232,10 @@ describe("cloudchamber image list", () => {
await runWrangler("cloudchamber images list");
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.out).toMatchInlineSnapshot(`
"REPOSITORY TAG
"
⛅️ wrangler x.x.x
──────────────────
REPOSITORY TAG
one hundred
one ten
two thousand
Expand Down Expand Up @@ -260,7 +271,10 @@ describe("cloudchamber image list", () => {
await runWrangler("cloudchamber images list --filter '^two$'");
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.out).toMatchInlineSnapshot(`
"REPOSITORY TAG
"
⛅️ wrangler x.x.x
──────────────────
REPOSITORY TAG
two thousand
two twenty"
`);
Expand Down Expand Up @@ -294,7 +308,10 @@ describe("cloudchamber image list", () => {
await runWrangler("cloudchamber images list");
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.out).toMatchInlineSnapshot(`
"REPOSITORY TAG
"
⛅️ wrangler x.x.x
──────────────────
REPOSITORY TAG
one hundred
one ten
two thousand
Expand Down Expand Up @@ -330,7 +347,10 @@ describe("cloudchamber image list", () => {
await runWrangler("cloudchamber images list --json");
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.out).toMatchInlineSnapshot(`
"[
"
⛅️ wrangler x.x.x
──────────────────
[
{
\\"name\\": \\"one\\",
\\"tags\\": [
Expand Down Expand Up @@ -384,7 +404,10 @@ describe("cloudchamber image list", () => {
await runWrangler("cloudchamber images list --json");
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.out).toMatchInlineSnapshot(`
"[
"
⛅️ wrangler x.x.x
──────────────────
[
{
\\"name\\": \\"one\\",
\\"tags\\": [
Expand Down Expand Up @@ -434,8 +457,6 @@ describe("cloudchamber image delete", () => {
expect(std.out).toMatchInlineSnapshot(`
"wrangler cloudchamber images delete <image>

Remove an image from the Cloudflare managed registry

POSITIONALS
image Image and tag to delete, of the form IMAGE:TAG [string] [required]

Expand Down Expand Up @@ -488,7 +509,12 @@ describe("cloudchamber image delete", () => {
await runWrangler("cloudchamber images delete one:hundred");
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.out).toMatchInlineSnapshot(
`"Deleted one:hundred (some-digest)"`
`
"
⛅️ wrangler x.x.x
──────────────────
Deleted one:hundred (some-digest)"
`
);
});

Expand Down
Loading
Loading