{"id":37183192,"url":"https://github.com/groovili/go-dynamock-v2","last_synced_at":"2026-01-14T21:09:11.082Z","repository":{"id":57481998,"uuid":"189232688","full_name":"groovili/go-dynamock-v2","owner":"groovili","description":"Amazon DynamoDB mock for unit testing","archived":false,"fork":true,"pushed_at":"2019-06-06T10:46:48.000Z","size":80,"stargazers_count":4,"open_issues_count":0,"forks_count":5,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-11-17T12:42:33.094Z","etag":null,"topics":["aws","dynamo","go","golang-package","mock","test"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"gusaul/go-dynamock","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/groovili.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-29T13:37:37.000Z","updated_at":"2024-04-16T18:11:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/groovili/go-dynamock-v2","commit_stats":null,"previous_names":["groovili/go-dynamock"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/groovili/go-dynamock-v2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/groovili%2Fgo-dynamock-v2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/groovili%2Fgo-dynamock-v2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/groovili%2Fgo-dynamock-v2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/groovili%2Fgo-dynamock-v2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/groovili","download_url":"https://codeload.github.com/groovili/go-dynamock-v2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/groovili%2Fgo-dynamock-v2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28434583,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","dynamo","go","golang-package","mock","test"],"created_at":"2026-01-14T21:09:10.549Z","updated_at":"2026-01-14T21:09:11.072Z","avatar_url":"https://github.com/groovili.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-dynamock-v2\n\n[![GoDoc](https://godoc.org/github.com/groovili/go-dynamock-v2?status.png)](https://godoc.org/github.com/groovili/go-dynamock-v2) \n[![Go Report Card](https://goreportcard.com/badge/github.com/groovili/go-dynamock-v2)](https://goreportcard.com/report/github.com/groovili/go-dynamock-v2) \n[![Build Status](https://api.travis-ci.org/groovili/go-dynamock-v2.svg?branch=master)](https://travis-ci.org/groovili/go-dynamock-v2)\n[![Codecov](https://codecov.io/gh/groovili/go-dynamock-v2/branch/master/graphs/badge.svg?branch=master)](https://codecov.io/gh/groovili/go-dynamock-v2)\n\nAmazon DynamoDB mock for unit testing, fully compatible with [SDK](https://github.com/aws/aws-sdk-go-v2).\n\nVisit [GoDoc](https://godoc.org/github.com/groovili/go-dynamock-v2) for public API documentation.\n\nThanks to [gusaul](https://github.com/gusaul)  for the first version of package [go-dynamock](https://github.com/gusaul/go-dynamock).\n\n## Requirements\n\n- Go \u003e= 1.11.x\n- [AWS SDK GO V2](https://github.com/aws/aws-sdk-go-v2) \u003e= v0.9.0\n\n\n## Usage\nTo use mock you should depend in your code on [ClientAPI interface](https://github.com/aws/aws-sdk-go-v2/tree/master/service/dynamodb/dynamodbiface), instead of dependency on specific DynamoDB instance.\n\n``` go\npackage main\n\nimport (\n    \"github.com/aws/aws-sdk-go-v2/service/dynamodb/dynamodbiface\"\n)\n\ntype Service struct {\n    DynamoDB dynamodbiface.ClientAPI\n}\n\nfunc NewService (dynamo dynamodbiface.ClientAPI) *Service {\n    return \u0026Service{\n        DynamoDB: dynamo,\n    }\n}\n```\n\n#### Function you want to test\n``` go\npackage main\n\nimport (\n    \"context\"\n    \"strconv\"\n    \n    \"github.com/aws/aws-sdk-go-v2/aws\"\n    \"github.com/aws/aws-sdk-go-v2/service/dynamodb\"\n    \"github.com/aws/aws-sdk-go-v2/service/dynamodb/dynamodbattribute\"\n)\n\nfunc GetNameByID(ID int) (*string, error) {\n\tparam := \u0026dynamodb.GetItemInput{\n\t\tKey: map[string]dynamodb.AttributeValue{\n\t\t\t\"id\": {\n\t\t\t\tN: aws.String(strconv.Itoa(ID)),\n\t\t\t},\n\t\t},\n\t\tTableName: aws.String(\"employee\"),\n\t}\n\n\treq := Fake.DB.GetItemRequest(param)\n\tif req.Error != nil {\n\t\treturn nil, req.Error\n\t}\n\n\tvar value *string\n\toutput, err := req.Send(context.Background())\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif v, ok := output.Item[\"name\"]; ok {\n\t\terr := dynamodbattribute.Unmarshal(\u0026v, \u0026value)\n\t\tif err != nil {\n\t\t\treturn value, err\n\t\t}\n\t}\n\n\treturn value, nil\n}\n```\n\n#### Test\n``` go\npackage examples\n\nimport (\n\t\"strconv\"\n\t\"testing\"\n\n\tdynamock \"github.com/groovili/go-dynamock-v2\"\n\n\t\"github.com/aws/aws-sdk-go-v2/aws\"\n\t\"github.com/aws/aws-sdk-go-v2/service/dynamodb\"\n)\n\nfunc init() {\n\tFake = new(FakeDynamo)\n\tFake.DB, Mock = dynamock.New()\n}\n\nfunc TestGetItem(t *testing.T) {\n\tID := 123\n\texpectKey := map[string]dynamodb.AttributeValue{\n\t\t\"id\": {\n\t\t\tN: aws.String(strconv.Itoa(ID)),\n\t\t},\n\t}\n\n\texpectedResult := \"rick sanchez\"\n\tresult := dynamodb.GetItemResponse{\n\t\tGetItemOutput: \u0026dynamodb.GetItemOutput{\n\t\t\tItem: map[string]dynamodb.AttributeValue{\n\t\t\t\t\"id\": {\n\t\t\t\t\tN: aws.String(strconv.Itoa(ID)),\n\t\t\t\t},\n\t\t\t\t\"name\": {\n\t\t\t\t\tS: aws.String(expectedResult),\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t}\n\n\tMock.ExpectGetItem().Table(\"employee\").WithKeys(expectKey).WillReturn(result)\n\n\tactualResult, err := GetNameByID(ID)\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\n\tif aws.StringValue(actualResult) != expectedResult {\n\t\tt.Fatalf(\"Fail: expected: %s, got: %s\", expectedResult, aws.StringValue(actualResult))\n\t}\n}\n```\n\n## Currently Supported Functions\n``` go\nGetItemRequest(*dynamodb.GetItemInput) dynamodb.GetItemRequest\nPutItemRequest(*dynamodb.PutItemInput) dynamodb.PutItemRequest\nUpdateItemRequest(*dynamodb.UpdateItemInput) dynamodb.UpdateItemRequest\nDeleteItemRequest(*dynamodb.DeleteItemInput) dynamodb.DeleteItemRequest\nBatchGetItemRequest(*dynamodb.BatchGetItemInput) dynamodb.BatchGetItemRequest\nBatchWriteItemRequest(*dynamodb.BatchWriteItemInput) dynamodb.BatchWriteItemRequest\nScanRequest(*dynamodb.ScanInput) dynamodb.ScanRequest\nQueryRequest(*dynamodb.QueryInput) dynamodb.QueryRequest\nCreateTableRequest(*dynamodb.CreateTableInput) dynamodb.CreateTableRequest\nDescribeTableRequest(*dynamodb.DescribeTableInput) dynamodb.DescribeTableRequest\nWaitUntilTableExists(context.Context, *dynamodb.DescribeTableInput, ...aws.WaiterOption) error\n```\n\n## Contributions\n\nFeel free to open a pull request.\n\n## License\n\nThe [MIT License](https://github.com/groovili/go-dynamock-v2/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgroovili%2Fgo-dynamock-v2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgroovili%2Fgo-dynamock-v2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgroovili%2Fgo-dynamock-v2/lists"}