Created
September 6, 2020 10:23
-
-
Save subzero112233/67443bd0bce3b4448e9b2e0c4ffbcdd7 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"fmt" | |
"testing" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/service/dynamodb" | |
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface" | |
"github.com/stretchr/testify/assert" | |
) | |
type DynamodbMockClient struct { | |
dynamodbiface.DynamoDBAPI | |
} | |
func (m *DynamodbMockClient) GetItem(input *dynamodb.GetItemInput) ( | |
*dynamodb.GetItemOutput, | |
error, | |
) { | |
return &dynamodb.GetItemOutput{ | |
Item: map[string]*dynamodb.AttributeValue{ | |
"PlayerName": {S: aws.String("Manu Ginobili")}, | |
"JerseyNumber": {N: aws.String("20")}, | |
"Position": {S: aws.String("Shooting Guard")}, | |
}, | |
}, nil | |
} | |
func TestGetItem(t *testing.T) { | |
scans_table := "SanAntonioSpurs-TEST" | |
conf, err := InitializeConfig() | |
assert.Equal(t, err, nil, "returned an error when it shouldn't have") | |
conf.DynamoDB = &DynamodbMockClient{} | |
x := &Item{} | |
x.PlayerName.Value = "Manu Ginobili" | |
x.JerseyNumber.Value = "20" | |
i, err := getItem(conf, scans_table, x) | |
fmt.Println(i) | |
assert.Equal(t, err, nil, "returned an error when it shouldn't have") | |
assert.Equal(t, i["PlayerName"], x.PlayerName.Value, "returned item from dynamo doesn't match") | |
assert.Equal(t, i["JerseyNumber"], x.JerseyNumber.Value, "returned item from dynamo doesn't match") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment