Skip to content

Commit

Permalink
remove pager package
Browse files Browse the repository at this point in the history
this commit removes pager package infavor of keeping the page structure
local to the notifier package.

Signed-off-by: ldelossa <ldelossa@redhat.com>
  • Loading branch information
ldelossa authored and ldelossa committed Aug 20, 2020
1 parent 223c2ff commit 4d69438
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 33 deletions.
5 changes: 2 additions & 3 deletions httptransport/notificationshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -21,7 +20,7 @@ const (
)

type Response struct {
Page pager.Page `json:"page"`
Page notifier.Page `json:"page"`
Notifications []notifier.Notification `json:"notifications"`
}

Expand Down Expand Up @@ -131,7 +130,7 @@ func (h *NotifHandler) Get(w http.ResponseWriter, r *http.Request) {
}
}

inP := &pager.Page{
inP := &notifier.Page{
Size: pageSize,
Next: next,
}
Expand Down
17 changes: 8 additions & 9 deletions httptransport/notificationshandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions notifier/mockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/pager/pager.go → notifier/pager.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pager
package notifier

import (
"github.com/google/uuid"
Expand Down
3 changes: 1 addition & 2 deletions notifier/postgres/notification_pagination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
}

Expand Down
9 changes: 4 additions & 5 deletions notifier/postgres/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand All @@ -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,
}

Expand All @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions notifier/postgres/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand Down
5 changes: 2 additions & 3 deletions notifier/service/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 2 additions & 3 deletions notifier/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand All @@ -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)
}

Expand Down
3 changes: 1 addition & 2 deletions notifier/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

"github.com/google/uuid"
"github.com/quay/clair/v4/pkg/pager"
)

// PutOpts is provided to Notificationer.Put
Expand Down Expand Up @@ -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
//
Expand Down

0 comments on commit 4d69438

Please sign in to comment.