@@ -439,6 +439,40 @@ describe("Balancer", function()
439439 assert .stub (mock_instance .sync ).was_called_with (mock_instance , expected_backend )
440440 end )
441441
442+ it (" sets balancer to nil when service is of type External name and DNS could not resolve" , function ()
443+ backend = {
444+ name = " example2-com" , service = { spec = { [" type" ] = " ExternalName" } },
445+ endpoints = {
446+ { address = " example2.com" , port = " 80" , maxFails = 0 , failTimeout = 0 }
447+ }
448+ }
449+
450+ helpers .mock_resty_dns_query (nil , { errcode = 3 , errstr = " NXDNS: no such host (mock)" })
451+ local mock_instance = { sync = function (backend ) end }
452+ setmetatable (mock_instance , implementation )
453+ implementation .new = function (self , backend ) return mock_instance end
454+ local s = spy .on (implementation , " new" )
455+ assert .has_no .errors (function () balancer .sync_backend (backend ) end )
456+ assert .spy (s ).was_not_called ()
457+ assert .is_nil (balancer .get_balancer_by_upstream_name (backend .name ))
458+ end )
459+
460+ it (" sets balancer to nil when service is of type External name and endpoints in nil (omitted by go calling POST /configuration/backends)" , function ()
461+ backend = {
462+ name = " example-com" , service = { spec = { [" type" ] = " ExternalName" } },
463+ endpoints = nil
464+ }
465+
466+ helpers .mock_resty_dns_query (nil , { errcode = 3 , errstr = " NXDNS: no such host (mock)" })
467+ local mock_instance = { sync = function (backend ) end }
468+ setmetatable (mock_instance , implementation )
469+ implementation .new = function (self , backend ) return mock_instance end
470+ local s = spy .on (implementation , " new" )
471+ assert .has_no .errors (function () balancer .sync_backend (backend ) end )
472+ assert .spy (s ).was_not_called ()
473+ assert .is_nil (balancer .get_balancer_by_upstream_name (backend .name ))
474+ end )
475+
442476 it (" wraps IPv6 addresses into square brackets" , function ()
443477 local backend = {
444478 name = " example-com" ,
0 commit comments