Skip to content

Commit

Permalink
Integration test for DebugFilter
Browse files Browse the repository at this point in the history
Work on #1
  • Loading branch information
markmandel committed Jul 30, 2020
1 parent 32df637 commit 62a13d6
Showing 1 changed file with 69 additions and 1 deletion.
70 changes: 69 additions & 1 deletion tests/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ extern crate quilkin;
mod tests {
use std::net::{IpAddr, Ipv4Addr, SocketAddr};

use serde_yaml::{Mapping, Value};
use slog::info;

use quilkin::config::{Config, ConnectionConfig, EndPoint, Filter, Local};
use quilkin::extensions::default_registry;
use quilkin::extensions::filters::DebugFilterFactory;
use quilkin::extensions::{default_registry, FilterFactory};
use quilkin::test_utils::{
echo_server, logger, recv_multiple_packets, run_proxy, TestFilterFactory,
};
Expand Down Expand Up @@ -120,4 +122,70 @@ mod tests {
close_server();
close_client();
}

#[tokio::test]
async fn debug_filter() {
let base_logger = logger();
// handy for grabbing the configuration name
let factory = DebugFilterFactory::new(&base_logger);

// create two echo servers as endpoints
let echo = echo_server().await;

// filter config
let mut map = Mapping::new();
map.insert(Value::from("id"), Value::from("server"));
// create server configuration
let server_port = 12247;
let server_config = Config {
local: Local { port: server_port },
filters: vec![Filter {
name: factory.name(),
config: serde_yaml::Value::Mapping(map),
}],
connections: ConnectionConfig::Server {
endpoints: vec![EndPoint {
name: "server".to_string(),
address: echo,
connection_ids: vec![],
}],
},
};
let close_server = run_proxy(&base_logger, default_registry(&base_logger), server_config);

let mut map = Mapping::new();
map.insert(Value::from("id"), Value::from("client"));
// create a local client
let client_port = 12248;
let client_config = Config {
local: Local { port: client_port },
filters: vec![Filter {
name: factory.name(),
config: serde_yaml::Value::Mapping(map),
}],
connections: ConnectionConfig::Client {
addresses: vec![SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
server_port,
)],
connection_id: String::from(""),
lb_policy: None,
},
};
let close_client = run_proxy(&base_logger, default_registry(&base_logger), client_config);

// let's send the packet
let (mut recv_chan, mut send) = recv_multiple_packets(&base_logger).await;

// game client
let local_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), client_port);
info!(base_logger, "Sending hello"; "addr" => local_addr);
send.send_to("hello".as_bytes(), &local_addr).await.unwrap();

// since the debug filter doesn't change the data, it should be exactly the same
assert_eq!("hello", recv_chan.recv().await.unwrap());

close_server();
close_client();
}
}

0 comments on commit 62a13d6

Please sign in to comment.