| 60 | const fileContents = "TestContents" |
| 61 | |
| 62 | func checkFilesAndFolders(t *testing.T, files []checkedFileOrFolder, folders []checkedFileOrFolder, local string, remote string, timeout time.Duration) { |
| 63 | beginTimeStamp := time.Now() |
| 64 | |
| 65 | var missingFileOrFolder string |
| 66 | var unexpectedFileOrFolder string |
| 67 | |
| 68 | Outer: |
| 69 | for time.Since(beginTimeStamp) < timeout { |
| 70 | time.Sleep(time.Millisecond * 100) |
| 71 | |
| 72 | missingFileOrFolder = "" |
| 73 | unexpectedFileOrFolder = "" |
| 74 | |
| 75 | /* |
| 76 | If something is expected to be there but it isn't, we expect that the sync-job isn't finished yet. |
| 77 | The same applies if a file has missing content. Also if a file is there when it shouldn't be. |
| 78 | In these cases we continue the outer Loop until everything is there or the time runs up. |
| 79 | |
| 80 | If something unexpected happens like an unxpected error or a wrong file type, we let the test fail and return |
| 81 | */ |
| 82 | // Check files |
| 83 | FileCheck: |
| 84 | for _, v := range files { |
| 85 | localFile := path.Join(local, v.path) |
| 86 | remoteFile := path.Join(remote, v.path) |
| 87 | |
| 88 | localData, err := os.ReadFile(localFile) |
| 89 | if v.shouldExistInLocal && os.IsNotExist(err) { |
| 90 | missingFileOrFolder = localFile |
| 91 | continue Outer |
| 92 | } |
| 93 | if !v.shouldExistInLocal && !os.IsNotExist(err) { |
| 94 | unexpectedFileOrFolder = localFile |
| 95 | continue Outer |
| 96 | } |
| 97 | if err != nil && !os.IsNotExist(err) { |
| 98 | t.Fatal(err) |
| 99 | } |
| 100 | |
| 101 | remoteData, err := os.ReadFile(remoteFile) |
| 102 | if v.shouldExistInRemote && os.IsNotExist(err) { |
| 103 | missingFileOrFolder = remoteFile |
| 104 | continue Outer |
| 105 | } |
| 106 | if !v.shouldExistInRemote && !os.IsNotExist(err) { |
| 107 | unexpectedFileOrFolder = remoteFile |
| 108 | continue Outer |
| 109 | } |
| 110 | if !v.shouldExistInRemote && os.IsNotExist(err) { |
| 111 | continue FileCheck |
| 112 | } |
| 113 | if err != nil { |
| 114 | t.Fatal(err) |
| 115 | } |
| 116 | |
| 117 | if v.shouldExistInLocal { |
| 118 | if string(localData) != fileContents { |
| 119 | missingFileOrFolder = localFile |