{"id":15048415,"url":"https://github.com/connormckelvey/go-github-mockable","last_synced_at":"2026-01-02T11:23:08.099Z","repository":{"id":63255657,"uuid":"565572764","full_name":"connormckelvey/go-github-mockable","owner":"connormckelvey","description":"Mockable, interface-based wrapper for the github.com/google/go-github *Client","archived":false,"fork":false,"pushed_at":"2022-11-15T22:23:05.000Z","size":198,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-20T18:33:10.423Z","etag":null,"topics":["github","go-github","golang","gomock","mocking"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/connormckelvey.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":"2022-11-13T20:29:01.000Z","updated_at":"2022-11-15T22:28:16.000Z","dependencies_parsed_at":"2022-11-15T23:00:19.275Z","dependency_job_id":null,"html_url":"https://github.com/connormckelvey/go-github-mockable","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/connormckelvey%2Fgo-github-mockable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/connormckelvey%2Fgo-github-mockable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/connormckelvey%2Fgo-github-mockable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/connormckelvey%2Fgo-github-mockable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/connormckelvey","download_url":"https://codeload.github.com/connormckelvey/go-github-mockable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243495495,"owners_count":20299923,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["github","go-github","golang","gomock","mocking"],"created_at":"2024-09-24T21:11:33.470Z","updated_at":"2026-01-02T11:23:08.071Z","avatar_url":"https://github.com/connormckelvey.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go Github Mockable\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/connormckelvey/go-github-mockable.svg)](https://pkg.go.dev/github.com/connormckelvey/go-github-mockable) [![Go Report Card](https://goreportcard.com/badge/github.com/connormckelvey/go-github-mockable)](https://goreportcard.com/report/github.com/connormckelvey/go-github-mockable)\n\nGo Github Mockable provides an interface-based wrapper for the [Go Github](https://github.com/google/go-github) client, making it possible to generate mocks (also included) for the client using [GoMock](https://github.com/golang/mock). \n\n## Installation\n\n```bash\n$ go get github.com/connormckelvey/go-github-mockable\n```\n\n## Features\n\n### [ClientAPI interface type](https://pkg.go.dev/github.com/connormckelvey/go-github-mockable#ClientAPI) \n\nInterface type to be used in place of `*github.Client`. Allows dependency injection of a mocked `ClientAPI`. \n\nFor example\n\n```go\n\ntype MyService struct {\n    github *github.Client\n}\n\nfunc NewMyService(client *github.Client) *Service {\n    return \u0026MyService{\n        github: client,\n    }\n}\n\n//becomes:\n\ntype MyService struct {\n    github gogithubmockable.ClientAPI\n}\n\nfunc NewMyService(client gogithubmockable.ClientAPI) *Service {\n    return \u0026MyService{\n        github: client,\n    }\n}\n```\n\n### [ClientAPI implementation](https://pkg.go.dev/github.com/connormckelvey/go-github-mockable#Client)\n\n`gogithubmockable.Client` provides a default implementation of `gogithubmockable.ClientAPI` by dispatching calls to a provided `*github.Client` \n\nFor example:\n\n```go\n\nfunc main() {\n    gh := github.NewClient(nil)\n    client := gogithubmockable.NewClient(gh)\n\n    service := NewMyService(client)\n    ...\n}\n\n\nfunc TestMyService(t *testing.T) {\n    ctrl := gomock.NewController(t)\n\n\tmockClient := mocks.NewMockClientAPI(ctrl)\n    service := NewMYService(mockClient)\n}\n```\n\n\n### [Services Getter Methods](https://pkg.go.dev/github.com/connormckelvey/go-github-mockable#Client.Actions)\n\nThe `ClientAPI` interface include getter methods for every service normally available on the `*github.Client` struct. The return types for the getter methods are themselves interfaces allowing services to be independently mocked. \n\nFor example\n\n```go\nfunc (s *MyService) Foo() {\n    repo, _, err := s.github.Repositories.Get(context.Background(), \"owner\", \"repo\")\n    ...\n}\n\n// becomes\n\nfunc (s *MyService) Foo() {\n    repo, _, err := s.github.Repositories().Get(context.Background(), \"owner\", \"repo\")\n    ...\n}\n```\n\n### [Service interfaces](https://pkg.go.dev/github.com/connormckelvey/go-github-mockable#ActionsService)\n\nThe service getter methods included on the `ClientAPI` interface return interface types defined with all public methods included on the original concrete service types. \n\n\n\n## Usage\n\n```go\npackage main\n\nimport (\n    \"github.com/google/go-github/v48/github\"\n    \"github.com/connormckelvey/go-github-mockable\"\n)\n\nfunc main() {\n    gh := github.NewClient(nil)\n    client := gogithubmockable.NewClient(gh)\n\n\n    // Instead of client.Repositories, use client.Repositories()\n    c.Repositories().Get(context.TODO(), \"owner\", \"repo\")\n    ...\n}\n```\n\n### Mocking\n\n```go\nfunc TestMockClientAPI(t *testing.T) {\n\tctrl := gomock.NewController(t)\n\towner := \"connormckelvey\"\n\trepo := \"go-github-mockable\"\n\texpected := fmt.Sprintf(\"%s/%s\", owner, repo)\n\n\trm := mocks.NewMockRepositoriesService(ctrl)\n\trm.EXPECT().Get(gomock.Any(), gomock.Eq(owner), gomock.Eq(repo)).Return(\n\t\t\u0026github.Repository{\n\t\t\tFullName: \u0026expected,\n\t\t},\n\t\t\u0026github.Response{},\n\t\tnil,\n\t)\n\n\tcm := mocks.NewMockClientAPI(ctrl)\n\tcm.EXPECT().Repositories().Return(rm)\n\n\tservice := NewMyService(cm)\n\tfullName, err := service.FullName()\n\trequire.NoError(t, err)\n\tassert.Equal(t, expected, fullName)\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconnormckelvey%2Fgo-github-mockable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconnormckelvey%2Fgo-github-mockable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconnormckelvey%2Fgo-github-mockable/lists"}