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)
| 134 | // 02340070 - Temp file on the disk |
| 135 | |
| 136 | func 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 | |
| 173 | func TestHandleFileWithTemp(t *testing.T) { |
| 174 | // After diff between required and existing we should: |
nothing calls this directly
no test coverage detected