Skip to content

Commit

Permalink
Fixes parsing issue #39. (#40)
Browse files Browse the repository at this point in the history
Moves to actual structs from newtypes for the HttpPathModifier.

Signed-off-by: Ryan Thomas <ryan@fl0.com>
  • Loading branch information
rthomas authored Feb 27, 2023
1 parent 16bcf65 commit 92bfcd6
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/httproute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,13 @@ pub enum HttpPathModifier {
/// ReplaceFullPath specifies the value with which to replace the full path
/// of a request during a rewrite or redirect.
#[serde(rename_all = "camelCase")]
ReplaceFullPath(String),
ReplaceFullPath { replace_full_path: String },

/// ReplacePrefixMatch specifies the value with which to replace the prefix
/// match of a request during a rewrite or redirect. For example, a request
/// to "/foo/bar" with a prefix match of "/foo" would be modified to "/bar".
#[serde(rename_all = "camelCase")]
ReplacePrefixMatch(String),
ReplacePrefixMatch { replace_prefix_match: String },
}

/// HTTPRequestRedirect defines a filter that redirects a request. This filter
Expand Down Expand Up @@ -629,3 +629,36 @@ pub struct HttpRouteStatus {
#[serde(flatten)]
pub inner: RouteStatus,
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_deserialize_http_route() {
// Test json with a URLRewrote
let test_json = r#"{
"apiVersion":"gateway.networking.k8s.io/v1beta1",
"kind":"HTTPRoute",
"metadata":{"name":"route_name"},
"spec":{
"parentRefs":null,
"hostnames":null,
"rules":[{
"matches":null,
"filters":[{
"type":"URLRewrite",
"urlRewrite":{
"hostname":null,
"path":{
"type":"ReplacePrefixMatch",
"replacePrefixMatch":"/"
}
}
}],
"backendRefs":null
}]}}"#;
let route: Result<HttpRoute, _> = serde_json::from_str(test_json);
assert!(route.is_ok());
}
}

0 comments on commit 92bfcd6

Please sign in to comment.