Skip to content

Instantly share code, notes, and snippets.

@subzero112233
Created September 6, 2020 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subzero112233/67443bd0bce3b4448e9b2e0c4ffbcdd7 to your computer and use it in GitHub Desktop.
Save subzero112233/67443bd0bce3b4448e9b2e0c4ffbcdd7 to your computer and use it in GitHub Desktop.
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