@@ -10,15 +10,31 @@ import (
1010 "github.com/stretchr/testify/require"
1111)
1212
13+ // DynamoDBAPI is the subset of *dynamodb.Client operations used by the helpers in this file.
14+ // Declared as an interface so tests can substitute a mock; a real *dynamodb.Client satisfies it
15+ // automatically.
16+ type DynamoDBAPI interface {
17+ DescribeTable (ctx context.Context , params * dynamodb.DescribeTableInput , optFns ... func (* dynamodb.Options )) (* dynamodb.DescribeTableOutput , error )
18+ DescribeTimeToLive (ctx context.Context , params * dynamodb.DescribeTimeToLiveInput , optFns ... func (* dynamodb.Options )) (* dynamodb.DescribeTimeToLiveOutput , error )
19+ ListTagsOfResource (ctx context.Context , params * dynamodb.ListTagsOfResourceInput , optFns ... func (* dynamodb.Options )) (* dynamodb.ListTagsOfResourceOutput , error )
20+ }
21+
1322// GetDynamoDBTableTagsContextE fetches resource tags of a specified dynamoDB table.
1423// The ctx parameter supports cancellation and timeouts.
1524func GetDynamoDBTableTagsContextE (t testing.TestingT , ctx context.Context , region string , tableName string ) ([]types.Tag , error ) {
16- table , err := GetDynamoDBTableContextE (t , ctx , region , tableName )
25+ client , err := NewDynamoDBClientContextE (t , ctx , region )
1726 if err != nil {
1827 return nil , err
1928 }
2029
21- client , err := NewDynamoDBClientContextE (t , ctx , region )
30+ return GetDynamoDBTableTagsWithClientContextE (t , ctx , client , tableName )
31+ }
32+
33+ // GetDynamoDBTableTagsWithClientContextE fetches resource tags of a specified dynamoDB table using
34+ // the provided DynamoDB client.
35+ // The ctx parameter supports cancellation and timeouts.
36+ func GetDynamoDBTableTagsWithClientContextE (t testing.TestingT , ctx context.Context , client DynamoDBAPI , tableName string ) ([]types.Tag , error ) {
37+ table , err := GetDynamoDBTableWithClientContextE (t , ctx , client , tableName )
2238 if err != nil {
2339 return nil , err
2440 }
@@ -81,6 +97,13 @@ func GetDynamoDBTableTimeToLiveContextE(t testing.TestingT, ctx context.Context,
8197 return nil , err
8298 }
8399
100+ return GetDynamoDBTableTimeToLiveWithClientContextE (t , ctx , client , tableName )
101+ }
102+
103+ // GetDynamoDBTableTimeToLiveWithClientContextE fetches the TTL configuration of a specified
104+ // dynamoDB table using the provided DynamoDB client.
105+ // The ctx parameter supports cancellation and timeouts.
106+ func GetDynamoDBTableTimeToLiveWithClientContextE (t testing.TestingT , ctx context.Context , client DynamoDBAPI , tableName string ) (* types.TimeToLiveDescription , error ) {
84107 out , err := client .DescribeTimeToLive (ctx , & dynamodb.DescribeTimeToLiveInput {
85108 TableName : aws .String (tableName ),
86109 })
@@ -124,6 +147,13 @@ func GetDynamoDBTableContextE(t testing.TestingT, ctx context.Context, region st
124147 return nil , err
125148 }
126149
150+ return GetDynamoDBTableWithClientContextE (t , ctx , client , tableName )
151+ }
152+
153+ // GetDynamoDBTableWithClientContextE fetches information about the specified dynamoDB table using
154+ // the provided DynamoDB client.
155+ // The ctx parameter supports cancellation and timeouts.
156+ func GetDynamoDBTableWithClientContextE (t testing.TestingT , ctx context.Context , client DynamoDBAPI , tableName string ) (* types.TableDescription , error ) {
127157 out , err := client .DescribeTable (ctx , & dynamodb.DescribeTableInput {
128158 TableName : aws .String (tableName ),
129159 })
0 commit comments