{"id":21546322,"url":"https://github.com/tyrchen/tonic-mock","last_synced_at":"2025-04-10T05:42:27.933Z","repository":{"id":44736682,"uuid":"347264862","full_name":"tyrchen/tonic-mock","owner":"tyrchen","description":"Test utilities for easy mocking tonic streaming interface","archived":false,"fork":false,"pushed_at":"2024-05-07T03:16:54.000Z","size":15,"stargazers_count":15,"open_issues_count":4,"forks_count":14,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T06:54:42.352Z","etag":null,"topics":["grpc","testing-tools","tonic"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/tonic-mock","language":"Rust","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/tyrchen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-13T03:45:09.000Z","updated_at":"2025-03-05T11:24:27.000Z","dependencies_parsed_at":"2023-01-23T05:46:14.658Z","dependency_job_id":null,"html_url":"https://github.com/tyrchen/tonic-mock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyrchen%2Ftonic-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyrchen%2Ftonic-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyrchen%2Ftonic-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyrchen%2Ftonic-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tyrchen","download_url":"https://codeload.github.com/tyrchen/tonic-mock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248166462,"owners_count":21058478,"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":["grpc","testing-tools","tonic"],"created_at":"2024-11-24T06:09:47.166Z","updated_at":"2025-04-10T05:42:27.905Z","avatar_url":"https://github.com/tyrchen.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tonic-mock\n\n[tonic](https://docs.rs/tonic) is a great crate to build GRPC applications. However, testing RPC built with tonic is not straightforward, especially for the streaming interface. If you have an RPC like this:\n\n```protobuf\nrpc Push(stream RequestPush) returns (stream ResponsePush);\n```\n\nTesting it usually involves lots of effort on properly mocking the data. This little crate helps to make it easier to mock the incoming data and to manipulate the response so that you could focus on testing the logic itself. For example:\n\n```rust\n#[tokio::test]\nasync fn service_push_works() -\u003e anyhow::Result\u003c()\u003e {\n    let mut events: Vec\u003cRequestPush\u003e = Vec::with_capacity(3);\n    for i in 0..3 {\n        events.push(RequestPush::new(id: Bytes::from(i.to_string), data: Bytes::from(\"a\".repeat(10))));\n    }\n\n    // preparing the streaming request\n    let req = tonic_mock::streaming_request(events);\n\n    let server = start_server();\n\n    // call the service\n    let res = server.push(req).await?;\n\n    // iterate the response and assert the result\n    tonic_mock::process_streaming_response(result, |msg, i| {\n        assert!(msg.is_ok());\n        assert_eq!(msg.as_ref().unwrap().code, i as i32);\n    })\n    .await;\n\n    Ok(())\n}\n```\n\nThree main functions provided:\n\n- streaming_request: build streaming requests based on a vector of messages.\n- process_streaming_response: iterate the streaming response and call the closure user provided.\n- stream_to_vec: iterate the streaming response and generate a vector for further processing.\n\nNote these functions are for testing purpose only. DO NOT use them in other cases.\n\n\n## License\n\n`prost-helper` is distributed under the terms of MIT.\n\nSee [LICENSE](LICENSE.md) for details.\n\nCopyright 2021 Tyr Chen\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyrchen%2Ftonic-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftyrchen%2Ftonic-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyrchen%2Ftonic-mock/lists"}