@@ -80,27 +80,36 @@ describe('resolvmon watch', function () {
80
80
it ( 'detect resolv.conf delete' , function ( done ) {
81
81
82
82
resolvmon . setPath ( temporary_conf ) ;
83
- fs . writeFileSync ( temporary_conf , "nameserver 127.0.0.11\nnameserver 127.0.0.22\n" ) ;
84
83
85
- resolvmon . on ( 'error' , function ( err ) {
84
+ fs . writeFile ( temporary_conf , "nameserver 127.0.0.11\nnameserver 127.0.0.22\n" , function ( err ) {
85
+
86
86
expect ( err ) . not . to . be . defined ;
87
- done ( err ) ;
88
- } ) ;
89
87
90
- resolvmon . on ( 'update' , function ( nameservers ) {
88
+ if ( err ) {
89
+ return done ( ) ;
90
+ }
91
91
92
- expect ( nameservers ) . to . be . defined ;
93
- expect ( nameservers ) . to . be . instanceof ( Array ) ;
94
- expect ( nameservers ) . to . eql ( [ ] ) ;
92
+ resolvmon . on ( 'error' , function ( err ) {
93
+ expect ( err ) . not . to . be . defined ;
94
+ done ( err ) ;
95
+ } ) ;
95
96
96
- done ( ) ;
97
+ resolvmon . on ( 'update' , function ( nameservers ) {
97
98
98
- } ) ;
99
+ expect ( nameservers ) . to . be . defined ;
100
+ expect ( nameservers ) . to . be . instanceof ( Array ) ;
101
+ expect ( nameservers ) . to . eql ( [ ] ) ;
99
102
100
- resolvmon . start ( ) ;
103
+ done ( ) ;
104
+
105
+ } ) ;
106
+
107
+ resolvmon . start ( ) ;
108
+
109
+ process . nextTick ( function ( ) {
110
+ fs . unlinkSync ( temporary_conf ) ;
111
+ } ) ;
101
112
102
- process . nextTick ( function ( ) {
103
- fs . unlink ( temporary_conf ) ;
104
113
} ) ;
105
114
106
115
} ) ;
@@ -109,55 +118,71 @@ describe('resolvmon watch', function () {
109
118
110
119
resolvmon . setPath ( temporary_conf ) ;
111
120
112
- fs . writeFileSync ( temporary_conf , "nameserver 127.0.0.12\nnameserver 127.0.0.23" ) ;
121
+ fs . writeFile ( temporary_conf , "nameserver 127.0.0.12\nnameserver 127.0.0.23" , function ( err ) {
113
122
114
- resolvmon . on ( 'error' , function ( err ) {
115
123
expect ( err ) . not . to . be . defined ;
116
- done ( err ) ;
117
- } ) ;
118
124
119
- resolvmon . on ( 'update' , function ( nameservers ) {
125
+ if ( err ) {
126
+ return done ( ) ;
127
+ }
120
128
121
- expect ( nameservers ) . to . be . defined ;
122
- expect ( nameservers ) . to . be . instanceof ( Array ) ;
123
- expect ( nameservers ) . to . eql ( [ '127.0.0.12' , '127.0.0.23' , '127.0.0.34' , '127.0.0.45' ] ) ;
129
+ resolvmon . on ( 'error' , function ( err ) {
130
+ expect ( err ) . not . to . be . defined ;
131
+ done ( err ) ;
132
+ } ) ;
124
133
125
- done ( ) ;
134
+ resolvmon . on ( 'update' , function ( nameservers ) {
126
135
127
- } ) ;
136
+ expect ( nameservers ) . to . be . defined ;
137
+ expect ( nameservers ) . to . be . instanceof ( Array ) ;
138
+ expect ( nameservers ) . to . eql ( [ '127.0.0.12' , '127.0.0.23' , '127.0.0.34' , '127.0.0.45' ] ) ;
128
139
129
- resolvmon . start ( ) ;
140
+ done ( ) ;
130
141
131
- process . nextTick ( function ( ) {
132
- fs . appendFileSync ( temporary_conf , "\nnameserver 127.0.0.34\nnameserver 127.0.0.45\n" ) ;
133
- } ) ;
142
+ } ) ;
143
+
144
+ resolvmon . start ( ) ;
134
145
146
+ process . nextTick ( function ( ) {
147
+ fs . appendFileSync ( temporary_conf , "\nnameserver 127.0.0.34\nnameserver 127.0.0.45\n" ) ;
148
+ } ) ;
149
+
150
+
151
+ } ) ;
135
152
136
153
} ) ;
137
154
138
155
it ( 'detect resolv.conf modification' , function ( done ) {
139
156
140
157
resolvmon . setPath ( temporary_conf ) ;
141
158
142
- fs . writeFileSync ( temporary_conf , "nameserver 127.0.0.77\nnameserver 127.0.0.88\n" ) ;
159
+ fs . writeFile ( temporary_conf , "nameserver 127.0.0.77\nnameserver 127.0.0.88\n" , function ( err ) {
143
160
144
- resolvmon . on ( 'error' , function ( err ) {
145
161
expect ( err ) . not . to . be . defined ;
146
- done ( err ) ;
147
- } ) ;
148
162
149
- resolvmon . on ( 'update' , function ( nameservers ) {
163
+ if ( err ) {
164
+ return done ( ) ;
165
+ }
150
166
151
- expect ( nameservers ) . to . be . defined ;
152
- expect ( nameservers ) . to . be . instanceof ( Array ) ;
153
- expect ( nameservers ) . to . eql ( [ '127.0.0.100' , '127.0.0.200' ] ) ;
154
- done ( ) ;
155
- } ) ;
167
+ resolvmon . on ( 'error' , function ( err ) {
168
+ expect ( err ) . not . to . be . defined ;
169
+ done ( err ) ;
170
+ } ) ;
156
171
157
- resolvmon . start ( ) ;
172
+ resolvmon . on ( 'update' , function ( nameservers ) {
173
+
174
+ expect ( nameservers ) . to . be . defined ;
175
+ expect ( nameservers ) . to . be . instanceof ( Array ) ;
176
+ expect ( nameservers ) . to . eql ( [ '127.0.0.100' , '127.0.0.200' ] ) ;
177
+ done ( ) ;
178
+ } ) ;
179
+
180
+ resolvmon . start ( ) ;
181
+
182
+ process . nextTick ( function ( ) {
183
+ fs . writeFileSync ( temporary_conf , "nameserver 127.0.0.100\nnameserver 127.0.0.200" ) ;
184
+ } ) ;
158
185
159
- process . nextTick ( function ( ) {
160
- fs . writeFileSync ( temporary_conf , "nameserver 127.0.0.100\nnameserver 127.0.0.200" ) ;
161
186
} ) ;
162
187
163
188
} ) ;
@@ -190,7 +215,7 @@ describe('resolvmon watch', function () {
190
215
after ( function ( ) {
191
216
192
217
try {
193
- fs . unlink ( temporary_conf + '.renamed' ) ;
218
+ fs . unlinkSync ( temporary_conf + '.renamed' ) ;
194
219
} catch ( ex ) {
195
220
}
196
221
@@ -226,7 +251,7 @@ describe('resolvmon watch', function () {
226
251
after ( function ( ) {
227
252
228
253
try {
229
- fs . unlink ( temporary_conf + '.renamed' ) ;
254
+ fs . unlinkSync ( temporary_conf + '.renamed' ) ;
230
255
} catch ( ex ) {
231
256
}
232
257
0 commit comments