Skip to content

Commit

Permalink
Make DynamoDb.getSubscribersInState private
Browse files Browse the repository at this point in the history
Now that ProcessSubscribersInState is in place, there's no need for
clients to bother managing the complexity of getSubscribersInState.
  • Loading branch information
mbland committed May 7, 2023
1 parent ad02bbf commit 44593c4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
3 changes: 0 additions & 3 deletions db/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ type Database interface {
Get(ctx context.Context, email string) (*Subscriber, error)
Put(ctx context.Context, subscriber *Subscriber) error
Delete(ctx context.Context, email string) error
GetSubscribersInState(
context.Context, SubscriberStatus, StartKey,
) ([]*Subscriber, StartKey, error)
ProcessSubscribersInState(
context.Context, SubscriberStatus, SubscriberProcessor,
) error
Expand Down
4 changes: 2 additions & 2 deletions db/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (db *DynamoDb) ProcessSubscribersInState(
var next StartKey

for {
subs, next, err = db.GetSubscribersInState(ctx, status, next)
subs, next, err = db.getSubscribersInState(ctx, status, next)

if err != nil {
return
Expand All @@ -359,7 +359,7 @@ type dynamoDbStartKey struct {

func (*dynamoDbStartKey) isDbStartKey() {}

func (db *DynamoDb) GetSubscribersInState(
func (db *DynamoDb) getSubscribersInState(
ctx context.Context, state SubscriberStatus, startKey StartKey,
) (subs []*Subscriber, nextStartKey StartKey, err error) {
const errFmt = "failed to get %s subscribers: %s"
Expand Down
17 changes: 2 additions & 15 deletions db/dynamodb_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func TestDynamoDb(t *testing.T) {
})
})

t.Run("ProcessSubscribers", func(t *testing.T) {
t.Run("ProcessSubscribersInState", func(t *testing.T) {
emails := make(
[]string,
0,
Expand Down Expand Up @@ -358,20 +358,7 @@ func TestDynamoDb(t *testing.T) {
setup(t)
defer teardown()

t.Run("GetSubscribersInStateSucceeds", func(t *testing.T) {
subs, next, err := testDb.GetSubscribersInState(
ctx, SubscriberVerified, nil,
)

assert.NilError(t, err)
assert.Assert(t, is.Nil(next))

// The ordering here isn't necessarily guaranteed, but expected
// to be the same as insertion.
assert.DeepEqual(t, testVerifiedSubscribers, subs)
})

t.Run("ProcessSubscribersInStateSucceeds", func(t *testing.T) {
t.Run("Succeeds", func(t *testing.T) {
subs := &[]*Subscriber{}
f := SubscriberFunc(func(s *Subscriber) bool {
*subs = append(*subs, s)
Expand Down
8 changes: 4 additions & 4 deletions db/dynamodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func TestGetSubscribersInState(t *testing.T) {
t.Run("Succeeds", func(t *testing.T) {
dyndb, _ := setupDbWithSubscribers()

subs, next, err := dyndb.GetSubscribersInState(
subs, next, err := dyndb.getSubscribersInState(
ctx, SubscriberVerified, nil,
)

Expand All @@ -439,7 +439,7 @@ func TestGetSubscribersInState(t *testing.T) {
t.Run("FailsIfNewScanInputFails", func(t *testing.T) {
dyndb, _ := setupDbWithSubscribers()

subs, next, err := dyndb.GetSubscribersInState(
subs, next, err := dyndb.getSubscribersInState(
ctx, SubscriberVerified, &bogusDbStartKey{})

assert.Assert(t, is.Nil(subs))
Expand All @@ -453,7 +453,7 @@ func TestGetSubscribersInState(t *testing.T) {
dyndb, client := setupDbWithSubscribers()
client.scanErr = errors.New("scanning error")

subs, next, err := dyndb.GetSubscribersInState(
subs, next, err := dyndb.getSubscribersInState(
ctx, SubscriberVerified, nil,
)

Expand All @@ -472,7 +472,7 @@ func TestGetSubscribersInState(t *testing.T) {
string(status): toDynamoDbTimestamp(testTimestamp),
})

subs, _, err := dyndb.GetSubscribersInState(
subs, _, err := dyndb.getSubscribersInState(
ctx, SubscriberVerified, nil,
)

Expand Down

0 comments on commit 44593c4

Please sign in to comment.