Skip to content

Commit

Permalink
Move waitForTable to DynamoDb.WaitForTable
Browse files Browse the repository at this point in the history
This method was originally only a test helper, but we need it for the
upcoming 'elistman create-subscribers-table' command. This is because
we'll need to wait for the table before calling UpdateTimeToLive.
  • Loading branch information
mbland committed May 18, 2023
1 parent 80cb66d commit f11ecc9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
9 changes: 9 additions & 0 deletions db/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ func (db *DynamoDb) CreateTable(ctx context.Context) (err error) {
return
}

func (db *DynamoDb) WaitForTable(
ctx context.Context, maxWait time.Duration,
) error {
input := &dynamodb.DescribeTableInput{TableName: aws.String(db.TableName)}
waiter := dynamodb.NewTableExistsWaiter(db.Client)

return waiter.Wait(ctx, input, maxWait)
}

func (db *DynamoDb) UpdateTimeToLive(
ctx context.Context,
) (ttlSpec *dbtypes.TimeToLiveSpecification, err error) {
Expand Down
11 changes: 1 addition & 10 deletions db/dynamodb_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func setupDynamoDb() (dynDb *DynamoDb, teardown func() error, err error) {
return
} else if err = dynDb.CreateTable(ctx); err != nil {
err = teardownDbWithError(err)
} else if err = waitForTable(ctx, dynDb); err != nil {
} else if err = dynDb.WaitForTable(ctx, maxTableWaitDuration); err != nil {
err = teardownDbWithError(err)
} else {
teardown = func() error {
Expand Down Expand Up @@ -138,15 +138,6 @@ func localDbConfig() (*aws.Config, string, error) {
return dbConfig, endpoint, nil
}

func waitForTable(ctx context.Context, dynDb *DynamoDb) error {
input := &dynamodb.DescribeTableInput{
TableName: aws.String(dynDb.TableName),
}
waiter := dynamodb.NewTableExistsWaiter(dynDb.Client)

return waiter.Wait(ctx, input, maxTableWaitDuration)
}

func newTestSubscriber() *Subscriber {
return NewSubscriber(testutils.RandomString(8) + "@example.com")
}
Expand Down

0 comments on commit f11ecc9

Please sign in to comment.