@@ -39,7 +39,7 @@ var _ = Describe("SubGraph controller", func() {
3939 By ("creating a new SubGraph" )
4040 ctx := context .Background ()
4141
42- gi := & v1beta1.SubGraph {
42+ subgraph := & v1beta1.SubGraph {
4343 ObjectMeta : metav1.ObjectMeta {
4444 Name : subgraphName ,
4545 Namespace : "default" ,
@@ -51,7 +51,7 @@ var _ = Describe("SubGraph controller", func() {
5151 },
5252 },
5353 }
54- Expect (k8sClient .Create (ctx , gi )).Should (Succeed ())
54+ Expect (k8sClient .Create (ctx , subgraph )).Should (Succeed ())
5555
5656 By ("waiting for the reconciliation" )
5757 instanceLookupKey := types.NamespacedName {Name : subgraphName , Namespace : "default" }
@@ -178,4 +178,151 @@ var _ = Describe("SubGraph controller", func() {
178178 Expect (k8sClient .Delete (ctx , subgraph )).Should (Succeed ())
179179 })
180180 })
181+
182+ When ("reconciling a SubGraph with a schema from an http endpoint runs into a specified timeout" , func () {
183+ subgraphName := fmt .Sprintf ("subgraph-%s" , randStringRunes (5 ))
184+ var subgraph * v1beta1.SubGraph
185+
186+ It ("should not update the status" , func () {
187+ By ("creating a new SubGraph" )
188+ ctx := context .Background ()
189+
190+ subgraph = & v1beta1.SubGraph {
191+ ObjectMeta : metav1.ObjectMeta {
192+ Name : subgraphName ,
193+ Namespace : "default" ,
194+ },
195+ Spec : v1beta1.SubGraphSpec {
196+ Timeout : & metav1.Duration {},
197+ Schema : v1beta1.Schema {
198+ HTTP : & v1beta1.SchemaHTTP {
199+ Endpoint : "http://127.0.0.1:29001" ,
200+ },
201+ },
202+ },
203+ }
204+ Expect (k8sClient .Create (ctx , subgraph )).Should (Succeed ())
205+ })
206+
207+ It ("should update the subgraph status" , func () {
208+ ctx := context .Background ()
209+ reconciledInstance := & v1beta1.SubGraph {}
210+ instanceLookupKey := types.NamespacedName {Name : subgraphName , Namespace : "default" }
211+
212+ expectedStatus := & v1beta1.SubGraphStatus {
213+ ObservedGeneration : 1 ,
214+ Conditions : []metav1.Condition {
215+ {
216+ Type : v1beta1 .ConditionReady ,
217+ Status : metav1 .ConditionFalse ,
218+ Reason : "ReconciliationFailed" ,
219+ Message : "failed to fetch schema from http endpoint: Get \" http://127.0.0.1:29001\" : context deadline exceeded" ,
220+ },
221+ },
222+ }
223+ eventuallyMatchExactConditions (ctx , instanceLookupKey , reconciledInstance , expectedStatus )
224+ })
225+
226+ It ("cleans up" , func () {
227+ ctx := context .Background ()
228+ Expect (k8sClient .Delete (ctx , subgraph )).Should (Succeed ())
229+ })
230+ })
231+
232+ When ("it reconciles a subgraph with an invalid schema" , func () {
233+ subgraphName := fmt .Sprintf ("subgraph-%s" , randStringRunes (5 ))
234+ var subgraph * v1beta1.SubGraph
235+ schema := "not a valid graphql schema"
236+
237+ It ("creates a new subgraph" , func () {
238+ ctx := context .Background ()
239+
240+ subgraph = & v1beta1.SubGraph {
241+ ObjectMeta : metav1.ObjectMeta {
242+ Name : subgraphName ,
243+ Namespace : "default" ,
244+ },
245+ Spec : v1beta1.SubGraphSpec {
246+ Schema : v1beta1.Schema {
247+ SDL : & schema ,
248+ },
249+ },
250+ }
251+ Expect (k8sClient .Create (ctx , subgraph )).Should (Succeed ())
252+ })
253+
254+ It ("should update the subgraph status" , func () {
255+ ctx := context .Background ()
256+ reconciledInstance := & v1beta1.SubGraph {}
257+ instanceLookupKey := types.NamespacedName {Name : subgraphName , Namespace : "default" }
258+
259+ expectedStatus := & v1beta1.SubGraphStatus {
260+ ObservedGeneration : 1 ,
261+ Conditions : []metav1.Condition {
262+ {
263+ Type : v1beta1 .ConditionReady ,
264+ Status : metav1 .ConditionFalse ,
265+ Reason : "ReconciliationFailed" ,
266+ Message : "schema is invalid: schema.graphql:1:1: Unexpected Name \" not\" " ,
267+ },
268+ },
269+ }
270+ eventuallyMatchExactConditions (ctx , instanceLookupKey , reconciledInstance , expectedStatus )
271+ Expect (reconciledInstance .Status .Schema ).To (Equal ("" ))
272+ })
273+
274+ It ("cleans up" , func () {
275+ ctx := context .Background ()
276+ Expect (k8sClient .Delete (ctx , subgraph )).Should (Succeed ())
277+ })
278+ })
279+
280+ When ("it reconciles a subgraph with an invalid schema but schema validation is disabled" , func () {
281+ subgraphName := fmt .Sprintf ("subgraph-%s" , randStringRunes (5 ))
282+ var subgraph * v1beta1.SubGraph
283+ schema := "not a valid graphql schema"
284+
285+ It ("creates a new subgraph" , func () {
286+ ctx := context .Background ()
287+
288+ subgraph = & v1beta1.SubGraph {
289+ ObjectMeta : metav1.ObjectMeta {
290+ Name : subgraphName ,
291+ Namespace : "default" ,
292+ },
293+ Spec : v1beta1.SubGraphSpec {
294+ SkipSchemaValidation : true ,
295+ Schema : v1beta1.Schema {
296+ SDL : & schema ,
297+ },
298+ },
299+ }
300+ Expect (k8sClient .Create (ctx , subgraph )).Should (Succeed ())
301+ })
302+
303+ It ("should update the subgraph status" , func () {
304+ ctx := context .Background ()
305+ reconciledInstance := & v1beta1.SubGraph {}
306+ instanceLookupKey := types.NamespacedName {Name : subgraphName , Namespace : "default" }
307+
308+ expectedStatus := & v1beta1.SubGraphStatus {
309+ ObservedGeneration : 1 ,
310+ Conditions : []metav1.Condition {
311+ {
312+ Type : v1beta1 .ConditionReady ,
313+ Status : metav1 .ConditionTrue ,
314+ Reason : "ReconciliationSuccessful" ,
315+ Message : "schema available" ,
316+ },
317+ },
318+ }
319+ eventuallyMatchExactConditions (ctx , instanceLookupKey , reconciledInstance , expectedStatus )
320+ Expect (reconciledInstance .Status .Schema ).To (Equal (schema ))
321+ })
322+
323+ It ("cleans up" , func () {
324+ ctx := context .Background ()
325+ Expect (k8sClient .Delete (ctx , subgraph )).Should (Succeed ())
326+ })
327+ })
181328})
0 commit comments