Skip to content

Commit

Permalink
fix: in test scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
maxneuvians authored Jan 20, 2024
1 parent 086a3af commit 6311fd8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/pull_requests_lambda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ jobs:
with:
args: docker restart "${{ job.services.local-kms.id }}"

- name: Install AWS CLI v2
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o /tmp/awscliv2.zip
unzip -q /tmp/awscliv2.zip -d /tmp
rm /tmp/awscliv2.zip
sudo /tmp/aws/install --update
rm -rf /tmp/aws/
- name: Create DynamoDB table
run: |
./.devcontainer/dynamodb-local-create.sh
- name: Install dependencies
run: go get .

Expand Down
22 changes: 22 additions & 0 deletions storage/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ type DynamoDBBackend struct {
table_name string
}

func (b *DynamoDBBackend) createTable() error {
primary_key := "id"

_, err := b.client.CreateTable(context.TODO(), &dynamodb.CreateTableInput{
AttributeDefinitions: []types.AttributeDefinition{
{
AttributeName: &primary_key,
AttributeType: types.ScalarAttributeTypeS,
},
},
KeySchema: []types.KeySchemaElement{
{
AttributeName: &primary_key,
KeyType: types.KeyTypeHash,
},
},
TableName: &b.table_name,
})

return err
}

func (b *DynamoDBBackend) Delete(id uuid.UUID) error {
_, err := b.client.DeleteItem(context.TODO(), &dynamodb.DeleteItemInput{
Key: map[string]types.AttributeValue{
Expand Down
18 changes: 18 additions & 0 deletions storage/dynamodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ import (
"github.com/google/uuid"
)

func TestMain(m *testing.M) {
// Ensure that a DynamoDB table exists
backend := DynamoDBBackend{}

_ = backend.Init(map[string]string{
"endpoint": getDynamoDBHost(),
"region": "ca-central-1",
"table_name": "secrets",
})

_ = backend.createTable()

// setup
code := m.Run()
// teardown
os.Exit(code)
}

func getDynamoDBHost() string {
host := "http://dynamodb-local:8000"

Expand Down

0 comments on commit 6311fd8

Please sign in to comment.