Skip to content

Commit a21c2fb

Browse files
author
Florian
committed
Remove-Test work. The manual removals are now one-sided
1 parent 9aaec41 commit a21c2fb

2 files changed

Lines changed: 46 additions & 59 deletions

File tree

pkg/devspace/sync/sync_config_test.go

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ func setExcludePaths(syncClient *SyncConfig) {
198198
func createTestFilesAndFolders(local string, remote string) ([]checkedFileOrFolder, []checkedFileOrFolder) {
199199

200200
//Write local files
201-
ioutil.WriteFile(path.Join(local, "testFileLocal1"), []byte(fileContents), 0666)
202-
ioutil.WriteFile(path.Join(local, "testFileLocal2"), []byte(fileContents), 0666)
201+
ioutil.WriteFile(path.Join(local, "testFileLocal"), []byte(fileContents), 0666)
203202
ioutil.WriteFile(path.Join(local, "ignoreFileLocal"), []byte(fileContents), 0666)
204203
ioutil.WriteFile(path.Join(local, "noDownloadFileLocal"), []byte(fileContents), 0666)
205204
ioutil.WriteFile(path.Join(local, "noUploadFileLocal"), []byte(fileContents), 0666)
@@ -210,15 +209,13 @@ func createTestFilesAndFolders(local string, remote string) ([]checkedFileOrFold
210209
os.Mkdir(path.Join(local, "noDownloadFolderLocal"), 0755)
211210
os.Mkdir(path.Join(local, "noUploadFolderLocal"), 0755)
212211

213-
ioutil.WriteFile(path.Join(local, "testFolder", "testFileLocal1"), []byte(fileContents), 0666)
214-
ioutil.WriteFile(path.Join(local, "testFolder", "testFileLocal2"), []byte(fileContents), 0666)
212+
ioutil.WriteFile(path.Join(local, "testFolder", "testFileLocal"), []byte(fileContents), 0666)
215213
ioutil.WriteFile(path.Join(local, "testFolder", "ignoreFileLocal"), []byte(fileContents), 0666)
216214
ioutil.WriteFile(path.Join(local, "testFolder", "noDownloadFileLocal"), []byte(fileContents), 0666)
217215
ioutil.WriteFile(path.Join(local, "testFolder", "noUploadFileLocal"), []byte(fileContents), 0666)
218216

219217
// Write remote files
220-
ioutil.WriteFile(path.Join(remote, "testFileRemote1"), []byte(fileContents), 0666)
221-
ioutil.WriteFile(path.Join(remote, "testFileRemote2"), []byte(fileContents), 0666)
218+
ioutil.WriteFile(path.Join(remote, "testFileRemote"), []byte(fileContents), 0666)
222219
ioutil.WriteFile(path.Join(remote, "ignoreFileRemote"), []byte(fileContents), 0666)
223220
ioutil.WriteFile(path.Join(remote, "noDownloadFileRemote"), []byte(fileContents), 0666)
224221
ioutil.WriteFile(path.Join(remote, "noUploadFileRemote"), []byte(fileContents), 0666)
@@ -229,16 +226,14 @@ func createTestFilesAndFolders(local string, remote string) ([]checkedFileOrFold
229226
os.Mkdir(path.Join(remote, "noDownloadFolderRemote"), 0755)
230227
os.Mkdir(path.Join(remote, "noUploadFolderRemote"), 0755)
231228

232-
ioutil.WriteFile(path.Join(remote, "testFolder", "testFileRemote1"), []byte(fileContents), 0666)
233-
ioutil.WriteFile(path.Join(remote, "testFolder", "testFileRemote2"), []byte(fileContents), 0666)
229+
ioutil.WriteFile(path.Join(remote, "testFolder", "testFileRemote"), []byte(fileContents), 0666)
234230
ioutil.WriteFile(path.Join(remote, "testFolder", "ignoreFileRemote"), []byte(fileContents), 0666)
235231
ioutil.WriteFile(path.Join(remote, "testFolder", "noDownloadFileRemote"), []byte(fileContents), 0666)
236232
ioutil.WriteFile(path.Join(remote, "testFolder", "noUploadFileRemote"), []byte(fileContents), 0666)
237233

238234
//-----------The following files will be removed later-------------------------------------
239235
//Write local files
240-
ioutil.WriteFile(path.Join(local, "testFileLocal1_Remove"), []byte(fileContents), 0666)
241-
ioutil.WriteFile(path.Join(local, "testFileLocal2_Remove"), []byte(fileContents), 0666)
236+
ioutil.WriteFile(path.Join(local, "testFileLocal_Remove"), []byte(fileContents), 0666)
242237
ioutil.WriteFile(path.Join(local, "ignoreFileLocal_Remove"), []byte(fileContents), 0666)
243238
ioutil.WriteFile(path.Join(local, "noDownloadFileLocal_Remove"), []byte(fileContents), 0666)
244239
ioutil.WriteFile(path.Join(local, "noUploadFileLocal_Remove"), []byte(fileContents), 0666)
@@ -249,39 +244,30 @@ func createTestFilesAndFolders(local string, remote string) ([]checkedFileOrFold
249244
os.Mkdir(path.Join(local, "noDownloadFolderLocal_Remove"), 0755)
250245
os.Mkdir(path.Join(local, "noUploadFolderLocal_Remove"), 0755)
251246

252-
ioutil.WriteFile(path.Join(local, "testFolder", "testFileLocal1_Remove"), []byte(fileContents), 0666)
253-
ioutil.WriteFile(path.Join(local, "testFolder", "testFileLocal2_Remove"), []byte(fileContents), 0666)
247+
ioutil.WriteFile(path.Join(local, "testFolder", "testFileLocal_Remove"), []byte(fileContents), 0666)
254248
ioutil.WriteFile(path.Join(local, "testFolder", "ignoreFileLocal_Remove"), []byte(fileContents), 0666)
255249
ioutil.WriteFile(path.Join(local, "testFolder", "noDownloadFileLocal_Remove"), []byte(fileContents), 0666)
256250
ioutil.WriteFile(path.Join(local, "testFolder", "noUploadFileLocal_Remove"), []byte(fileContents), 0666)
257251

258252
// Write remote files
259-
ioutil.WriteFile(path.Join(remote, "testFileRemote1_Remove"), []byte(fileContents), 0666)
260-
ioutil.WriteFile(path.Join(remote, "testFileRemote2_Remove"), []byte(fileContents), 0666)
253+
ioutil.WriteFile(path.Join(remote, "testFileRemote_Remove"), []byte(fileContents), 0666)
261254
ioutil.WriteFile(path.Join(remote, "ignoreFileRemote_Remove"), []byte(fileContents), 0666)
262255
ioutil.WriteFile(path.Join(remote, "noDownloadFileRemote_Remove"), []byte(fileContents), 0666)
263256
ioutil.WriteFile(path.Join(remote, "noUploadFileRemote_Remove"), []byte(fileContents), 0666)
264257

265-
os.Mkdir(path.Join(remote, "testFolder_Remove"), 0755)
266258
os.Mkdir(path.Join(remote, "testFolderRemote_Remove"), 0755)
267259
os.Mkdir(path.Join(remote, "ignoreFolderRemote_Remove"), 0755)
268260
os.Mkdir(path.Join(remote, "noDownloadFolderRemote_Remove"), 0755)
269261
os.Mkdir(path.Join(remote, "noUploadFolderRemote_Remove"), 0755)
270262

271-
ioutil.WriteFile(path.Join(remote, "testFolder", "testFileRemote1_Remove"), []byte(fileContents), 0666)
272-
ioutil.WriteFile(path.Join(remote, "testFolder", "testFileRemote2_Remove"), []byte(fileContents), 0666)
263+
ioutil.WriteFile(path.Join(remote, "testFolder", "testFileRemote_Remove"), []byte(fileContents), 0666)
273264
ioutil.WriteFile(path.Join(remote, "testFolder", "ignoreFileRemote_Remove"), []byte(fileContents), 0666)
274265
ioutil.WriteFile(path.Join(remote, "testFolder", "noDownloadFileRemote_Remove"), []byte(fileContents), 0666)
275266
ioutil.WriteFile(path.Join(remote, "testFolder", "noUploadFileRemote_Remove"), []byte(fileContents), 0666)
276267

277268
filesToCheck := []checkedFileOrFolder{
278269
checkedFileOrFolder{
279-
path: "testFileLocal1",
280-
shouldExistInLocal: true,
281-
shouldExistInRemote: true,
282-
},
283-
checkedFileOrFolder{
284-
path: "testFileLocal2",
270+
path: "testFileLocal",
285271
shouldExistInLocal: true,
286272
shouldExistInRemote: true,
287273
},
@@ -301,12 +287,7 @@ func createTestFilesAndFolders(local string, remote string) ([]checkedFileOrFold
301287
shouldExistInRemote: false,
302288
},
303289
checkedFileOrFolder{
304-
path: "testFolder/testFileLocal1",
305-
shouldExistInLocal: true,
306-
shouldExistInRemote: true,
307-
},
308-
checkedFileOrFolder{
309-
path: "testFolder/testFileLocal2",
290+
path: "testFolder/testFileLocal",
310291
shouldExistInLocal: true,
311292
shouldExistInRemote: true,
312293
},
@@ -327,12 +308,7 @@ func createTestFilesAndFolders(local string, remote string) ([]checkedFileOrFold
327308
},
328309

329310
checkedFileOrFolder{
330-
path: "testFileRemote1",
331-
shouldExistInLocal: true,
332-
shouldExistInRemote: true,
333-
},
334-
checkedFileOrFolder{
335-
path: "testFileRemote2",
311+
path: "testFileRemote",
336312
shouldExistInLocal: true,
337313
shouldExistInRemote: true,
338314
},
@@ -352,12 +328,7 @@ func createTestFilesAndFolders(local string, remote string) ([]checkedFileOrFold
352328
shouldExistInRemote: true,
353329
},
354330
checkedFileOrFolder{
355-
path: "testFolder/testFileRemote1",
356-
shouldExistInLocal: true,
357-
shouldExistInRemote: true,
358-
},
359-
checkedFileOrFolder{
360-
path: "testFolder/testFileRemote2",
331+
path: "testFolder/testFileRemote",
361332
shouldExistInLocal: true,
362333
shouldExistInRemote: true,
363334
},
@@ -436,6 +407,9 @@ func createTestFilesAndFolders(local string, remote string) ([]checkedFileOrFold
436407
filesToCheck = append(filesToCheck, removeEquivalent)
437408
}
438409
for _, f := range foldersToCheck {
410+
if f.path == "testFolder" {
411+
continue
412+
}
439413
removeEquivalent := checkedFileOrFolder{
440414
path: f.path + "_Remove",
441415
shouldExistInLocal: f.shouldExistInLocal,
@@ -449,17 +423,20 @@ func createTestFilesAndFolders(local string, remote string) ([]checkedFileOrFold
449423

450424
func removeSomeTestFilesAndFolders(local string, remote string, filesToCheck []checkedFileOrFolder, foldersToCheck []checkedFileOrFolder, removeSuffix string) ([]checkedFileOrFolder, []checkedFileOrFolder, error) {
451425

426+
var completeSuffix string
452427
removeIfSuffixMatch := func(path string, f os.FileInfo, err error) error {
453-
if strings.HasSuffix(path, removeSuffix) {
428+
if strings.HasSuffix(path, completeSuffix) {
454429
return os.RemoveAll(path)
455430
}
456431
return nil
457432
}
458433

434+
completeSuffix = "Remote" + removeSuffix
459435
err := filepath.Walk(remote, removeIfSuffixMatch)
460436
if err != nil {
461437
return nil, nil, err
462438
}
439+
completeSuffix = "Local" + removeSuffix
463440
err = filepath.Walk(local, removeIfSuffixMatch)
464441
if err != nil {
465442
return nil, nil, err

pkg/devspace/sync/util_test.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,21 @@ func checkFilesAndFolders(t *testing.T, files []checkedFileOrFolder, folders []c
116116
beginTimeStamp := time.Now()
117117

118118
var missingFileOrFolder checkedFileOrFolder
119+
var unexpectedFileOrFolder checkedFileOrFolder
119120

120121
Outer:
121122
for time.Since(beginTimeStamp) < timeout {
122123

124+
missingFileOrFolder = checkedFileOrFolder{}
125+
unexpectedFileOrFolder = checkedFileOrFolder{}
126+
123127
/*
124128
If something is expected to be there but it isn't, we expect that the sync-job isn't finished yet.
125-
The same applies if a file has missing content.
126-
Therefore we continue the outer Loop until everything is there or the time runs up.
129+
The same applies if a file has missing content. Also if a file is there when it shouldn't be.
130+
In these cases we continue the outer Loop until everything is there or the time runs up.
127131
128-
If something unexpected happens like an unxpected error or wrong file content or a wrong file type
129-
or the existance of a file or folder that shouldn't be there, we let the test fail and return*/
132+
If something unexpected happens like an unxpected error or a wrong file type, we let the test fail and return
133+
*/
130134
// Check files
131135
FileCheck:
132136
for _, v := range files {
@@ -139,8 +143,8 @@ Outer:
139143
continue Outer
140144
}
141145
if !v.shouldExistInLocal && !os.IsNotExist(err) {
142-
t.Error("Local File " + localFile + " shouldn't exist but it does")
143-
return
146+
unexpectedFileOrFolder = v
147+
continue Outer
144148
}
145149
if err != nil && !os.IsNotExist(err) {
146150
t.Error(err)
@@ -153,8 +157,8 @@ Outer:
153157
continue Outer
154158
}
155159
if !v.shouldExistInRemote && !os.IsNotExist(err) {
156-
t.Error("Remote File " + remoteFile + " shouldn't exist but it does")
157-
return
160+
unexpectedFileOrFolder = v
161+
continue Outer
158162
}
159163
if !v.shouldExistInRemote && os.IsNotExist(err) {
160164
continue FileCheck
@@ -180,7 +184,6 @@ Outer:
180184
}
181185

182186
// Check folders
183-
FolderCheck:
184187
for _, v := range folders {
185188
localFolder := path.Join(local, v.path)
186189
remoteFolder := path.Join(remote, v.path)
@@ -190,14 +193,14 @@ Outer:
190193
missingFileOrFolder = v
191194
continue Outer
192195
}
196+
if !v.shouldExistInLocal && !os.IsNotExist(err) {
197+
unexpectedFileOrFolder = v
198+
continue Outer
199+
}
193200
if err != nil && !os.IsNotExist(err) {
194201
t.Error(err)
195202
return
196203
}
197-
if !v.shouldExistInLocal && !os.IsNotExist(err) {
198-
t.Error("Local Directory " + localFolder + " shouldn't exist but it does")
199-
return
200-
}
201204
if err == nil && stat.IsDir() == false {
202205
t.Errorf("Expected %s to be a dir", localFolder)
203206
return
@@ -208,10 +211,11 @@ Outer:
208211
missingFileOrFolder = v
209212
continue Outer
210213
}
211-
if !v.shouldExistInRemote && os.IsNotExist(err) {
212-
continue FolderCheck
214+
if !v.shouldExistInRemote && !os.IsNotExist(err) {
215+
unexpectedFileOrFolder = v
216+
continue Outer
213217
}
214-
if err != nil {
218+
if err != nil && !os.IsNotExist(err) {
215219
t.Error(err)
216220
return
217221
}
@@ -245,5 +249,11 @@ Outer:
245249
return
246250
}
247251

248-
t.Error("Sync Failed. Missing: " + path.Join(remote, missingFileOrFolder.path))
252+
if missingFileOrFolder.path != "" {
253+
t.Error("Sync Failed. Missing: " + path.Join(remote, missingFileOrFolder.path))
254+
} else if unexpectedFileOrFolder.path != "" {
255+
t.Error("Sync Failed. Shouldn't be there: " + path.Join(remote, unexpectedFileOrFolder.path))
256+
} else {
257+
t.Error("unexpected")
258+
}
249259
}

0 commit comments

Comments
 (0)