Skip to content

Commit d865917

Browse files
committed
validate nested configuration
1 parent 7c80139 commit d865917

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-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
@@ -2494,6 +2494,40 @@ describe("normalizeAndValidateConfig()", () => {
24942494
- \\"containers.durable_objects\\" is deprecated. Use the \\"class_name\\" field instead."
24952495
`);
24962496
});
2497+
2498+
it("should error for invalid containers.configuration fields", () => {
2499+
const { diagnostics } = normalizeAndValidateConfig(
2500+
{
2501+
name: "test-worker",
2502+
containers: [
2503+
{
2504+
class_name: "test-class",
2505+
configuration: {
2506+
image: "config-image",
2507+
secrets: [],
2508+
labels: [],
2509+
disk: { size: "2GB" },
2510+
memory: "256MB",
2511+
vcpu: 0.5,
2512+
memory_mib: 256,
2513+
invalid_field: "should not be here",
2514+
another_invalid: 123,
2515+
},
2516+
},
2517+
],
2518+
} as unknown as RawConfig,
2519+
undefined,
2520+
undefined,
2521+
{ env: undefined }
2522+
);
2523+
2524+
console.dir(diagnostics.warnings);
2525+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2526+
"Processing wrangler configuration:
2527+
- \\"containers.configuration\\" is deprecated. Use top level \\"containers\\" fields instead. \\"configuration.image\\" should be \\"image\\", \\"configuration.disk\\" should be set via \\"instance_type\\".
2528+
- Unexpected fields found in containers.configuration field: \\"invalid_field\\",\\"another_invalid\\""
2529+
`);
2530+
});
24972531
});
24982532

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

packages/wrangler/src/config/validation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,6 +2570,12 @@ function validateContainerApp(
25702570
"durable_objects",
25712571
]
25722572
);
2573+
validateAdditionalProperties(
2574+
diagnostics,
2575+
`${field}.configuration`,
2576+
Object.keys(containerAppOptional.configuration),
2577+
["image", "secrets", "labels", "disk", "memory", "vcpu", "memory_mib"]
2578+
);
25732579
}
25742580

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

0 commit comments

Comments
 (0)