MCPcopy
hub / github.com/syncthing/syncthing / TestHandleFile

Function TestHandleFile

lib/model/folder_sendrecv_test.go:136–171  ·  view source on GitHub ↗

Layout of the files: (indexes from the above array) 12345678 - Required file 02005008 - Existing file (currently in the index) 02340070 - Temp file on the disk

(t *testing.T)

Source from the content-addressed store, hash-verified

134// 02340070 - Temp file on the disk
135
136func TestHandleFile(t *testing.T) {
137 // After the diff between required and existing we should:
138 // Copy: 2, 5, 8
139 // Pull: 1, 3, 4, 6, 7
140
141 existingBlocks := []int{0, 2, 0, 0, 5, 0, 0, 8}
142 existingFile := setupFile("filex", existingBlocks)
143 requiredFile := existingFile
144 requiredFile.Blocks = blocks[1:]
145
146 _, f := setupSendReceiveFolder(t, existingFile)
147
148 copyChan := make(chan copyBlocksState, 1)
149
150 f.handleFile(t.Context(), requiredFile, copyChan)
151
152 // Receive the results
153 toCopy := <-copyChan
154
155 if len(toCopy.blocks) != 8 {
156 t.Errorf("Unexpected count of copy blocks: %d != 8", len(toCopy.blocks))
157 }
158
159 for _, block := range blocks[1:] {
160 found := false
161 for _, toCopyBlock := range toCopy.blocks {
162 if bytes.Equal(toCopyBlock.Hash, block.Hash) {
163 found = true
164 break
165 }
166 }
167 if !found {
168 t.Errorf("Did not find block %s", block.String())
169 }
170 }
171}
172
173func TestHandleFileWithTemp(t *testing.T) {
174 // After diff between required and existing we should:

Callers

nothing calls this directly

Calls 5

setupFileFunction · 0.85
setupSendReceiveFolderFunction · 0.85
handleFileMethod · 0.80
StringMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected