{"action":"created","comment":{"url":"https://api.github.com/repos/uber-go/dosa/pulls/comments/114226807","pull_request_review_id":35676047,"id":114226807,"diff_hunk":"@@ -0,0 +1,70 @@\n+# Examples: Testing\n+\n+The example here demonstrates how to write tests for code that uses the DOSA\n+client. For now, we are suggesting the use of a mock client that we have\n+generated using [MockGen](https://github.com/golang/mock). It's available\n+as `(github.com/uber-go/dosa/mocks).MockClient`.\n+\n+## `MockClient` Usage\n+\n+Given an entity defined as:\n+\n+    type User struct {\n+        dosa.Entity `dosa:\"primaryKey=UUID\"`\n+        UUID        dosa.UUID\n+        Name        string\n+        Email       string\n+        CreatedOn   time.Time\n+    }\n+\n+And a method that operates on that entity called `GetUser`:\n+\n+    type Datastore struct {\n+        client dosa.Client\n+    }\n+\n+    func (d *Datastore) GetUser(ctx context.Context, uuid dosa.UUID) (*User, error) {\n+        user := &User{uuid: uuid}\n+        readCtx, readCancel := context.WithTimeout(ctx, 1 * time.Second)\n+        if err := d.client.Read(readCts\n+    }\n+\n+The `client` behavior can then be mocked using `MockClient`:\n+\n+    package datastore_test\n+\n+    import (\n+        \"github.com/golang/mock/gomock\"\n+        \"github.com/stretchr/testify/assert\"\n+\n+        \"github.com/uber-go/dosa\"\n+        examples \"github.com/uber-go/dosa/examples/testing\"\n+        \"github.com/uber-go/dosa/mocks\"\n+    )\n+\n+    func TestGetUser(t *testing.T) {\n+        ctrl := gomock.NewController(t)\n+        defer ctrl.Finish()\n+\n+        // mock error from `Read` call\n+        c1 := mocks.NewMockClient(ctrl)\n+        c1.EXPECT().Initialize(gomock.Any()).Return(nil).Times(1)\n+        c1.EXPECT().Read(gomock.Any(), nil, user).Return(errors.New(\"Read Error\")).Times(1)\n+        ds1, _ := examples.NewDatastore(c1)\n+\n+        u1, err1 := ds1.GetUser(ctx, uuid)\n+        assert.Error(t, err1)\n+        assert.Nil(t, u1)\n+\n+        // happy path\n+        c2 := mocks.NewMockClient(ctrl)\n+        c2.EXPECT().Initialize(gomock.Any()).Return(nil).Times(1)\n+        c2.EXPECT().Read(gomock.Any(), nil, user).Return(nil).Times(1)\n+        ds2, _ := examples.NewDatastore(c2)\n+\n+        u2, err2 := ds2.GetUser(ctx, uuid)\n+        assert.NoError(t, err2)\n+        assert.Equal(t, u2, user)\n+    }\n+\n+A complete, runnable example of this can be found in our [testing examples package](https://github.com/uber-go/dosa/tree/master/examples/testing).","path":"examples/testing/README.md","position":70,"original_position":70,"commit_id":"d4a30417f0ff1fedae6a37f6e3d72ee33aa08763","original_commit_id":"32fe4fc73123be824840cdd7259c3704249968b0","user":{"login":"eculver","id":40828,"avatar_url":"https://avatars0.githubusercontent.com/u/40828?v=3","gravatar_id":"","url":"https://api.github.com/users/eculver","html_url":"https://github.com/eculver","followers_url":"https://api.github.com/users/eculver/followers","following_url":"https://api.github.com/users/eculver/following{/other_user}","gists_url":"https://api.github.com/users/eculver/gists{/gist_id}","starred_url":"https://api.github.com/users/eculver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eculver/subscriptions","organizations_url":"https://api.github.com/users/eculver/orgs","repos_url":"https://api.github.com/users/eculver/repos","events_url":"https://api.github.com/users/eculver/events{/privacy}","received_events_url":"https://api.github.com/users/eculver/received_events","type":"User","site_admin":false},"body":"ACK. Can just run `make mocks` now. I also added a README.","created_at":"2017-05-02T00:01:08Z","updated_at":"2017-05-02T00:01:08Z","html_url":"https://github.com/uber-go/dosa/pull/139#discussion_r114226807","pull_request_url":"https://api.github.com/repos/uber-go/dosa/pulls/139","_links":{"self":{"href":"https://api.github.com/repos/uber-go/dosa/pulls/comments/114226807"},"html":{"href":"https://github.com/uber-go/dosa/pull/139#discussion_r114226807"},"pull_request":{"href":"https://api.github.com/repos/uber-go/dosa/pulls/139"}}},"pull_request":{"url":"https://api.github.com/repos/uber-go/dosa/pulls/139","id":118453178,"html_url":"https://github.com/uber-go/dosa/pull/139","diff_url":"https://github.com/uber-go/dosa/pull/139.diff","patch_url":"https://github.com/uber-go/dosa/pull/139.patch","issue_url":"https://api.github.com/repos/uber-go/dosa/issues/139","number":139,"state":"open","locked":false,"title":"Add mock client","user":{"login":"eculver","id":40828,"avatar_url":"https://avatars0.githubusercontent.com/u/40828?v=3","gravatar_id":"","url":"https://api.github.com/users/eculver","html_url":"https://github.com/eculver","followers_url":"https://api.github.com/users/eculver/followers","following_url":"https://api.github.com/users/eculver/following{/other_user}","gists_url":"https://api.github.com/users/eculver/gists{/gist_id}","starred_url":"https://api.github.com/users/eculver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eculver/subscriptions","organizations_url":"https://api.github.com/users/eculver/orgs","repos_url":"https://api.github.com/users/eculver/repos","events_url":"https://api.github.com/users/eculver/events{/privacy}","received_events_url":"https://api.github.com/users/eculver/received_events","type":"User","site_admin":false},"body":"This adds a mock client implementation generated by gomock and runnable examples for using it.","created_at":"2017-05-01T22:25:42Z","updated_at":"2017-05-02T00:01:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fb3827f36d2a943ebf5b2802ff2143370a575c1e","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/uber-go/dosa/pulls/139/commits","review_comments_url":"https://api.github.com/repos/uber-go/dosa/pulls/139/comments","review_comment_url":"https://api.github.com/repos/uber-go/dosa/pulls/comments{/number}","comments_url":"https://api.github.com/repos/uber-go/dosa/issues/139/comments","statuses_url":"https://api.github.com/repos/uber-go/dosa/statuses/d4a30417f0ff1fedae6a37f6e3d72ee33aa08763","head":{"label":"uber-go:mock-client","ref":"mock-client","sha":"d4a30417f0ff1fedae6a37f6e3d72ee33aa08763","user":{"login":"uber-go","id":19262598,"avatar_url":"https://avatars1.githubusercontent.com/u/19262598?v=3","gravatar_id":"","url":"https://api.github.com/users/uber-go","html_url":"https://github.com/uber-go","followers_url":"https://api.github.com/users/uber-go/followers","following_url":"https://api.github.com/users/uber-go/following{/other_user}","gists_url":"https://api.github.com/users/uber-go/gists{/gist_id}","starred_url":"https://api.github.com/users/uber-go/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber-go/subscriptions","organizations_url":"https://api.github.com/users/uber-go/orgs","repos_url":"https://api.github.com/users/uber-go/repos","events_url":"https://api.github.com/users/uber-go/events{/privacy}","received_events_url":"https://api.github.com/users/uber-go/received_events","type":"Organization","site_admin":false},"repo":{"id":77975785,"name":"dosa","full_name":"uber-go/dosa","owner":{"login":"uber-go","id":19262598,"avatar_url":"https://avatars1.githubusercontent.com/u/19262598?v=3","gravatar_id":"","url":"https://api.github.com/users/uber-go","html_url":"https://github.com/uber-go","followers_url":"https://api.github.com/users/uber-go/followers","following_url":"https://api.github.com/users/uber-go/following{/other_user}","gists_url":"https://api.github.com/users/uber-go/gists{/gist_id}","starred_url":"https://api.github.com/users/uber-go/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber-go/subscriptions","organizations_url":"https://api.github.com/users/uber-go/orgs","repos_url":"https://api.github.com/users/uber-go/repos","events_url":"https://api.github.com/users/uber-go/events{/privacy}","received_events_url":"https://api.github.com/users/uber-go/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber-go/dosa","description":"DOSA is a data object abstraction layer","fork":false,"url":"https://api.github.com/repos/uber-go/dosa","forks_url":"https://api.github.com/repos/uber-go/dosa/forks","keys_url":"https://api.github.com/repos/uber-go/dosa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber-go/dosa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber-go/dosa/teams","hooks_url":"https://api.github.com/repos/uber-go/dosa/hooks","issue_events_url":"https://api.github.com/repos/uber-go/dosa/issues/events{/number}","events_url":"https://api.github.com/repos/uber-go/dosa/events","assignees_url":"https://api.github.com/repos/uber-go/dosa/assignees{/user}","branches_url":"https://api.github.com/repos/uber-go/dosa/branches{/branch}","tags_url":"https://api.github.com/repos/uber-go/dosa/tags","blobs_url":"https://api.github.com/repos/uber-go/dosa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber-go/dosa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber-go/dosa/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber-go/dosa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber-go/dosa/statuses/{sha}","languages_url":"https://api.github.com/repos/uber-go/dosa/languages","stargazers_url":"https://api.github.com/repos/uber-go/dosa/stargazers","contributors_url":"https://api.github.com/repos/uber-go/dosa/contributors","subscribers_url":"https://api.github.com/repos/uber-go/dosa/subscribers","subscription_url":"https://api.github.com/repos/uber-go/dosa/subscription","commits_url":"https://api.github.com/repos/uber-go/dosa/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber-go/dosa/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber-go/dosa/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber-go/dosa/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber-go/dosa/contents/{+path}","compare_url":"https://api.github.com/repos/uber-go/dosa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber-go/dosa/merges","archive_url":"https://api.github.com/repos/uber-go/dosa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber-go/dosa/downloads","issues_url":"https://api.github.com/repos/uber-go/dosa/issues{/number}","pulls_url":"https://api.github.com/repos/uber-go/dosa/pulls{/number}","milestones_url":"https://api.github.com/repos/uber-go/dosa/milestones{/number}","notifications_url":"https://api.github.com/repos/uber-go/dosa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber-go/dosa/labels{/name}","releases_url":"https://api.github.com/repos/uber-go/dosa/releases{/id}","deployments_url":"https://api.github.com/repos/uber-go/dosa/deployments","created_at":"2017-01-04T03:10:40Z","updated_at":"2017-05-01T18:08:58Z","pushed_at":"2017-05-02T00:00:21Z","git_url":"git://github.com/uber-go/dosa.git","ssh_url":"git@github.com:uber-go/dosa.git","clone_url":"https://github.com/uber-go/dosa.git","svn_url":"https://github.com/uber-go/dosa","homepage":null,"size":10643,"stargazers_count":5,"watchers_count":5,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":5,"default_branch":"master"}},"base":{"label":"uber-go:master","ref":"master","sha":"47f9cce3adcaa21ecc16c2d06e4f9238be3c779d","user":{"login":"uber-go","id":19262598,"avatar_url":"https://avatars1.githubusercontent.com/u/19262598?v=3","gravatar_id":"","url":"https://api.github.com/users/uber-go","html_url":"https://github.com/uber-go","followers_url":"https://api.github.com/users/uber-go/followers","following_url":"https://api.github.com/users/uber-go/following{/other_user}","gists_url":"https://api.github.com/users/uber-go/gists{/gist_id}","starred_url":"https://api.github.com/users/uber-go/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber-go/subscriptions","organizations_url":"https://api.github.com/users/uber-go/orgs","repos_url":"https://api.github.com/users/uber-go/repos","events_url":"https://api.github.com/users/uber-go/events{/privacy}","received_events_url":"https://api.github.com/users/uber-go/received_events","type":"Organization","site_admin":false},"repo":{"id":77975785,"name":"dosa","full_name":"uber-go/dosa","owner":{"login":"uber-go","id":19262598,"avatar_url":"https://avatars1.githubusercontent.com/u/19262598?v=3","gravatar_id":"","url":"https://api.github.com/users/uber-go","html_url":"https://github.com/uber-go","followers_url":"https://api.github.com/users/uber-go/followers","following_url":"https://api.github.com/users/uber-go/following{/other_user}","gists_url":"https://api.github.com/users/uber-go/gists{/gist_id}","starred_url":"https://api.github.com/users/uber-go/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber-go/subscriptions","organizations_url":"https://api.github.com/users/uber-go/orgs","repos_url":"https://api.github.com/users/uber-go/repos","events_url":"https://api.github.com/users/uber-go/events{/privacy}","received_events_url":"https://api.github.com/users/uber-go/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber-go/dosa","description":"DOSA is a data object abstraction layer","fork":false,"url":"https://api.github.com/repos/uber-go/dosa","forks_url":"https://api.github.com/repos/uber-go/dosa/forks","keys_url":"https://api.github.com/repos/uber-go/dosa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber-go/dosa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber-go/dosa/teams","hooks_url":"https://api.github.com/repos/uber-go/dosa/hooks","issue_events_url":"https://api.github.com/repos/uber-go/dosa/issues/events{/number}","events_url":"https://api.github.com/repos/uber-go/dosa/events","assignees_url":"https://api.github.com/repos/uber-go/dosa/assignees{/user}","branches_url":"https://api.github.com/repos/uber-go/dosa/branches{/branch}","tags_url":"https://api.github.com/repos/uber-go/dosa/tags","blobs_url":"https://api.github.com/repos/uber-go/dosa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber-go/dosa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber-go/dosa/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber-go/dosa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber-go/dosa/statuses/{sha}","languages_url":"https://api.github.com/repos/uber-go/dosa/languages","stargazers_url":"https://api.github.com/repos/uber-go/dosa/stargazers","contributors_url":"https://api.github.com/repos/uber-go/dosa/contributors","subscribers_url":"https://api.github.com/repos/uber-go/dosa/subscribers","subscription_url":"https://api.github.com/repos/uber-go/dosa/subscription","commits_url":"https://api.github.com/repos/uber-go/dosa/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber-go/dosa/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber-go/dosa/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber-go/dosa/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber-go/dosa/contents/{+path}","compare_url":"https://api.github.com/repos/uber-go/dosa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber-go/dosa/merges","archive_url":"https://api.github.com/repos/uber-go/dosa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber-go/dosa/downloads","issues_url":"https://api.github.com/repos/uber-go/dosa/issues{/number}","pulls_url":"https://api.github.com/repos/uber-go/dosa/pulls{/number}","milestones_url":"https://api.github.com/repos/uber-go/dosa/milestones{/number}","notifications_url":"https://api.github.com/repos/uber-go/dosa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber-go/dosa/labels{/name}","releases_url":"https://api.github.com/repos/uber-go/dosa/releases{/id}","deployments_url":"https://api.github.com/repos/uber-go/dosa/deployments","created_at":"2017-01-04T03:10:40Z","updated_at":"2017-05-01T18:08:58Z","pushed_at":"2017-05-02T00:00:21Z","git_url":"git://github.com/uber-go/dosa.git","ssh_url":"git@github.com:uber-go/dosa.git","clone_url":"https://github.com/uber-go/dosa.git","svn_url":"https://github.com/uber-go/dosa","homepage":null,"size":10643,"stargazers_count":5,"watchers_count":5,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/uber-go/dosa/pulls/139"},"html":{"href":"https://github.com/uber-go/dosa/pull/139"},"issue":{"href":"https://api.github.com/repos/uber-go/dosa/issues/139"},"comments":{"href":"https://api.github.com/repos/uber-go/dosa/issues/139/comments"},"review_comments":{"href":"https://api.github.com/repos/uber-go/dosa/pulls/139/comments"},"review_comment":{"href":"https://api.github.com/repos/uber-go/dosa/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/uber-go/dosa/pulls/139/commits"},"statuses":{"href":"https://api.github.com/repos/uber-go/dosa/statuses/d4a30417f0ff1fedae6a37f6e3d72ee33aa08763"}}}}
{"actor":{"display_login":"eculver"}}