@@ -17,6 +17,7 @@ describe('ZookeeperManager', () => {
1717 connect : sinon . stub ( ) ,
1818 getData : sinon . stub ( ) ,
1919 mkdirp : sinon . stub ( ) ,
20+ create : sinon . stub ( ) ,
2021 close : sinon . stub ( ) ,
2122 } ;
2223
@@ -88,4 +89,42 @@ describe('ZookeeperManager', () => {
8889 done ( ) ;
8990 } ) ;
9091 } ) ;
92+
93+ it ( 'should create parent path without data and child with data using mkdirpWithChildDataOnly' , done => {
94+ mockClient . mkdirp . callsArgWith ( 4 , null ) ;
95+ mockClient . create . callsArgWith ( 4 , null ) ;
96+
97+ zkClient = new ZookeeperManager ( 'localhost:2181' , { } , log ) ;
98+
99+ const testPath = '/config/bucket1' ;
100+ const testData = Buffer . from ( 'test-data' ) ;
101+
102+ zkClient . mkdirpWithChildDataOnly ( testPath , testData , err => {
103+ assert . ifError ( err ) ;
104+ sinon . assert . calledOnce ( mockClient . mkdirp ) ;
105+ sinon . assert . calledWith ( mockClient . mkdirp , '/config' , null ) ;
106+ sinon . assert . calledOnce ( mockClient . create ) ;
107+ sinon . assert . calledWith ( mockClient . create , testPath , testData ) ;
108+ done ( ) ;
109+ } ) ;
110+ } ) ;
111+
112+ it ( 'should handle NODE_EXISTS error on parent path in mkdirpWithChildDataOnly' , done => {
113+ mockClient . mkdirp . callsArgWith ( 4 , { name : 'NODE_EXISTS' } ) ;
114+ mockClient . create . callsArgWith ( 4 , null ) ;
115+
116+ zkClient = new ZookeeperManager ( 'localhost:2181' , { } , log ) ;
117+
118+ const testPath = '/config/bucket1' ;
119+ const testData = Buffer . from ( 'test-data' ) ;
120+
121+ zkClient . mkdirpWithChildDataOnly ( testPath , testData , err => {
122+ assert . ifError ( err ) ;
123+ sinon . assert . calledOnce ( mockClient . mkdirp ) ;
124+ sinon . assert . calledWith ( mockClient . mkdirp , '/config' , null ) ;
125+ sinon . assert . calledOnce ( mockClient . create ) ;
126+ sinon . assert . calledWith ( mockClient . create , testPath , testData ) ;
127+ done ( ) ;
128+ } ) ;
129+ } ) ;
91130} ) ;
0 commit comments