Skip to content

Commit

Permalink
Implement delete table
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Lacasse committed Jul 20, 2023
1 parent 81e4219 commit e39a6cc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
21 changes: 20 additions & 1 deletion handler/deletetable.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,29 @@ package handler

import (
"context"
"encoding/json"
"fmt"

"github.com/aws/aws-sdk-go/service/dynamodb"
)

func DeleteTable(ctx context.Context, s *state, input *dynamodb.DeleteTableInput) (*dynamodb.DeleteTableOutput, error) {
return &dynamodb.DeleteTableOutput{}, nil
key := fmt.Sprintf("$table:%s", *input.TableName)
jsonValue, err := s.kv.Get(ctx, []byte(key))
if err != nil {
return nil, err
}

var td dynamodb.TableDescription
if err = json.Unmarshal(jsonValue, &td); err != nil {
return nil, err
}

if err = s.kv.Delete(ctx, []byte(key)); err != nil {
return nil, err
}

return &dynamodb.DeleteTableOutput{
TableDescription: &td,
}, nil
}
38 changes: 29 additions & 9 deletions itest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,42 @@ func TestInvalidCreateTable(t *testing.T) {
require.Error(t, err)
}

func TestListTables(t *testing.T) {
func TestDeleteTable(t *testing.T) {
ddbSvc := getDDBService(t)

_, err := ddbSvc.ListTables(&dynamodb.ListTablesInput{
Limit: aws.Int64(5),
testTableName := "TestTable"
_, err := ddbSvc.CreateTable(&dynamodb.CreateTableInput{
TableName: aws.String(testTableName),
AttributeDefinitions: []*dynamodb.AttributeDefinition{
{
AttributeName: aws.String("id"),
AttributeType: aws.String(dynamodb.ScalarAttributeTypeS),
},
{
AttributeName: aws.String("value"),
AttributeType: aws.String(dynamodb.ScalarAttributeTypeS),
},
},
KeySchema: []*dynamodb.KeySchemaElement{
{
AttributeName: aws.String("id"),
KeyType: aws.String(dynamodb.KeyTypeHash),
},
},
})
require.NoError(t, err)
}

func TestDeleteTable(t *testing.T) {
ddbSvc := getDDBService(t)

_, err := ddbSvc.DeleteTable(&dynamodb.DeleteTableInput{
TableName: aws.String("TestTable"),
response, err := ddbSvc.DeleteTable(&dynamodb.DeleteTableInput{
TableName: aws.String(testTableName),
})
require.NoError(t, err)
require.NotNil(t, response.TableDescription)
require.Equal(t, *response.TableDescription.TableName, testTableName)

_, err = ddbSvc.DescribeTable(&dynamodb.DescribeTableInput{
TableName: aws.String(testTableName),
})
require.Error(t, err)
}

func TestPutItem(t *testing.T) {
Expand Down

0 comments on commit e39a6cc

Please sign in to comment.