mirror of
https://codeberg.org/JasterV/granc.git
synced 2026-04-26 18:40:05 +00:00
This PR implements a new subcommand `doc` that generates markdown documentation for a given gRPC service! **Description** For the most part, the inner logic of this subcommand is the same as the `describe`, the only thing that changes is the way that the found descriptor is transformed to a final output. In this case, a `Packages` type has been implemented to transform a `ServiceDescriptor` into a map of `Package`s. Each package groups all the file descriptors with the same package name (or namespace). A `Package` contains all the necessary information for a file of documentation to be generated (All its contained services, messages and enum descriptors and its name). The output of this command is a folder with all the generated documentation, which contains a file per protobuf package. **Introduced the `granc-test-support` crate** * Renamed the `echo_service` crate as `granc-test-support`, providing both the definition of a protobuf service for integration testing and a function to compile protobuffer at runtime into a file descriptor (Potentially this could be used to let users pass a folder to a proto project in addition to the server reflection and the local file descriptor options. For example, the `call` command could compile a file descriptor on the fly from a folder containing a protobuffer project before making the call to the gRPC server. **Descriptor API Enhancements:** * Added `name`, `full_name`, and `package_name` methods to the `Descriptor` enum to simplify access to descriptor metadata. (`granc-core/src/client/types.rs`) **Dependency Management Improvements:** * Added grouping for gRPC-related dependencies in `dependabot.yml` for improved automated dependency updates. (`.github/dependabot.yml`)
49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
use granc_core::client::{Descriptor, GrancClient};
|
|
use granc_test_support::echo_service::FILE_DESCRIPTOR_SET;
|
|
|
|
#[test]
|
|
fn test_offline_list_services() {
|
|
let client = GrancClient::offline(FILE_DESCRIPTOR_SET.to_vec())
|
|
.expect("Failed to load file descriptor set");
|
|
|
|
let mut services = client.list_services();
|
|
services.sort();
|
|
|
|
assert_eq!(services.as_slice(), ["echo.EchoService"]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_offline_describe_descriptors() {
|
|
let client = GrancClient::offline(FILE_DESCRIPTOR_SET.to_vec())
|
|
.expect("Failed to load file descriptor set");
|
|
|
|
// 1. Success: Service
|
|
let desc = client
|
|
.get_descriptor_by_symbol("echo.EchoService")
|
|
.expect("Service not found");
|
|
|
|
assert!(matches!(
|
|
desc,
|
|
Descriptor::ServiceDescriptor(s) if s.name() == "EchoService"
|
|
));
|
|
|
|
// 2. Success: Message
|
|
let desc = client
|
|
.get_descriptor_by_symbol("echo.EchoRequest")
|
|
.expect("Message not found");
|
|
|
|
assert!(matches!(
|
|
desc,
|
|
Descriptor::MessageDescriptor(m) if m.name() == "EchoRequest"
|
|
));
|
|
|
|
// 3. Error: Symbol Not Found
|
|
let desc = client.get_descriptor_by_symbol("echo.Ghost");
|
|
assert!(desc.is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn test_offline_creation_error() {
|
|
let result = GrancClient::offline(vec![0, 1, 2, 3]);
|
|
assert!(result.is_err());
|
|
}
|