@@ -35,12 +35,12 @@ import (
3535
3636const (
3737 testGitHubDn = "https://localhost:12345"
38- tarballPathTrailer = "/archive/5d5b1bf126485b0e2c972bac41b376438601e266.tar.gz"
38+ archivePathTrailer = "/archive/5d5b1bf126485b0e2c972bac41b376438601e266.tar.gz"
3939 closedServerURL = "https://127.0.0.1:54321"
4040)
4141
42- func TestRepoFromTarballLink (t * testing.T ) {
43- got , err := RepoFromTarballLink (testGitHubDn , testGitHubDn + "/org-name/repo-name" + tarballPathTrailer )
42+ func TestRepoFromArchiveLink (t * testing.T ) {
43+ got , err := repoFromArchiveLink (testGitHubDn , testGitHubDn + "/org-name/repo-name" + archivePathTrailer )
4444 if err != nil {
4545 t .Fatal (err )
4646 }
@@ -53,22 +53,22 @@ func TestRepoFromTarballLink(t *testing.T) {
5353 }
5454}
5555
56- func TestRepoFromTarballLinkErrors (t * testing.T ) {
56+ func TestRepoFromArchiveLink_Error (t * testing.T ) {
5757 for _ , test := range []struct {
5858 name string
59- tarballLink string
59+ archiveLink string
6060 }{
6161 {
6262 name : "URL path does not match prefix" ,
63- tarballLink : "too-short" ,
63+ archiveLink : "too-short" ,
6464 },
6565 {
6666 name : "URL path has only one component after prefix removal" ,
67- tarballLink : testGitHubDn + "/org" ,
67+ archiveLink : testGitHubDn + "/org" ,
6868 },
6969 } {
7070 t .Run (test .name , func (t * testing.T ) {
71- if got , err := RepoFromTarballLink (testGitHubDn , test .tarballLink ); err == nil {
71+ if got , err := repoFromArchiveLink (testGitHubDn , test .archiveLink ); err == nil {
7272 t .Errorf ("expected an error, got=%v" , got )
7373 }
7474 })
@@ -207,26 +207,26 @@ func TestTarballLink(t *testing.T) {
207207 want : "https://test.example.com/my-org/my-repo/archive/def456.tar.gz" ,
208208 },
209209 } {
210- got := TarballLink (test .githubDownload , test .repo , test .sha )
210+ got := tarballLink (test .githubDownload , test .repo , test .sha )
211211 if got != test .want {
212- t .Errorf ("TarballLink () = %q, want %q" , got , test .want )
212+ t .Errorf ("tarballLink () = %q, want %q" , got , test .want )
213213 }
214214 }
215215}
216216
217- func TestDownloadTarballTgzExists (t * testing.T ) {
217+ func TestDownload_TgzExists (t * testing.T ) {
218218 testDir := t .TempDir ()
219219 tarball := makeTestContents (t )
220220 target := path .Join (testDir , "existing-file" )
221221 if err := os .WriteFile (target , tarball .Contents , 0644 ); err != nil {
222222 t .Fatal (err )
223223 }
224- if err := DownloadTarball (t .Context (), target , "https://unused/placeholder.tar.gz" , tarball .Sha256 ); err != nil {
224+ if err := download (t .Context (), target , "https://unused/placeholder.tar.gz" , tarball .Sha256 ); err != nil {
225225 t .Fatal (err )
226226 }
227227}
228228
229- func TestDownloadTarballNeedsDownload (t * testing.T ) {
229+ func TestDownload_NeedsDownload (t * testing.T ) {
230230 testDir := t .TempDir ()
231231 tarball := makeTestContents (t )
232232 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
@@ -239,7 +239,7 @@ func TestDownloadTarballNeedsDownload(t *testing.T) {
239239 defer server .Close ()
240240
241241 expected := path .Join (testDir , "new-file" )
242- if err := DownloadTarball (t .Context (), expected , server .URL + "/placeholder.tar.gz" , tarball .Sha256 ); err != nil {
242+ if err := download (t .Context (), expected , server .URL + "/placeholder.tar.gz" , tarball .Sha256 ); err != nil {
243243 t .Fatal (err )
244244 }
245245 got , err := os .ReadFile (expected )
@@ -251,7 +251,7 @@ func TestDownloadTarballNeedsDownload(t *testing.T) {
251251 }
252252}
253253
254- func TestDownloadTarballChecksumMismatch (t * testing.T ) {
254+ func TestDownload_ChecksumMismatch (t * testing.T ) {
255255 testDir := t .TempDir ()
256256 tarball := makeTestContents (t )
257257 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
@@ -263,7 +263,7 @@ func TestDownloadTarballChecksumMismatch(t *testing.T) {
263263 target := path .Join (testDir , "target-file" )
264264 wrongSha := "0000000000000000000000000000000000000000000000000000000000000000"
265265
266- err := DownloadTarball (t .Context (), target , server .URL + "/test.tar.gz" , wrongSha )
266+ err := download (t .Context (), target , server .URL + "/test.tar.gz" , wrongSha )
267267 if ! errors .Is (err , errChecksumMismatch ) {
268268 t .Fatalf ("expected errChecksumMismatch, got: %v" , err )
269269 }
@@ -272,7 +272,7 @@ func TestDownloadTarballChecksumMismatch(t *testing.T) {
272272 }
273273}
274274
275- func TestDownloadTarball_ContextCanceled (t * testing.T ) {
275+ func TestDownload_ContextCanceled (t * testing.T ) {
276276 testDir := t .TempDir ()
277277 // Set up a mock web server that sleeps to simulate a long download.
278278 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
@@ -285,13 +285,13 @@ func TestDownloadTarball_ContextCanceled(t *testing.T) {
285285 // Create a context that will be canceled explicitly after a short delay.
286286 ctx , cancel := context .WithCancel (t .Context ())
287287 // Start a goroutine to cancel the context after a brief period,
288- // so that `DownloadTarball ` is still in progress when the cancellation occurs.
288+ // so that `download ` is still in progress when the cancellation occurs.
289289 go func () {
290290 time .Sleep (50 * time .Millisecond )
291291 cancel ()
292292 }()
293293
294- err := DownloadTarball (ctx , target , server .URL + "/test.tar.gz" , "any-sha" )
294+ err := download (ctx , target , server .URL + "/test.tar.gz" , "any-sha" )
295295 if ! errors .Is (err , context .Canceled ) {
296296 t .Fatalf ("expected context.Canceled, got: %v" , err )
297297 }
@@ -332,7 +332,7 @@ func TestExtractTarball(t *testing.T) {
332332 }
333333
334334 destDir := t .TempDir ()
335- if err := ExtractTarball (tarballPath , destDir ); err != nil {
335+ if err := extractTarball (tarballPath , destDir ); err != nil {
336336 t .Fatal (err )
337337 }
338338
@@ -393,7 +393,7 @@ func createTestTarball(t *testing.T, topLevelDir string, files map[string]string
393393 return buf .Bytes ()
394394}
395395
396- func TestExtractTarballErrors (t * testing.T ) {
396+ func TestExtractTarball_Errors (t * testing.T ) {
397397 for _ , test := range []struct {
398398 name string
399399 tarballPath func (t * testing.T ) string // Function to create the test file
@@ -467,15 +467,15 @@ func TestExtractTarballErrors(t *testing.T) {
467467 },
468468 } {
469469 t .Run (test .name , func (t * testing.T ) {
470- err := ExtractTarball (test .tarballPath (t ), test .dest (t ))
470+ err := extractTarball (test .tarballPath (t ), test .dest (t ))
471471 if (err != nil ) != test .wantErr {
472- t .Errorf ("ExtractTarball () error = %v, wantErr %v" , err , test .wantErr )
472+ t .Errorf ("extractTarball () error = %v, wantErr %v" , err , test .wantErr )
473473 }
474474 })
475475 }
476476}
477477
478- func TestDownloadTarballErrors (t * testing.T ) {
478+ func TestDownload_Error (t * testing.T ) {
479479 for _ , test := range []struct {
480480 name string
481481 target func (t * testing.T ) string
@@ -523,17 +523,17 @@ func TestDownloadTarballErrors(t *testing.T) {
523523 t .Cleanup (func () {
524524 defaultBackoff = 10 * time .Second
525525 })
526- err := DownloadTarball (context .Background (), test .target (t ), test .url (t ), test .sha )
526+ err := download (context .Background (), test .target (t ), test .url (t ), test .sha )
527527 if (err != nil ) != test .wantErr {
528- t .Errorf ("DownloadTarball () error = %v, wantErr %v" , err , test .wantErr )
528+ t .Errorf ("download () error = %v, wantErr %v" , err , test .wantErr )
529529 }
530530 })
531531 }
532532}
533533
534- func TestDownloadTarballEmptySha (t * testing.T ) {
534+ func TestDownload_EmptySha (t * testing.T ) {
535535 target := path .Join (t .TempDir (), "target" )
536- err := DownloadTarball (t .Context (), target , "https://any-url" , "" )
536+ err := download (t .Context (), target , "https://any-url" , "" )
537537 if ! errors .Is (err , errMissingSHA256 ) {
538538 t .Errorf ("expected errMissingSHA256, got: %v" , err )
539539 }
@@ -632,7 +632,7 @@ func TestLatestCommitAndChecksum(t *testing.T) {
632632 }
633633}
634634
635- func TestDownloadTarballRetryErrorIncludesLastFailure (t * testing.T ) {
635+ func TestDownload_RetryErrorIncludesLastFailure (t * testing.T ) {
636636 defaultBackoff = time .Millisecond
637637 t .Cleanup (func () {
638638 defaultBackoff = 10 * time .Second
@@ -643,7 +643,7 @@ func TestDownloadTarballRetryErrorIncludesLastFailure(t *testing.T) {
643643 defer server .Close ()
644644
645645 target := path .Join (t .TempDir (), "target-file" )
646- err := DownloadTarball (t .Context (), target , server .URL + "/test.tar.gz" , "any-sha" )
646+ err := download (t .Context (), target , server .URL + "/test.tar.gz" , "any-sha" )
647647 if err == nil {
648648 t .Fatal ("expected an error" )
649649 }
@@ -655,7 +655,7 @@ func TestDownloadTarballRetryErrorIncludesLastFailure(t *testing.T) {
655655 }
656656}
657657
658- func TestDownloadTarballRetrySucceeds (t * testing.T ) {
658+ func TestDownload_RetrySucceeds (t * testing.T ) {
659659 defaultBackoff = time .Millisecond
660660 t .Cleanup (func () {
661661 defaultBackoff = 10 * time .Second
@@ -674,7 +674,7 @@ func TestDownloadTarballRetrySucceeds(t *testing.T) {
674674 defer server .Close ()
675675
676676 target := path .Join (t .TempDir (), "target-file" )
677- if err := DownloadTarball (t .Context (), target , server .URL + "/test.tar.gz" , tarball .Sha256 ); err != nil {
677+ if err := download (t .Context (), target , server .URL + "/test.tar.gz" , tarball .Sha256 ); err != nil {
678678 t .Fatal (err )
679679 }
680680
0 commit comments