@@ -11,12 +11,14 @@ import (
1111 "github.com/stretchr/testify/require"
1212 "github.com/stretchr/testify/suite"
1313
14- "go-codex-client/communities"
1514 mock_communities "go-codex-client/communities/mock"
1615 "go-codex-client/protobuf"
1716
1817 "go.uber.org/mock/gomock"
1918 "go.uber.org/zap"
19+
20+ "go-codex-client/codexmanifest"
21+ "go-codex-client/communities"
2022)
2123
2224// CodexArchiveDownloaderSuite demonstrates testify's suite functionality
@@ -63,7 +65,7 @@ func (suite *CodexArchiveDownloaderSuite) TestBasicSingleArchive() {
6365 // Set up mock expectations - same as before
6466 suite .mockClient .EXPECT ().
6567 TriggerDownloadWithContext (gomock .Any (), "test-cid-1" ).
66- Return (communities .CodexManifest {Cid : "test-cid-1" }, nil ).
68+ Return (codexmanifest .CodexManifest {Cid : "test-cid-1" }, nil ).
6769 Times (1 )
6870
6971 // First HasCid call returns false, second returns true (simulating polling)
@@ -149,7 +151,7 @@ func (suite *CodexArchiveDownloaderSuite) TestMultipleArchives() {
149151 for _ , cid := range expectedCids {
150152 suite .mockClient .EXPECT ().
151153 TriggerDownloadWithContext (gomock .Any (), cid ).
152- Return (communities .CodexManifest {Cid : cid }, nil ).
154+ Return (codexmanifest .CodexManifest {Cid : cid }, nil ).
153155 Times (1 )
154156
155157 // Each archive becomes available after one poll
@@ -236,7 +238,7 @@ func (suite *CodexArchiveDownloaderSuite) TestErrorDuringTriggerDownload() {
236238 // Mock TriggerDownloadWithContext to simulate an error
237239 suite .mockClient .EXPECT ().
238240 TriggerDownloadWithContext (gomock .Any (), "test-cid-1" ).
239- Return (communities .CodexManifest {}, assert .AnError ). // Return a generic error to simulate failure
241+ Return (codexmanifest .CodexManifest {}, assert .AnError ). // Return a generic error to simulate failure
240242 Times (1 )
241243
242244 // No HasCid calls should be made since TriggerDownload fails
@@ -288,13 +290,13 @@ func (suite *CodexArchiveDownloaderSuite) TestActualCancellationDuringTriggerDow
288290 // Use DoAndReturn to create a realistic TriggerDownload that waits for cancellation
289291 suite .mockClient .EXPECT ().
290292 TriggerDownloadWithContext (gomock .Any (), "test-cid-1" ).
291- DoAndReturn (func (ctx context.Context , cid string ) (communities .CodexManifest , error ) {
293+ DoAndReturn (func (ctx context.Context , cid string ) (codexmanifest .CodexManifest , error ) {
292294 // Simulate work by waiting for context cancellation
293295 select {
294296 case <- time .After (5 * time .Second ): // This should never happen in our test
295- return communities .CodexManifest {Cid : cid }, nil
297+ return codexmanifest .CodexManifest {Cid : cid }, nil
296298 case <- ctx .Done (): // Wait for actual context cancellation
297- return communities .CodexManifest {}, ctx .Err () // Return the actual cancellation error
299+ return codexmanifest .CodexManifest {}, ctx .Err () // Return the actual cancellation error
298300 }
299301 }).
300302 Times (1 )
@@ -352,7 +354,7 @@ func (suite *CodexArchiveDownloaderSuite) TestCancellationDuringPolling() {
352354 // Mock successful TriggerDownload
353355 suite .mockClient .EXPECT ().
354356 TriggerDownloadWithContext (gomock .Any (), "test-cid-1" ).
355- Return (communities .CodexManifest {Cid : "test-cid-1" }, nil ).
357+ Return (codexmanifest .CodexManifest {Cid : "test-cid-1" }, nil ).
356358 Times (1 )
357359
358360 // Mock polling - allow multiple calls, but we'll cancel before completion
@@ -420,7 +422,7 @@ func (suite *CodexArchiveDownloaderSuite) TestPollingTimeout() {
420422 // Mock successful TriggerDownload
421423 suite .mockClient .EXPECT ().
422424 TriggerDownloadWithContext (gomock .Any (), "test-cid-1" ).
423- Return (communities .CodexManifest {Cid : "test-cid-1" }, nil ).
425+ Return (codexmanifest .CodexManifest {Cid : "test-cid-1" }, nil ).
424426 Times (1 )
425427
426428 // Mock polling to always return false (simulating timeout)
@@ -496,7 +498,7 @@ func (suite *CodexArchiveDownloaderSuite) TestWithExistingArchives() {
496498 // Only archive-2 should be downloaded (not in existingArchiveIDs)
497499 suite .mockClient .EXPECT ().
498500 TriggerDownloadWithContext (gomock .Any (), "cid-2" ).
499- Return (communities .CodexManifest {Cid : "cid-2" }, nil ).
501+ Return (codexmanifest .CodexManifest {Cid : "cid-2" }, nil ).
500502 Times (1 ) // Only one call expected
501503
502504 // Only archive-2 should be polled
@@ -577,15 +579,15 @@ func (suite *CodexArchiveDownloaderSuite) TestPartialSuccess_OneSuccessOneError(
577579 // Archive-2 succeeds
578580 suite .mockClient .EXPECT ().
579581 TriggerDownloadWithContext (gomock .Any (), "cid-2" ).
580- Return (communities .CodexManifest {Cid : "cid-2" }, nil )
582+ Return (codexmanifest .CodexManifest {Cid : "cid-2" }, nil )
581583 suite .mockClient .EXPECT ().
582584 HasCid ("cid-2" ).
583585 Return (true , nil )
584586
585587 // Archive-1 fails
586588 suite .mockClient .EXPECT ().
587589 TriggerDownloadWithContext (gomock .Any (), "cid-1" ).
588- Return (communities .CodexManifest {}, fmt .Errorf ("trigger failed" ))
590+ Return (codexmanifest .CodexManifest {}, fmt .Errorf ("trigger failed" ))
589591
590592 logger := zap .NewNop ()
591593 downloader := communities .NewCodexArchiveDownloader (suite .mockClient , index , communityID , []string {}, cancelChan , logger )
@@ -633,22 +635,22 @@ func (suite *CodexArchiveDownloaderSuite) TestPartialSuccess_SuccessErrorCancell
633635 // Archive-3 (newest) succeeds
634636 suite .mockClient .EXPECT ().
635637 TriggerDownloadWithContext (gomock .Any (), "cid-3" ).
636- Return (communities .CodexManifest {Cid : "cid-3" }, nil )
638+ Return (codexmanifest .CodexManifest {Cid : "cid-3" }, nil )
637639 suite .mockClient .EXPECT ().
638640 HasCid ("cid-3" ).
639641 Return (true , nil )
640642
641643 // Archive-2 fails
642644 suite .mockClient .EXPECT ().
643645 TriggerDownloadWithContext (gomock .Any (), "cid-2" ).
644- Return (communities .CodexManifest {}, fmt .Errorf ("trigger failed" ))
646+ Return (codexmanifest .CodexManifest {}, fmt .Errorf ("trigger failed" ))
645647
646648 // Archive-1 will be cancelled (no expectations needed)
647649 suite .mockClient .EXPECT ().
648650 TriggerDownloadWithContext (gomock .Any (), "cid-1" ).
649- DoAndReturn (func (ctx context.Context , cid string ) (communities .CodexManifest , error ) {
651+ DoAndReturn (func (ctx context.Context , cid string ) (codexmanifest .CodexManifest , error ) {
650652 <- ctx .Done () // Wait for cancellation
651- return communities .CodexManifest {}, ctx .Err ()
653+ return codexmanifest .CodexManifest {}, ctx .Err ()
652654 }).
653655 AnyTimes ()
654656
@@ -700,17 +702,17 @@ func (suite *CodexArchiveDownloaderSuite) TestPartialSuccess_SuccessThenCancella
700702 // Archive-2 (newer) succeeds
701703 suite .mockClient .EXPECT ().
702704 TriggerDownloadWithContext (gomock .Any (), "cid-2" ).
703- Return (communities .CodexManifest {Cid : "cid-2" }, nil )
705+ Return (codexmanifest .CodexManifest {Cid : "cid-2" }, nil )
704706 suite .mockClient .EXPECT ().
705707 HasCid ("cid-2" ).
706708 Return (true , nil )
707709
708710 // Archive-1 will be cancelled
709711 suite .mockClient .EXPECT ().
710712 TriggerDownloadWithContext (gomock .Any (), "cid-1" ).
711- DoAndReturn (func (ctx context.Context , cid string ) (communities .CodexManifest , error ) {
713+ DoAndReturn (func (ctx context.Context , cid string ) (codexmanifest .CodexManifest , error ) {
712714 <- ctx .Done () // Wait for cancellation
713- return communities .CodexManifest {}, ctx .Err ()
715+ return codexmanifest .CodexManifest {}, ctx .Err ()
714716 }).
715717 AnyTimes ()
716718
@@ -762,9 +764,9 @@ func (suite *CodexArchiveDownloaderSuite) TestNoSuccess_OnlyCancellation() {
762764 // Both archives will be cancelled
763765 suite .mockClient .EXPECT ().
764766 TriggerDownloadWithContext (gomock .Any (), gomock .Any ()).
765- DoAndReturn (func (ctx context.Context , cid string ) (communities .CodexManifest , error ) {
767+ DoAndReturn (func (ctx context.Context , cid string ) (codexmanifest .CodexManifest , error ) {
766768 <- ctx .Done () // Wait for cancellation
767- return communities .CodexManifest {}, ctx .Err ()
769+ return codexmanifest .CodexManifest {}, ctx .Err ()
768770 }).
769771 AnyTimes ()
770772
@@ -815,10 +817,10 @@ func (suite *CodexArchiveDownloaderSuite) TestNoSuccess_OnlyErrors() {
815817 // Both archives fail
816818 suite .mockClient .EXPECT ().
817819 TriggerDownloadWithContext (gomock .Any (), "cid-1" ).
818- Return (communities .CodexManifest {}, fmt .Errorf ("trigger failed for cid-1" ))
820+ Return (codexmanifest .CodexManifest {}, fmt .Errorf ("trigger failed for cid-1" ))
819821 suite .mockClient .EXPECT ().
820822 TriggerDownloadWithContext (gomock .Any (), "cid-2" ).
821- Return (communities .CodexManifest {}, fmt .Errorf ("trigger failed for cid-2" ))
823+ Return (codexmanifest .CodexManifest {}, fmt .Errorf ("trigger failed for cid-2" ))
822824
823825 logger := zap .NewNop ()
824826 downloader := communities .NewCodexArchiveDownloader (suite .mockClient , index , communityID , []string {}, cancelChan , logger )
0 commit comments