TestFetchRemainingBlocks exercises the high-level FetchRemainingBlocks method using a fake HTTPRequester that returns the exact block data.
(t *testing.T)
| 86 | // TestFetchRemainingBlocks exercises the high-level FetchRemainingBlocks |
| 87 | // method using a fake HTTPRequester that returns the exact block data. |
| 88 | func TestFetchRemainingBlocks(t *testing.T) { |
| 89 | // Setup control file for a single block |
| 90 | data := []byte{10, 11, 12, 13, 14, 15, 16, 17} |
| 91 | control := MakeZsyncControl([][]byte{data}) |
| 92 | |
| 93 | dir := t.TempDir() |
| 94 | s, err := zsync.NewFromControlFile(bytes.NewReader(control.Bytes()), zsync.SyncerOptions{TargetDirectory: dir, OverrideTargetFilename: "outfile"}) |
| 95 | if err != nil { |
| 96 | t.Fatalf("New failed: %v", err) |
| 97 | } |
| 98 | |
| 99 | // replace URL list with a synthetic URL (doesn't matter for fake client) |
| 100 | // Use the fake client which returns 206 Partial Content and our block data |
| 101 | client := &fakeClient{status: http.StatusPartialContent, body: data} |
| 102 | |
| 103 | // Fetch remaining blocks. We provide empty referer and noProgress=true |
| 104 | got, err := s.FetchRemainingBlocks(client, "", nil) |
| 105 | if err != nil { |
| 106 | t.Fatalf("FetchRemainingBlocks failed: %v", err) |
| 107 | } |
| 108 | if got == 0 { |
| 109 | t.Fatalf("expected some bytes downloaded") |
| 110 | } |
| 111 | if s.Status() != zsync.CompleteData { |
| 112 | t.Fatalf("expected Syncer to be complete, got status %d", s.Status()) |
| 113 | } |
| 114 | // Verify file contents |
| 115 | fname, _ := s.Finalize() |
| 116 | b, err := os.ReadFile(fname) |
| 117 | if err != nil { |
| 118 | t.Fatalf("read file: %v", err) |
| 119 | } |
| 120 | if !bytes.Equal(b[:len(data)], data) { |
| 121 | t.Fatalf("file contents differ") |
| 122 | } |
| 123 | } |
nothing calls this directly
no test coverage detected