{"id":14983602,"url":"https://github.com/kapetndev/grpctest","last_synced_at":"2025-07-13T06:33:11.415Z","repository":{"id":44371841,"uuid":"350003228","full_name":"kapetndev/grpctest","owner":"kapetndev","description":"A module providing utilities for testing gRPC servers","archived":false,"fork":false,"pushed_at":"2023-08-01T13:12:37.000Z","size":183,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T00:11:17.994Z","etag":null,"topics":["golang","grpc","testing"],"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/kapetndev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-21T13:14:09.000Z","updated_at":"2023-04-03T16:12:44.000Z","dependencies_parsed_at":"2024-09-24T15:25:02.523Z","dependency_job_id":"7354b7dc-992d-45cc-a3cc-48d6bf6dd562","html_url":"https://github.com/kapetndev/grpctest","commit_stats":{"total_commits":6,"total_committers":2,"mean_commits":3.0,"dds":"0.16666666666666663","last_synced_commit":"e4ea28b66e1f92842e06a22e204ae492818e3fa9"},"previous_names":["crumbandbase/grpctest"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapetndev%2Fgrpctest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapetndev%2Fgrpctest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapetndev%2Fgrpctest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapetndev%2Fgrpctest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kapetndev","download_url":"https://codeload.github.com/kapetndev/grpctest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243864822,"owners_count":20360360,"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":["golang","grpc","testing"],"created_at":"2024-09-24T14:07:34.554Z","updated_at":"2025-03-16T12:15:26.650Z","avatar_url":"https://github.com/kapetndev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# grpctest ![test](https://github.com/kapetndev/grpctest/workflows/test/badge.svg?event=push)\n\n`grpctest` is a module providing utilities for testing gRPC servers.\nSpecifically it formalises a pattern of writing integration style tests by\nexercising the full gRPC stack.\n\n## Prerequisites\n\nYou will need the following things properly installed on your computer.\n\n- [Go](https://golang.org/): any one of the **three latest major**\n  [releases](https://golang.org/doc/devel/release.html)\n\n## Installation\n\nWith [Go module](https://github.com/golang/go/wiki/Modules) support (Go 1.11+),\nsimply add the following import\n\n```go\nimport \"github.com/kapetndev/grpctest\"\n```\n\nto your code, and then `go [build|run|test]` will automatically fetch the\nnecessary dependencies.\n\nOtherwise, to install the `grpctest` module, run the following command:\n\n```bash\n$ go get -u github.com/kapetndev/grpctest\n```\n\n## Usage\n\nTo use this module start by implementing a gRPC server as defined within\na protocol buffer definition. This will form the system under test. In this\nexample a type implementing the `EchoServer` interface has been created to echo\nback the request to the caller.\n\n```go\npackage server\n\nimport (\n\t\"context\"\n\n\techopb \"github.com/kapetndev/kapetn-api-go/echo/v1\"\n)\n\ntype EchoServer struct {\n\techopb.UnimplementedEchoServiceServer\n}\n\nfunc (s *EchoServer) Echo(ctx context.Context, in *echopb.EchoRequest) (*echopb.EchoResponse, error) {\n\treturn \u0026echopb.EchoResponse{Message: in.Message}, nil\n}\n```\n\nTo then test the server implementation create a gRPC server using the\n`grpctest.NewServer` function. This instantiates a wrapper around a regular\ngRPC server using an in-memory buffer to send and receive data. The wrapper\nalso exposes methods to create gRPC client connections across the buffer. These\nmay be used when instantiating new gRPC clients.\n\nThe example below demonstrates this within the context of a test.\n\n```go\npackage server_test\n\nimport (\n\t\"context\"\n\t\"testing\"\n\n\t\"github.com/kapetndev/echo/internal/server\"\n\t\"github.com/kapetndev/grpctest\"\n  echopb \"github.com/kapetndev/kapetn-api-go/echo/v1\"\n)\n\nfunc setupServer(t *testing.T) (grpctest.Closer, echopb.EchoClient) {\n\ts := grpctest.NewServer()\n\n\tconn, err := s.ClientConn()\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\n\techopb.RegisterEchoServer(s, \u0026server.EchoServer{})\n\ts.Serve()\n\n\treturn s.Close, echopb.NewEchoClient(conn)\n}\n\nfunc TestEcho(t *testing.T) {\n\tt.Run(\"returns the same message sent to the server\", func(t *testing.T) {\n\t\tcloser, client := setupServer(t)\n\t\tdefer closer()\n\n\t\tmessage := \"Hello, world\"\n\t\tresp, err := client.Echo(context.Background(), \u0026echopb.EchoRequest{Message: message})\n\t\tif err != nil {\n\t\t\tt.Errorf(\"expected: nil, got: %v\", err)\n\t\t}\n\n\t\tif resp.Message != message {\n\t\t\tt.Errorf(\"expected: %s, got: %s\", message, resp.Message)\n\t\t}\n\t})\n}\n```\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkapetndev%2Fgrpctest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkapetndev%2Fgrpctest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkapetndev%2Fgrpctest/lists"}