@@ -615,6 +615,66 @@ func TestHandleList_PaginationValidCases(t *testing.T) {
615615 }
616616}
617617
618+ func TestHandleGet_ContextCanceled (t * testing.T ) {
619+ repo := & mockRepository {
620+ findByNameFunc : func (_ context.Context , _ string , _ , _ int ) (* PackagePopularity , error ) {
621+ return nil , context .Canceled
622+ },
623+ }
624+
625+ mux := newTestMux (repo )
626+ req := httptest .NewRequest (http .MethodGet , "/api/packages/pacman" , nil )
627+ rr := httptest .NewRecorder ()
628+ mux .ServeHTTP (rr , req )
629+
630+ if rr .Code != http .StatusOK {
631+ t .Errorf ("expected no response written (status 200), got %d" , rr .Code )
632+ }
633+ if rr .Body .Len () != 0 {
634+ t .Errorf ("expected empty body, got %q" , rr .Body .String ())
635+ }
636+ }
637+
638+ func TestHandleList_ContextCanceled (t * testing.T ) {
639+ repo := & mockRepository {
640+ findAllFunc : func (_ context.Context , _ string , _ , _ , _ , _ int ) (* PackagePopularityList , error ) {
641+ return nil , fmt .Errorf ("count packages: %w" , context .Canceled )
642+ },
643+ }
644+
645+ mux := newTestMux (repo )
646+ req := httptest .NewRequest (http .MethodGet , "/api/packages" , nil )
647+ rr := httptest .NewRecorder ()
648+ mux .ServeHTTP (rr , req )
649+
650+ if rr .Code != http .StatusOK {
651+ t .Errorf ("expected no response written (status 200), got %d" , rr .Code )
652+ }
653+ if rr .Body .Len () != 0 {
654+ t .Errorf ("expected empty body, got %q" , rr .Body .String ())
655+ }
656+ }
657+
658+ func TestHandleSeries_ContextCanceled (t * testing.T ) {
659+ repo := & mockRepository {
660+ findSeriesByNameFunc : func (_ context.Context , _ string , _ , _ , _ , _ int ) (* PackagePopularityList , error ) {
661+ return nil , context .Canceled
662+ },
663+ }
664+
665+ mux := newTestMux (repo )
666+ req := httptest .NewRequest (http .MethodGet , "/api/packages/pacman/series" , nil )
667+ rr := httptest .NewRecorder ()
668+ mux .ServeHTTP (rr , req )
669+
670+ if rr .Code != http .StatusOK {
671+ t .Errorf ("expected no response written (status 200), got %d" , rr .Code )
672+ }
673+ if rr .Body .Len () != 0 {
674+ t .Errorf ("expected empty body, got %q" , rr .Body .String ())
675+ }
676+ }
677+
618678func TestHandleList_PaginationInvalidCases (t * testing.T ) {
619679 tests := []struct {
620680 name string
0 commit comments