@@ -28,6 +28,7 @@ describe("normalizeAndValidateConfig()", () => {
28
28
d1_databases : [ ] ,
29
29
vectorize : [ ] ,
30
30
constellation : [ ] ,
31
+ hyperdrive : [ ] ,
31
32
dev : {
32
33
ip : "0.0.0.0" ,
33
34
local_protocol : "http" ,
@@ -2076,6 +2077,101 @@ describe("normalizeAndValidateConfig()", () => {
2076
2077
} ) ;
2077
2078
} ) ;
2078
2079
2080
+ describe ( "[hyperdrive]" , ( ) => {
2081
+ it ( "should error if hyperdrive is an object" , ( ) => {
2082
+ const { diagnostics } = normalizeAndValidateConfig (
2083
+ { hyperdrive : { } } as unknown as RawConfig ,
2084
+ undefined ,
2085
+ { env : undefined }
2086
+ ) ;
2087
+
2088
+ expect ( diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
2089
+ expect ( diagnostics . renderErrors ( ) ) . toMatchInlineSnapshot ( `
2090
+ "Processing wrangler configuration:
2091
+ - The field \\"hyperdrive\\" should be an array but got {}."
2092
+ ` ) ;
2093
+ } ) ;
2094
+
2095
+ it ( "should error if hyperdrive is a string" , ( ) => {
2096
+ const { diagnostics } = normalizeAndValidateConfig (
2097
+ { hyperdrive : "BAD" } as unknown as RawConfig ,
2098
+ undefined ,
2099
+ { env : undefined }
2100
+ ) ;
2101
+
2102
+ expect ( diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
2103
+ expect ( diagnostics . renderErrors ( ) ) . toMatchInlineSnapshot ( `
2104
+ "Processing wrangler configuration:
2105
+ - The field \\"hyperdrive\\" should be an array but got \\"BAD\\"."
2106
+ ` ) ;
2107
+ } ) ;
2108
+
2109
+ it ( "should error if hyperdrive is a number" , ( ) => {
2110
+ const { diagnostics } = normalizeAndValidateConfig (
2111
+ { hyperdrive : 999 } as unknown as RawConfig ,
2112
+ undefined ,
2113
+ { env : undefined }
2114
+ ) ;
2115
+
2116
+ expect ( diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
2117
+ expect ( diagnostics . renderErrors ( ) ) . toMatchInlineSnapshot ( `
2118
+ "Processing wrangler configuration:
2119
+ - The field \\"hyperdrive\\" should be an array but got 999."
2120
+ ` ) ;
2121
+ } ) ;
2122
+
2123
+ it ( "should error if hyperdrive is null" , ( ) => {
2124
+ const { diagnostics } = normalizeAndValidateConfig (
2125
+ { hyperdrive : null } as unknown as RawConfig ,
2126
+ undefined ,
2127
+ { env : undefined }
2128
+ ) ;
2129
+
2130
+ expect ( diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
2131
+ expect ( diagnostics . renderErrors ( ) ) . toMatchInlineSnapshot ( `
2132
+ "Processing wrangler configuration:
2133
+ - The field \\"hyperdrive\\" should be an array but got null."
2134
+ ` ) ;
2135
+ } ) ;
2136
+
2137
+ it ( "should accept valid bindings" , ( ) => {
2138
+ const { diagnostics } = normalizeAndValidateConfig (
2139
+ {
2140
+ hyperdrive : [
2141
+ { binding : "VALID" , id : "343cd4f1d58c42fbb5bd082592fd7143" } ,
2142
+ ] ,
2143
+ } as unknown as RawConfig ,
2144
+ undefined ,
2145
+ { env : undefined }
2146
+ ) ;
2147
+
2148
+ expect ( diagnostics . hasErrors ( ) ) . toBe ( false ) ;
2149
+ } ) ;
2150
+
2151
+ it ( "should error if hyperdrive.bindings are not valid" , ( ) => {
2152
+ const { diagnostics } = normalizeAndValidateConfig (
2153
+ {
2154
+ hyperdrive : [
2155
+ { } ,
2156
+ { binding : "VALID" , id : "343cd4f1d58c42fbb5bd082592fd7143" } ,
2157
+ { binding : 2000 , project : 2111 } ,
2158
+ ] ,
2159
+ } as unknown as RawConfig ,
2160
+ undefined ,
2161
+ { env : undefined }
2162
+ ) ;
2163
+
2164
+ expect ( diagnostics . hasWarnings ( ) ) . toBe ( true ) ;
2165
+ expect ( diagnostics . renderErrors ( ) ) . toMatchInlineSnapshot ( `
2166
+ "Processing wrangler configuration:
2167
+ - \\"hyperdrive[0]\\" bindings should have a string \\"binding\\" field but got {}.
2168
+ - \\"hyperdrive[0]\\" bindings must have a \\"id\\" field but got {}.
2169
+ - \\"hyperdrive[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2000,\\"project\\":2111}.
2170
+ - \\"hyperdrive[2]\\" bindings must have a \\"id\\" field but got {\\"binding\\":2000,\\"project\\":2111}."
2171
+ ` ) ;
2172
+ } ) ;
2173
+ } ) ;
2174
+
2079
2175
describe ( "[queues]" , ( ) => {
2080
2176
it ( "should error if queues is not an object" , ( ) => {
2081
2177
const { config, diagnostics } = normalizeAndValidateConfig (
0 commit comments