Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Aug 6, 2024
1 parent a012805 commit 8eb4c31
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
70 changes: 70 additions & 0 deletions lib/s3lib/dynamodb_export_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package s3lib

import (
"github.com/aws/aws-sdk-go-v2/service/dynamodbstreams/types"
"github.com/stretchr/testify/assert"
"testing"
)
Expand Down Expand Up @@ -29,3 +30,72 @@ func TestAssertType(t *testing.T) {
assert.ErrorContains(t, err, "expected type bool, got string")
}
}

const validDynamoDBJSON = `{
"Item": {
"account_id": {
"S": "account-9825"
},
"user_id": {
"S": "user_id_1"
},
"is_null": {
"NULL": true
},
"sample_list": {
"L": [
{
"S": "item1"
},
{
"N": "2"
}
]
},
"flag": {
"BOOL": false
},
"string_set": {
"SS": [
"value2",
"value44",
"value55",
"value66",
"value1"
]
},
"random_number": {
"N": "4851973137566368817"
},
"number_set": {
"NS": [
"3",
"2",
"1"
]
},
"sample_map": {
"M": {
"key1": {
"S": "value1"
},
"key2": {
"N": "2"
}
}
}
}
}`

func TestParseDynamoDBJSON(t *testing.T) {
{
// Valid JSON
value, err := parseDynamoDBJSON([]byte(validDynamoDBJSON))
assert.NoError(t, err)
assert.Equal(t, 9, len(value))

// Check keys
value, isOk := value["account_id"].(*types.AttributeValueMemberS{})

Check failure on line 98 in lib/s3lib/dynamodb_export_test.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected {, expected )

Check failure on line 98 in lib/s3lib/dynamodb_export_test.go

View workflow job for this annotation

GitHub Actions / test

expected ')', found '{' (compile)
assert.True(t, isOk)
}
}

Check failure on line 101 in lib/s3lib/dynamodb_export_test.go

View workflow job for this annotation

GitHub Actions / test

syntax error: non-declaration statement outside function body (compile)
3 changes: 1 addition & 2 deletions lib/s3lib/s3lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ func (s *S3Client) StreamJsonGzipFile(ctx context.Context, file S3File, ch chan<
scanner.Buffer(buf, maxBufferSize)

for scanner.Scan() {
line := scanner.Bytes()
output, err := parseDynamoDBJSON(line)
output, err := parseDynamoDBJSON(scanner.Bytes())
if err != nil {
return fmt.Errorf("failed to parse dynamodb json: %w", err)
}
Expand Down

0 comments on commit 8eb4c31

Please sign in to comment.