Skip to content

Commit 670fd1c

Browse files
committed
Improve sync unit test
1 parent 24c48a9 commit 670fd1c

2 files changed

Lines changed: 11 additions & 26 deletions

File tree

pkg/devspace/sync/sync_config_test.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ func createTestSyncClient(testLocalPath, testRemotePath string) *SyncConfig {
6363
}
6464

6565
func TestInitialSync(t *testing.T) {
66-
if runtime.GOOS == "windows" {
67-
t.Skip("Skipping test on windows")
66+
if runtime.GOOS != "linux" {
67+
t.Skip("Skipping test on non linux platform")
6868
}
6969

7070
remote, local, outside := initTestDirs(t)
@@ -116,13 +116,12 @@ func TestInitialSync(t *testing.T) {
116116
return
117117
}
118118

119-
//This seems to hang in travis
120119
checkFilesAndFolders(t, filesToCheck, foldersToCheck, local, remote, 10*time.Second)
121120
}
122121

123122
func TestNormalSync(t *testing.T) {
124-
if runtime.GOOS == "windows" {
125-
t.Skip("Skipping test on windows")
123+
if runtime.GOOS != "linux" {
124+
t.Skip("Skipping test on non linux systems")
126125
}
127126

128127
remote, local, outside := initTestDirs(t)
@@ -187,16 +186,12 @@ func TestNormalSync(t *testing.T) {
187186
t.Error(err)
188187
return
189188
}
190-
checkFilesAndFolders(t, filesToCheck, foldersToCheck, local, remote, 10*time.Second)
191-
189+
checkFilesAndFolders(t, filesToCheck, foldersToCheck, local, remote, 20*time.Second)
192190
}
193191

194192
func setExcludePaths(syncClient *SyncConfig, testCases testCaseList) {
195-
196193
syncClient.ExcludePaths = []string{}
197-
198194
syncClient.DownloadExcludePaths = []string{}
199-
200195
syncClient.UploadExcludePaths = []string{}
201196

202197
for _, testCase := range testCases {
@@ -298,7 +293,6 @@ func makeBasicTestCases() (testCaseList, testCaseList) {
298293
}
299294

300295
func makeRemoveAndRenameTestCases(filesToCheck testCaseList, foldersToCheck testCaseList) (testCaseList, testCaseList) {
301-
302296
for n, array := range [2]testCaseList{filesToCheck, foldersToCheck} {
303297
for _, f := range array {
304298

@@ -406,13 +400,10 @@ func makeRemoveAndRenameTestCases(filesToCheck testCaseList, foldersToCheck test
406400
foldersToCheck = append(foldersToCheck, renameFolderFromOutside...)
407401

408402
return filesToCheck, foldersToCheck
409-
410403
}
411404

412405
func makeRemoteTestCases(testCases testCaseList) testCaseList {
413-
414406
for _, f := range testCases {
415-
416407
if strings.Contains(f.path, "Upload") {
417408
f.path = strings.Replace(f.path, "Upload", "Download", -1)
418409
} else if strings.Contains(f.path, "Download") {
@@ -432,9 +423,7 @@ func makeRemoteTestCases(testCases testCaseList) testCaseList {
432423
}
433424

434425
func makeDeepTestCases(testCases testCaseList) testCaseList {
435-
436426
for _, f := range testCases {
437-
438427
if f.path == "testFolder" {
439428
continue
440429
}
@@ -452,7 +441,6 @@ func makeDeepTestCases(testCases testCaseList) testCaseList {
452441
}
453442

454443
func createTestFilesAndFolders(local string, remote string, outside string, filesToCheck testCaseList, foldersToCheck testCaseList) error {
455-
456444
for _, f := range foldersToCheck {
457445
parentDir, err := getParentDir(local, remote, outside, f.editLocation)
458446
if err != nil {
@@ -482,7 +470,6 @@ func createTestFilesAndFolders(local string, remote string, outside string, file
482470
}
483471

484472
func removeSomeTestFilesAndFolders(local string, remote string, filesToCheck testCaseList, foldersToCheck testCaseList, removeSuffix string) (testCaseList, testCaseList, error) {
485-
486473
var completeSuffix string
487474
removeIfSuffixMatch := func(path string, f os.FileInfo, err error) error {
488475
if strings.HasSuffix(path, completeSuffix) {
@@ -520,11 +507,8 @@ func removeSomeTestFilesAndFolders(local string, remote string, filesToCheck tes
520507
}
521508

522509
func renameSomeTestFilesAndFolders(local string, remote string, outside string, filesToCheck testCaseList, foldersToCheck testCaseList) (testCaseList, testCaseList, error) {
523-
524510
for n, array := range [2]testCaseList{filesToCheck, foldersToCheck} {
525-
526511
for n, f := range array {
527-
528512
if !strings.Contains(f.path, "_Rename") {
529513
continue
530514
}
@@ -572,7 +556,6 @@ func renameSomeTestFilesAndFolders(local string, remote string, outside string,
572556
}
573557

574558
array[n] = f
575-
576559
}
577560

578561
if n == 0 {

pkg/devspace/sync/util_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414

1515
// TODO: CopyToContainer test
1616
func TestCopyToContainerTestable(t *testing.T) {
17-
if runtime.GOOS == "windows" {
18-
t.Skip("Skipping test on windows")
17+
if runtime.GOOS != "linux" {
18+
t.Skip("Skipping test on non linux platform")
1919
}
2020

2121
remote, local, _ := initTestDirs(t)
@@ -102,7 +102,6 @@ func TestCopyToContainerTestable(t *testing.T) {
102102
}
103103

104104
checkFilesAndFolders(t, filesToCheck, foldersToCheck, local, remote, 10*time.Second)
105-
106105
}
107106

108107
const (
@@ -149,14 +148,14 @@ func (arr testCaseList) Swap(i, j int) {
149148
const fileContents = "TestContents"
150149

151150
func checkFilesAndFolders(t *testing.T, files []checkedFileOrFolder, folders []checkedFileOrFolder, local string, remote string, timeout time.Duration) {
152-
153151
beginTimeStamp := time.Now()
154152

155153
var missingFileOrFolder string
156154
var unexpectedFileOrFolder string
157155

158156
Outer:
159157
for time.Since(beginTimeStamp) < timeout {
158+
time.Sleep(time.Millisecond * 100)
160159

161160
missingFileOrFolder = ""
162161
unexpectedFileOrFolder = ""
@@ -266,6 +265,9 @@ Outer:
266265
return
267266
}
268267

268+
// Print time since check start
269+
t.Logf("Time since check start: %s", time.Since(beginTimeStamp).String())
270+
269271
//If this code is reached, every time the results of the checks showed an unfinished sync. Timeout is reached
270272
printPathAndReturnNil := func(path string, f os.FileInfo, err error) error {
271273
t.Log(path)

0 commit comments

Comments
 (0)