From 4d69438ee210cf8db6d84b8eea74eb227fb3084a Mon Sep 17 00:00:00 2001 From: ldelossa Date: Wed, 19 Aug 2020 17:03:13 -0400 Subject: [PATCH] remove pager package this commit removes pager package infavor of keeping the page structure local to the notifier package. Signed-off-by: ldelossa --- httptransport/notificationshandler.go | 5 ++--- httptransport/notificationshandler_test.go | 17 ++++++++--------- notifier/mockstore.go | 5 ++--- {pkg/pager => notifier}/pager.go | 2 +- .../postgres/notification_pagination_test.go | 3 +-- notifier/postgres/notifications.go | 9 ++++----- notifier/postgres/store.go | 3 +-- notifier/service/mock.go | 5 ++--- notifier/service/service.go | 5 ++--- notifier/store.go | 3 +-- 10 files changed, 24 insertions(+), 33 deletions(-) rename {pkg/pager => notifier}/pager.go (94%) diff --git a/httptransport/notificationshandler.go b/httptransport/notificationshandler.go index 6980773a10..2aed85a6e8 100644 --- a/httptransport/notificationshandler.go +++ b/httptransport/notificationshandler.go @@ -11,7 +11,6 @@ import ( "github.com/quay/clair/v4/notifier" "github.com/quay/clair/v4/notifier/service" - "github.com/quay/clair/v4/pkg/pager" je "github.com/quay/claircore/pkg/jsonerr" "github.com/rs/zerolog" ) @@ -21,7 +20,7 @@ const ( ) type Response struct { - Page pager.Page `json:"page"` + Page notifier.Page `json:"page"` Notifications []notifier.Notification `json:"notifications"` } @@ -131,7 +130,7 @@ func (h *NotifHandler) Get(w http.ResponseWriter, r *http.Request) { } } - inP := &pager.Page{ + inP := ¬ifier.Page{ Size: pageSize, Next: next, } diff --git a/httptransport/notificationshandler_test.go b/httptransport/notificationshandler_test.go index f018884be8..0c8fc0f129 100644 --- a/httptransport/notificationshandler_test.go +++ b/httptransport/notificationshandler_test.go @@ -12,7 +12,6 @@ import ( "github.com/google/uuid" "github.com/quay/clair/v4/notifier" "github.com/quay/clair/v4/notifier/service" - "github.com/quay/clair/v4/pkg/pager" ) // TestUpdateOperationHandler is a parallel harness for testing a UpdateOperation handler. @@ -60,25 +59,25 @@ func testNotificationHandlerGet(t *testing.T) { t.Parallel() var ( nextID = uuid.New() - inPageWant = pager.Page{ + inPageWant = notifier.Page{ Size: 500, } noteID = uuid.New() - outPageWant = pager.Page{ + outPageWant = notifier.Page{ Size: 500, Next: &nextID, } ) nm := &service.Mock{ - Notifications_: func(ctx context.Context, id uuid.UUID, page *pager.Page) ([]notifier.Notification, pager.Page, error) { + Notifications_: func(ctx context.Context, id uuid.UUID, page *notifier.Page) ([]notifier.Notification, notifier.Page, error) { if !cmp.Equal(id, noteID) { t.Fatalf("got: %v, wanted: %v", id, noteID) } if !cmp.Equal(page, &inPageWant) { t.Fatalf("got: %v, wanted: %v", page, inPageWant) } - return []notifier.Notification{}, pager.Page{ + return []notifier.Notification{}, notifier.Page{ Size: inPageWant.Size, Next: &nextID, }, nil @@ -119,25 +118,25 @@ func testNotificationHandlerGetParams(t *testing.T) { ) var ( nextID = uuid.New() - inPageWant = pager.Page{ + inPageWant = notifier.Page{ Size: 100, } noteID = uuid.New() - outPageWant = pager.Page{ + outPageWant = notifier.Page{ Size: 100, Next: &nextID, } ) nm := &service.Mock{ - Notifications_: func(ctx context.Context, id uuid.UUID, page *pager.Page) ([]notifier.Notification, pager.Page, error) { + Notifications_: func(ctx context.Context, id uuid.UUID, page *notifier.Page) ([]notifier.Notification, notifier.Page, error) { if !cmp.Equal(id, noteID) { t.Fatalf("got: %v, wanted: %v", id, noteID) } if !cmp.Equal(page, &inPageWant) { t.Fatalf("got: %v, wanted: %v", page, inPageWant) } - return []notifier.Notification{}, pager.Page{ + return []notifier.Notification{}, notifier.Page{ Size: inPageWant.Size, Next: &nextID, }, nil diff --git a/notifier/mockstore.go b/notifier/mockstore.go index 2fe65aa09e..c97debc20d 100644 --- a/notifier/mockstore.go +++ b/notifier/mockstore.go @@ -4,12 +4,11 @@ import ( "context" "github.com/google/uuid" - "github.com/quay/clair/v4/pkg/pager" ) // MockStore implements a mock Store. type MockStore struct { - Notifications_ func(ctx context.Context, id uuid.UUID, page *pager.Page) ([]Notification, pager.Page, error) + Notifications_ func(ctx context.Context, id uuid.UUID, page *Page) ([]Notification, Page, error) PutNotifications_ func(ctx context.Context, opts PutOpts) error DeleteNotitfications_ func(ctx context.Context, id uuid.UUID) error Receipt_ func(ctx context.Context, id uuid.UUID) (Receipt, error) @@ -24,7 +23,7 @@ type MockStore struct { // Notifications retrieves the list of notifications associated with a // notification id -func (m *MockStore) Notifications(ctx context.Context, id uuid.UUID, page *pager.Page) ([]Notification, pager.Page, error) { +func (m *MockStore) Notifications(ctx context.Context, id uuid.UUID, page *Page) ([]Notification, Page, error) { return m.Notifications_(ctx, id, page) } diff --git a/pkg/pager/pager.go b/notifier/pager.go similarity index 94% rename from pkg/pager/pager.go rename to notifier/pager.go index 08a09728e0..d84e653749 100644 --- a/pkg/pager/pager.go +++ b/notifier/pager.go @@ -1,4 +1,4 @@ -package pager +package notifier import ( "github.com/google/uuid" diff --git a/notifier/postgres/notification_pagination_test.go b/notifier/postgres/notification_pagination_test.go index 0bf10c52ed..44a054fb36 100644 --- a/notifier/postgres/notification_pagination_test.go +++ b/notifier/postgres/notification_pagination_test.go @@ -8,7 +8,6 @@ import ( "github.com/google/uuid" "github.com/quay/clair/v4/notifier" - "github.com/quay/clair/v4/pkg/pager" "github.com/quay/claircore" "github.com/quay/claircore/test/integration" ) @@ -98,7 +97,7 @@ func TestNotePagination(t *testing.T) { t.Fatalf("failed to insert notifications: %v", err) } - var inPage = pager.Page{ + var inPage = notifier.Page{ Size: tt.pageSize, } diff --git a/notifier/postgres/notifications.go b/notifier/postgres/notifications.go index 379d6575d0..369cb0ec11 100644 --- a/notifier/postgres/notifications.go +++ b/notifier/postgres/notifications.go @@ -7,11 +7,10 @@ import ( "github.com/jackc/pgx/v4/pgxpool" clairerror "github.com/quay/clair/v4/clair-error" "github.com/quay/clair/v4/notifier" - "github.com/quay/clair/v4/pkg/pager" "github.com/rs/zerolog" ) -func notifications(ctx context.Context, pool *pgxpool.Pool, id uuid.UUID, page *pager.Page) ([]notifier.Notification, pager.Page, error) { +func notifications(ctx context.Context, pool *pgxpool.Pool, id uuid.UUID, page *notifier.Page) ([]notifier.Notification, notifier.Page, error) { const ( query = "SELECT id, body FROM notification_body WHERE notification_id = $1" pagedQuery = "SELECT id, body FROM notification_body WHERE notification_id = $1 AND id > $2 ORDER BY id ASC LIMIT $3" @@ -23,7 +22,7 @@ func notifications(ctx context.Context, pool *pgxpool.Pool, id uuid.UUID, page * // if no page argument early return all notifications if page == nil { - p := pager.Page{} + p := notifier.Page{} notifications := make([]notifier.Notification, 0, 0) rows, _ := pool.Query(ctx, query, id.String()) defer rows.Close() @@ -39,7 +38,7 @@ func notifications(ctx context.Context, pool *pgxpool.Pool, id uuid.UUID, page * } // page to return to client - outPage := pager.Page{ + outPage := notifier.Page{ Size: page.Size, } @@ -60,7 +59,7 @@ func notifications(ctx context.Context, pool *pgxpool.Pool, id uuid.UUID, page * var n notifier.Notification err := rows.Scan(&n.ID, &n) if err != nil { - return nil, pager.Page{}, clairerror.ErrBadNotification{id, err} + return nil, notifier.Page{}, clairerror.ErrBadNotification{id, err} } notifications = append(notifications, n) } diff --git a/notifier/postgres/store.go b/notifier/postgres/store.go index 2c8607d7e9..c376f118bf 100644 --- a/notifier/postgres/store.go +++ b/notifier/postgres/store.go @@ -6,7 +6,6 @@ import ( "github.com/google/uuid" "github.com/jackc/pgx/v4/pgxpool" "github.com/quay/clair/v4/notifier" - "github.com/quay/clair/v4/pkg/pager" ) // Store implements the notifier.Store interface @@ -20,7 +19,7 @@ func NewStore(pool *pgxpool.Pool) *Store { // Notifications retrieves the list of notifications associated with a // notification id -func (s *Store) Notifications(ctx context.Context, id uuid.UUID, page *pager.Page) ([]notifier.Notification, pager.Page, error) { +func (s *Store) Notifications(ctx context.Context, id uuid.UUID, page *notifier.Page) ([]notifier.Notification, notifier.Page, error) { return notifications(ctx, s.pool, id, page) } diff --git a/notifier/service/mock.go b/notifier/service/mock.go index ed233fe5a8..963f612595 100644 --- a/notifier/service/mock.go +++ b/notifier/service/mock.go @@ -6,20 +6,19 @@ import ( "github.com/google/uuid" "github.com/quay/clair/v4/notifier" "github.com/quay/clair/v4/notifier/keymanager" - "github.com/quay/clair/v4/pkg/pager" ) var _ Service = (*Mock)(nil) // Mock implements a mock notifier service type Mock struct { - Notifications_ func(ctx context.Context, id uuid.UUID, page *pager.Page) ([]notifier.Notification, pager.Page, error) + Notifications_ func(ctx context.Context, id uuid.UUID, page *notifier.Page) ([]notifier.Notification, notifier.Page, error) DeleteNotifications_ func(ctx context.Context, id uuid.UUID) error KeyStore_ func(ctx context.Context) notifier.KeyStore KeyManager_ func(ctx context.Context) *keymanager.Manager } -func (m *Mock) Notifications(ctx context.Context, id uuid.UUID, page *pager.Page) ([]notifier.Notification, pager.Page, error) { +func (m *Mock) Notifications(ctx context.Context, id uuid.UUID, page *notifier.Page) ([]notifier.Notification, notifier.Page, error) { return m.Notifications_(ctx, id, page) } diff --git a/notifier/service/service.go b/notifier/service/service.go index 4e72c23174..a9976f2666 100644 --- a/notifier/service/service.go +++ b/notifier/service/service.go @@ -17,7 +17,6 @@ import ( "github.com/quay/clair/v4/notifier/postgres" "github.com/quay/clair/v4/notifier/stomp" "github.com/quay/clair/v4/notifier/webhook" - "github.com/quay/clair/v4/pkg/pager" pgdl "github.com/quay/claircore/pkg/distlock/postgres" "github.com/remind101/migrate" "github.com/rs/zerolog" @@ -33,7 +32,7 @@ const ( // This remains an interface so remote clients may implement as well. type Service interface { // Retrieves an optional paginated set of notifications given an notification id - Notifications(ctx context.Context, id uuid.UUID, page *pager.Page) ([]notifier.Notification, pager.Page, error) + Notifications(ctx context.Context, id uuid.UUID, page *notifier.Page) ([]notifier.Notification, notifier.Page, error) // Deletes the provided notification id DeleteNotifications(ctx context.Context, id uuid.UUID) error // KeyStore returns the notifier's KeyStore. @@ -51,7 +50,7 @@ type service struct { keymanager *keymanager.Manager } -func (s *service) Notifications(ctx context.Context, id uuid.UUID, page *pager.Page) ([]notifier.Notification, pager.Page, error) { +func (s *service) Notifications(ctx context.Context, id uuid.UUID, page *notifier.Page) ([]notifier.Notification, notifier.Page, error) { return s.store.Notifications(ctx, id, page) } diff --git a/notifier/store.go b/notifier/store.go index 13a1f99ece..2f8e665c13 100644 --- a/notifier/store.go +++ b/notifier/store.go @@ -4,7 +4,6 @@ import ( "context" "github.com/google/uuid" - "github.com/quay/clair/v4/pkg/pager" ) // PutOpts is provided to Notificationer.Put @@ -42,7 +41,7 @@ type Notificationer interface { // paging has been exhausted. // // Page maybe nil to receive all notifications. - Notifications(ctx context.Context, id uuid.UUID, page *pager.Page) ([]Notification, pager.Page, error) + Notifications(ctx context.Context, id uuid.UUID, page *Page) ([]Notification, Page, error) // PutNotifications persists the provided notifications and associates // them with the provided notification id //