{"id":27147747,"url":"https://github.com/soroushj/grpcmock","last_synced_at":"2026-03-17T13:09:40.295Z","repository":{"id":65695852,"uuid":"597179605","full_name":"soroushj/grpcmock","owner":"soroushj","description":"Mock gRPC servers dynamically in Go","archived":false,"fork":false,"pushed_at":"2024-03-23T09:15:45.000Z","size":18,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-04T04:18:43.539Z","etag":null,"topics":["go-module","golang-module","grpc","grpc-go","mock","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/soroushj.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-03T20:01:28.000Z","updated_at":"2024-10-14T23:27:26.000Z","dependencies_parsed_at":"2024-03-23T11:22:25.284Z","dependency_job_id":"28b73051-765d-49ae-ae03-8f7ac84667fb","html_url":"https://github.com/soroushj/grpcmock","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soroushj%2Fgrpcmock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soroushj%2Fgrpcmock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soroushj%2Fgrpcmock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soroushj%2Fgrpcmock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soroushj","download_url":"https://codeload.github.com/soroushj/grpcmock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247838415,"owners_count":21004576,"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":["go-module","golang-module","grpc","grpc-go","mock","testing"],"created_at":"2025-04-08T11:51:01.532Z","updated_at":"2025-10-31T10:03:34.306Z","avatar_url":"https://github.com/soroushj.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# grpcmock: Mock gRPC servers dynamically in Go\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/soroushj/grpcmock.svg)](https://pkg.go.dev/github.com/soroushj/grpcmock)\n[![CI](https://github.com/soroushj/grpcmock/actions/workflows/ci.yml/badge.svg)](https://github.com/soroushj/grpcmock/actions/workflows/ci.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/soroushj/grpcmock)](https://goreportcard.com/report/github.com/soroushj/grpcmock)\n\nSee [docs and examples on pkg.go.dev](https://pkg.go.dev/github.com/soroushj/grpcmock).\n\nSee the [example](./example/) directory for a complete example.\n\n## Usage\n\n```go\nimport (\n\t\"context\"\n\t\"log\"\n\t\"net\"\n\n\t\"github.com/soroushj/grpcmock\"\n\t\"github.com/soroushj/grpcmock/example/notes\"\n\t\"google.golang.org/grpc\"\n\t\"google.golang.org/grpc/codes\"\n\t\"google.golang.org/grpc/status\"\n)\n\nfunc Example() {\n\t// Create a gRPC server using a grpcmock interceptor\n\tmock := grpcmock.New()\n\tserver := grpc.NewServer(grpc.UnaryInterceptor(mock.UnaryServerInterceptor()))\n\tdefer server.Stop()\n\n\t// Register an implementation of your server; the example Notes server in this case.\n\t// This typically should be the generated Unimplemented implementation.\n\tnotes.RegisterNotesServer(server, \u0026notes.UnimplementedNotesServer{})\n\n\t// Run the server on an available port\n\tlis, err := net.Listen(\"tcp\", \":0\")\n\tif err != nil {\n\t\tlog.Fatalf(\"listen: %v\", err)\n\t}\n\tgo func() {\n\t\tif err := server.Serve(lis); err != nil {\n\t\t\tlog.Fatalf(\"serve at %v: %v\", lis.Addr(), err)\n\t\t}\n\t}()\n\n\t// At this point, all methods on the server will return an Unimplemented error.\n\t// Let's change this behavior for the GetNote method of this server.\n\n\t// This is how you can set a mock response for a method; an error in this case.\n\t// After this, the GetNote method will return a NotFound error.\n\tmock.SetResponse(\"GetNote\", \u0026grpcmock.UnaryResponse{\n\t\tErr: status.Error(codes.NotFound, \"note not found\"),\n\t})\n\n\t// Similarly, you can set a non-error response.\n\t// After this, the GetNote method will return the response below.\n\tmock.SetResponse(\"GetNote\", \u0026grpcmock.UnaryResponse{\n\t\tResp: \u0026notes.GetNoteResponse{\n\t\t\tNote: \u0026notes.Note{\n\t\t\t\tId:   \"1\",\n\t\t\t\tText: \"a\",\n\t\t\t},\n\t\t},\n\t})\n\n\t// If you need something more than a simple response, you can set a handler.\n\t// After this, any call to GetNote will be handled using the function below.\n\tmock.SetHandler(\"GetNote\", func(ctx context.Context, req any) (any, error) {\n\t\tr := req.(*notes.GetNoteRequest)\n\t\tif r.Id == \"1\" {\n\t\t\treturn \u0026notes.GetNoteResponse{\n\t\t\t\tNote: \u0026notes.Note{\n\t\t\t\t\tId:   \"1\",\n\t\t\t\t\tText: \"a\",\n\t\t\t\t},\n\t\t\t}, nil\n\t\t}\n\t\treturn nil, status.Error(codes.NotFound, \"note not found\")\n\t})\n\n\t// You can remove any previously-set response or handler for a method.\n\t// After this, the GetNote method will return an Unimplemented error.\n\tmock.Unset(\"GetNote\")\n\n\t// You can also remove any response or handler for all methods\n\tmock.Clear()\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoroushj%2Fgrpcmock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoroushj%2Fgrpcmock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoroushj%2Fgrpcmock/lists"}