@@ -109,7 +109,42 @@ describe('kubernetes volumes', () => {
109109 await bindings . data ( resource ) ;
110110 expect ( Icinga . applyHost . mock . calls . length ) . toBe ( 1 ) ;
111111 } ) ;
112+
113+ it ( 'modify ingress object delete and create host' , async ( ) => {
114+ let instance = new Volume ( Logger , Node , Icinga , {
115+ hostName : null
116+ } ) ;
117+
118+ var resource = {
119+ type : 'MODIFIED' ,
120+ object : fixture
121+ } ;
122+
123+ Icinga . applyHost = jest . fn ( ) ;
124+ Icinga . deleteServicesByFilter = jest . fn ( ) ;
125+ Icinga . deleteHost = function ( name ) {
126+ expect ( name ) . toEqual ( 'volume-generic-nimble-fad5684e-22fb-11e9-94e3-0050568fe3c2' ) ;
127+ return new Promise ( ( resolve , reject ) => {
128+ resolve ( true ) ;
129+ } ) ;
130+ } ;
131+
132+ var bindings = { } ;
133+ var json = {
134+ on : async function ( name , callback ) {
135+ bindings [ name ] = callback ;
136+ }
137+ } ;
112138
139+ await instance . kubeListener ( ( ) => {
140+ return json ;
141+ } ) ;
142+
143+ await bindings . data ( resource ) ;
144+ expect ( Icinga . applyHost . mock . calls . length ) . toBe ( 1 ) ;
145+ expect ( Icinga . deleteServicesByFilter . mock . calls . length ) . toBe ( 0 ) ;
146+ } ) ;
147+
113148 it ( 'delete volume object delete' , async ( ) => {
114149 let instance = new Volume ( Logger , Node , Icinga ) ;
115150
@@ -233,7 +268,7 @@ describe('kubernetes volumes', () => {
233268 } ) ;
234269 } ) ;
235270
236- describe ( 'add all volume object http path rules as service objects' , ( ) => {
271+ describe ( 'add all volume objects as service objects' , ( ) => {
237272 it ( 'create service object' , async ( ) => {
238273 let instance = new Volume ( Logger , Node , Icinga ) ;
239274
@@ -288,6 +323,30 @@ describe('kubernetes volumes', () => {
288323 expect ( Icinga . applyService . mock . instances . length ) . toBe ( 1 ) ;
289324 expect ( calls [ 0 ] [ 3 ] ) . toEqual ( [ 'foo' , 'bar' ] ) ;
290325 } ) ;
326+
327+ it ( 'attach services to kube workers if attachToNodes is enabled' , async ( ) => {
328+ let instance = new Volume ( Logger , Node , Icinga , {
329+ attachToNodes : true
330+ } ) ;
331+
332+ Node . getWorkerNodes = function ( ) {
333+ return [ 'foo' , 'bar' ] ;
334+ } ;
335+
336+ Icinga . applyService = jest . fn ( ) ;
337+ Icinga . applyServiceGroup = jest . fn ( ) ;
338+ Icinga . applyHost = jest . fn ( ) ;
339+
340+ await instance . prepareObject ( fixture ) ;
341+ const calls = Icinga . applyService . mock . calls ;
342+ expect ( Icinga . applyHost . mock . instances . length ) . toBe ( 0 ) ;
343+ expect ( Icinga . applyService . mock . instances . length ) . toBe ( 2 ) ;
344+
345+ expect ( calls [ 0 ] [ 0 ] ) . toBe ( 'foo' ) ;
346+ expect ( calls [ 1 ] [ 0 ] ) . toBe ( 'bar' ) ;
347+ expect ( calls [ 0 ] [ 1 ] ) . toBe ( 'generic-nimble-fad5684e-22fb-11e9-94e3-0050568fe3c2' ) ;
348+ expect ( calls [ 1 ] [ 1 ] ) . toBe ( 'generic-nimble-fad5684e-22fb-11e9-94e3-0050568fe3c2' ) ;
349+ } ) ;
291350 } ) ;
292351
293352 describe ( 'kubernetes annotations' , ( ) => {
0 commit comments