Skip to content

Commit 65c2c19

Browse files
committed
validate nested configuration
1 parent af4dbde commit 65c2c19

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

packages/wrangler/src/__tests__/config/configuration.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,40 @@ describe("normalizeAndValidateConfig()", () => {
24892489
- \\"containers.durable_objects\\" is deprecated. Use the \\"class_name\\" field instead."
24902490
`);
24912491
});
2492+
2493+
it("should error for invalid containers.configuration fields", () => {
2494+
const { diagnostics } = normalizeAndValidateConfig(
2495+
{
2496+
name: "test-worker",
2497+
containers: [
2498+
{
2499+
class_name: "test-class",
2500+
configuration: {
2501+
image: "config-image",
2502+
secrets: [],
2503+
labels: [],
2504+
disk: { size: "2GB" },
2505+
memory: "256MB",
2506+
vcpu: 0.5,
2507+
memory_mib: 256,
2508+
invalid_field: "should not be here",
2509+
another_invalid: 123,
2510+
},
2511+
},
2512+
],
2513+
} as unknown as RawConfig,
2514+
undefined,
2515+
undefined,
2516+
{ env: undefined }
2517+
);
2518+
2519+
console.dir(diagnostics.warnings);
2520+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2521+
"Processing wrangler configuration:
2522+
- \\"containers.configuration\\" is deprecated. Use top level \\"containers\\" fields instead. \\"configuration.image\\" should be \\"image\\", \\"configuration.disk\\" should be set via \\"instance_type\\".
2523+
- Unexpected fields found in containers.configuration field: \\"invalid_field\\",\\"another_invalid\\""
2524+
`);
2525+
});
24922526
});
24932527

24942528
describe("[kv_namespaces]", () => {

packages/wrangler/src/config/validation.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,6 +2560,14 @@ function validateContainerApp(
25602560
"durable_objects",
25612561
]
25622562
);
2563+
if ("configuration" in containerAppOptional) {
2564+
validateAdditionalProperties(
2565+
diagnostics,
2566+
`${field}.configuration`,
2567+
Object.keys(containerAppOptional.configuration),
2568+
["image", "secrets", "labels", "disk", "memory", "vcpu", "memory_mib"]
2569+
);
2570+
}
25632571
}
25642572

25652573
if (diagnostics.errors.length > 0) {

0 commit comments

Comments
 (0)