MCPcopy Index your code
hub / github.com/devspace-sh/devspace / checkFilesAndFolders

Function checkFilesAndFolders

pkg/devspace/sync/util_test.go:62–203  ·  view source on GitHub ↗
(t *testing.T, files []checkedFileOrFolder, folders []checkedFileOrFolder, local string, remote string, timeout time.Duration)

Source from the content-addressed store, hash-verified

60const fileContents = "TestContents"
61
62func 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
68Outer:
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

Callers 2

TestInitialSyncFunction · 0.85
TestNormalSyncFunction · 0.85

Calls 6

LogMethod · 0.65
FatalMethod · 0.45
IsDirMethod · 0.45
FatalfMethod · 0.45
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected