@@ -146,19 +146,34 @@ func TestResolveMagicDNSExtraRecordsPath(t *testing.T) {
146
146
assertCommandOutputContains (t , client , []string {"dig" , "test.myvpn.example.com" }, "6.6.6.6" )
147
147
}
148
148
149
+ hs , err := scenario .Headscale ()
150
+ assertNoErr (t , err )
151
+
152
+ // Write the file directly into place from the docker API.
153
+ b0 , _ := json .Marshal ([]tailcfg.DNSRecord {
154
+ {
155
+ Name : "docker.myvpn.example.com" ,
156
+ Type : "A" ,
157
+ Value : "2.2.2.2" ,
158
+ },
159
+ })
160
+
161
+ err = hs .WriteFile (erPath , b0 )
162
+ assertNoErr (t , err )
163
+
164
+ for _ , client := range allClients {
165
+ assertCommandOutputContains (t , client , []string {"dig" , "docker.myvpn.example.com" }, "2.2.2.2" )
166
+ }
167
+
168
+ // Write a new file and move it to the path to ensure the reload
169
+ // works when a file is moved atomically into place.
149
170
extraRecords = append (extraRecords , tailcfg.DNSRecord {
150
171
Name : "otherrecord.myvpn.example.com" ,
151
172
Type : "A" ,
152
173
Value : "7.7.7.7" ,
153
174
})
154
175
b2 , _ := json .Marshal (extraRecords )
155
176
156
- hs , err := scenario .Headscale ()
157
- assertNoErr (t , err )
158
-
159
- // Write it to a separate file to ensure Docker's API doesnt
160
- // do anything unexpected and rather move it into place to trigger
161
- // a reload.
162
177
err = hs .WriteFile (erPath + "2" , b2 )
163
178
assertNoErr (t , err )
164
179
_ , err = hs .Execute ([]string {"mv" , erPath + "2" , erPath })
@@ -168,6 +183,61 @@ func TestResolveMagicDNSExtraRecordsPath(t *testing.T) {
168
183
assertCommandOutputContains (t , client , []string {"dig" , "test.myvpn.example.com" }, "6.6.6.6" )
169
184
assertCommandOutputContains (t , client , []string {"dig" , "otherrecord.myvpn.example.com" }, "7.7.7.7" )
170
185
}
186
+
187
+ // Write a new file and copy it to the path to ensure the reload
188
+ // works when a file is copied into place.
189
+ b3 , _ := json .Marshal ([]tailcfg.DNSRecord {
190
+ {
191
+ Name : "copy.myvpn.example.com" ,
192
+ Type : "A" ,
193
+ Value : "8.8.8.8" ,
194
+ },
195
+ })
196
+
197
+ err = hs .WriteFile (erPath + "3" , b3 )
198
+ assertNoErr (t , err )
199
+ _ , err = hs .Execute ([]string {"cp" , erPath + "3" , erPath })
200
+ assertNoErr (t , err )
201
+
202
+ for _ , client := range allClients {
203
+ assertCommandOutputContains (t , client , []string {"dig" , "copy.myvpn.example.com" }, "8.8.8.8" )
204
+ }
205
+
206
+ // Write in place to ensure pipe like behaviour works
207
+ b4 , _ := json .Marshal ([]tailcfg.DNSRecord {
208
+ {
209
+ Name : "docker.myvpn.example.com" ,
210
+ Type : "A" ,
211
+ Value : "9.9.9.9" ,
212
+ },
213
+ })
214
+ command := []string {"echo" , fmt .Sprintf ("'%s'" , string (b4 )), ">" , erPath }
215
+ _ , err = hs .Execute ([]string {"bash" , "-c" , strings .Join (command , " " )})
216
+ assertNoErr (t , err )
217
+
218
+ for _ , client := range allClients {
219
+ assertCommandOutputContains (t , client , []string {"dig" , "docker.myvpn.example.com" }, "9.9.9.9" )
220
+ }
221
+
222
+ // Delete the file and create a new one to ensure it is picked up again.
223
+ _ , err = hs .Execute ([]string {"rm" , erPath })
224
+ assertNoErr (t , err )
225
+
226
+ time .Sleep (2 * time .Second )
227
+
228
+ // The same paths should still be available as it is not cleared on delete.
229
+ for _ , client := range allClients {
230
+ assertCommandOutputContains (t , client , []string {"dig" , "docker.myvpn.example.com" }, "9.9.9.9" )
231
+ }
232
+
233
+ // Write a new file, the backoff mechanism should make the filewatcher pick it up
234
+ // again.
235
+ err = hs .WriteFile (erPath , b3 )
236
+ assertNoErr (t , err )
237
+
238
+ for _ , client := range allClients {
239
+ assertCommandOutputContains (t , client , []string {"dig" , "copy.myvpn.example.com" }, "8.8.8.8" )
240
+ }
171
241
}
172
242
173
243
// TestValidateResolvConf validates that the resolv.conf file
0 commit comments