-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_local_test.go
76 lines (57 loc) · 1.55 KB
/
client_local_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//go:build local
package dynamodb
import (
"context"
"log/slog"
"testing"
"github.com/aws/aws-sdk-go-v2/aws"
aws_dynamodb "github.com/aws/aws-sdk-go-v2/service/dynamodb"
aws_dynamodb_types "github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
)
func TestLocalClient(t *testing.T) {
slog.SetLogLoggerLevel(slog.LevelDebug)
ctx := context.Background()
client, err := NewClient(ctx, LOCAL_CLIENT_URI)
if err != nil {
t.Fatalf("Failed to create new client, %v", err)
}
test_table := "test"
table_opts := &CreateTablesOptions{
Tables: map[string]*aws_dynamodb.CreateTableInput{
test_table: &aws_dynamodb.CreateTableInput{
KeySchema: []aws_dynamodb_types.KeySchemaElement{
{
AttributeName: aws.String("Code"),
KeyType: "HASH", // partition key
},
},
AttributeDefinitions: []aws_dynamodb_types.AttributeDefinition{
{
AttributeName: aws.String("Code"),
AttributeType: "S",
},
},
BillingMode: aws_dynamodb_types.BillingModePayPerRequest,
},
},
}
err = CreateTables(ctx, client, table_opts)
if err != nil {
t.Fatalf("Failed to create tables, %v", err)
}
list_opts := &aws_dynamodb.ListTablesInput{}
list_rsp, err := client.ListTables(ctx, list_opts)
if err != nil {
t.Fatalf("Failed to list tables, %v", err)
}
for _, t := range list_rsp.TableNames {
slog.Debug(t)
}
delete_opts := &aws_dynamodb.DeleteTableInput{
TableName: aws.String(test_table),
}
_, err = client.DeleteTable(ctx, delete_opts)
if err != nil {
t.Fatalf("Failed to delete table, %v", err)
}
}