-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
273 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Go tests | ||
run-name: Running tests 🚀 | ||
on: [push] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 # Checks out the code | ||
- name: Setting Go up | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.19 | ||
- name: test | ||
run: make test | ||
- name: test-race | ||
run: make race |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
.PHONY: test | ||
test: | ||
go test ./... | ||
|
||
.PHONY: race | ||
race: | ||
go test -race ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package dynamo | ||
|
||
import ( | ||
"context" | ||
"github.com/artie-labs/reader/config" | ||
"github.com/stretchr/testify/suite" | ||
"testing" | ||
) | ||
|
||
type DynamoDBTestSuite struct { | ||
suite.Suite | ||
ctx context.Context | ||
} | ||
|
||
func (d *DynamoDBTestSuite) SetupTest() { | ||
d.ctx = context.Background() | ||
d.ctx = config.InjectIntoContext(d.ctx, &config.Settings{}) | ||
} | ||
|
||
func TestDynamoDBTestSuite(t *testing.T) { | ||
suite.Run(t, new(DynamoDBTestSuite)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package dynamo | ||
|
||
import ( | ||
"github.com/artie-labs/transfer/lib/ptr" | ||
"github.com/aws/aws-sdk-go/service/dynamodb" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func (d *DynamoDBTestSuite) TestTransformAttributeValue() { | ||
type _tc struct { | ||
name string | ||
attr *dynamodb.AttributeValue | ||
expectedValue interface{} | ||
} | ||
|
||
tcs := []_tc{ | ||
{ | ||
name: "string", | ||
attr: &dynamodb.AttributeValue{ | ||
S: ptr.ToString("hello"), | ||
}, | ||
expectedValue: "hello", | ||
}, | ||
{ | ||
name: "number", | ||
attr: &dynamodb.AttributeValue{ | ||
N: ptr.ToString("123"), | ||
}, | ||
expectedValue: float64(123), | ||
}, | ||
{ | ||
name: "boolean", | ||
attr: &dynamodb.AttributeValue{ | ||
BOOL: ptr.ToBool(true), | ||
}, | ||
expectedValue: true, | ||
}, | ||
{ | ||
name: "map", | ||
attr: &dynamodb.AttributeValue{ | ||
M: map[string]*dynamodb.AttributeValue{ | ||
"foo": { | ||
S: ptr.ToString("bar"), | ||
}, | ||
"bar": { | ||
N: ptr.ToString("123"), | ||
}, | ||
"nested_map": { | ||
M: map[string]*dynamodb.AttributeValue{ | ||
"foo": { | ||
S: ptr.ToString("bar"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectedValue: map[string]interface{}{ | ||
"foo": "bar", | ||
"bar": float64(123), | ||
"nested_map": map[string]interface{}{ | ||
"foo": "bar", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "list", | ||
attr: &dynamodb.AttributeValue{ | ||
L: []*dynamodb.AttributeValue{ | ||
{ | ||
S: ptr.ToString("foo"), | ||
}, | ||
{ | ||
N: ptr.ToString("123"), | ||
}, | ||
{ | ||
M: map[string]*dynamodb.AttributeValue{ | ||
"foo": { | ||
S: ptr.ToString("bar"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectedValue: []interface{}{ | ||
"foo", | ||
float64(123), | ||
map[string]interface{}{ | ||
"foo": "bar", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "string set", | ||
attr: &dynamodb.AttributeValue{ | ||
SS: []*string{ | ||
ptr.ToString("foo"), | ||
ptr.ToString("bar"), | ||
}, | ||
}, | ||
expectedValue: []string{ | ||
"foo", | ||
"bar", | ||
}, | ||
}, | ||
{ | ||
name: "number set", | ||
attr: &dynamodb.AttributeValue{ | ||
NS: []*string{ | ||
ptr.ToString("123"), | ||
ptr.ToString("456"), | ||
}, | ||
}, | ||
expectedValue: []float64{ | ||
123, | ||
456, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
actualValue := transformAttributeValue(tc.attr) | ||
assert.Equal(d.T(), tc.expectedValue, actualValue, tc.name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.