feat: complete Epic 1 production foundation
This commit is contained in:
@@ -1,28 +1,60 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use crank_core::{
|
||||
ExecutionConfig, HttpMethod, Operation, OperationId, OperationSecurityLevel, OperationStatus,
|
||||
Protocol, RestTarget, Target, ToolDescription,
|
||||
AdapterResponse, ExecutionConfig, ExecutionMode, HttpMethod, Operation, OperationId,
|
||||
OperationSecurityLevel, OperationStatus, PreparedRequest, Protocol, ProtocolAdapter,
|
||||
ProtocolAdapterError, RestTarget, RuntimeRequestContext as ProtocolRequestContext, Target,
|
||||
ToolDescription,
|
||||
};
|
||||
use crank_mapping::MappingSet;
|
||||
use crank_runtime::RuntimeExecutor;
|
||||
use crank_runtime::RuntimeExecutorBuilder;
|
||||
use crank_schema::{Schema, SchemaKind};
|
||||
use serde_json::json;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
#[test]
|
||||
fn prepares_empty_request_for_no_input_get_with_empty_mapping() {
|
||||
let executor = RuntimeExecutor::new();
|
||||
let operation = no_input_get_operation();
|
||||
use crate::support::RuntimeExecutorTestExt;
|
||||
|
||||
let request = executor
|
||||
.prepare_request(&operation.into(), &json!({}))
|
||||
.unwrap();
|
||||
#[tokio::test]
|
||||
async fn prepares_empty_request_for_no_input_get_with_empty_mapping() {
|
||||
let executor = RuntimeExecutorBuilder::new()
|
||||
.register_adapter(Arc::new(EmptyRequestAdapter))
|
||||
.build();
|
||||
let operation = no_input_get_operation().into();
|
||||
|
||||
assert!(request.path_params.is_empty());
|
||||
assert!(request.query_params.is_empty());
|
||||
assert!(request.headers.is_empty());
|
||||
assert!(request.body.is_none());
|
||||
let response = executor.execute(&operation, &json!({})).await.unwrap();
|
||||
assert_eq!(response, json!({}));
|
||||
}
|
||||
|
||||
struct EmptyRequestAdapter;
|
||||
|
||||
#[async_trait]
|
||||
impl ProtocolAdapter for EmptyRequestAdapter {
|
||||
fn protocol(&self) -> Protocol {
|
||||
Protocol::Rest
|
||||
}
|
||||
|
||||
fn supports_mode(&self, mode: ExecutionMode) -> bool {
|
||||
mode == ExecutionMode::Unary
|
||||
}
|
||||
|
||||
async fn invoke_unary(
|
||||
&self,
|
||||
_target: &Target,
|
||||
request: &PreparedRequest,
|
||||
_context: &ProtocolRequestContext,
|
||||
) -> Result<AdapterResponse, ProtocolAdapterError> {
|
||||
assert!(request.path_params.is_empty());
|
||||
assert!(request.query_params.is_empty());
|
||||
assert!(request.headers.is_empty());
|
||||
assert!(request.body.is_none());
|
||||
Ok(AdapterResponse {
|
||||
status_code: 200,
|
||||
headers: BTreeMap::new(),
|
||||
body: json!({}),
|
||||
data: json!({}),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn no_input_get_operation() -> Operation<Schema, MappingSet> {
|
||||
|
||||
Reference in New Issue
Block a user