(t *testing.T)
| 171 | } |
| 172 | |
| 173 | func TestHandleFileWithTemp(t *testing.T) { |
| 174 | // After diff between required and existing we should: |
| 175 | // Copy: 2, 5, 8 |
| 176 | // Pull: 1, 3, 4, 6, 7 |
| 177 | |
| 178 | // After dropping out blocks already on the temp file we should: |
| 179 | // Copy: 5, 8 |
| 180 | // Pull: 1, 6 |
| 181 | |
| 182 | existingBlocks := []int{0, 2, 0, 0, 5, 0, 0, 8} |
| 183 | existingFile := setupFile("file", existingBlocks) |
| 184 | requiredFile := existingFile |
| 185 | requiredFile.Blocks = blocks[1:] |
| 186 | |
| 187 | _, f := setupSendReceiveFolder(t, existingFile) |
| 188 | |
| 189 | if _, err := prepareTmpFile(f.Filesystem()); err != nil { |
| 190 | t.Fatal(err) |
| 191 | } |
| 192 | |
| 193 | copyChan := make(chan copyBlocksState, 1) |
| 194 | |
| 195 | f.handleFile(t.Context(), requiredFile, copyChan) |
| 196 | |
| 197 | // Receive the results |
| 198 | toCopy := <-copyChan |
| 199 | |
| 200 | if len(toCopy.blocks) != 4 { |
| 201 | t.Errorf("Unexpected count of copy blocks: %d != 4", len(toCopy.blocks)) |
| 202 | } |
| 203 | |
| 204 | for _, idx := range []int{1, 5, 6, 8} { |
| 205 | found := false |
| 206 | block := blocks[idx] |
| 207 | for _, toCopyBlock := range toCopy.blocks { |
| 208 | if bytes.Equal(toCopyBlock.Hash, block.Hash) { |
| 209 | found = true |
| 210 | break |
| 211 | } |
| 212 | } |
| 213 | if !found { |
| 214 | t.Errorf("Did not find block %s", block.String()) |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | func TestCopierFinder(t *testing.T) { |
| 220 | // After diff between required and existing we should: |
nothing calls this directly
no test coverage detected