-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
End to End test for the TestFilter (#64)
End to end test of the TestFilter implementation, proving an integration test for the full Filter trait experience. Work on #1
- Loading branch information
1 parent
d794f88
commit 9819437
Showing
1 changed file
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright 2020 Google LLC All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
extern crate quilkin; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::net::{IpAddr, Ipv4Addr, SocketAddr}; | ||
|
||
use slog::info; | ||
|
||
use quilkin::config::{Config, ConnectionConfig, EndPoint, Filter, Local}; | ||
use quilkin::extensions::default_filters; | ||
use quilkin::test_utils::{echo_server, logger, recv_multiple_packets, run_proxy, TestFilter}; | ||
|
||
#[tokio::test] | ||
async fn test_filter() { | ||
let base_logger = logger(); | ||
|
||
// create two echo servers as endpoints | ||
let echo = echo_server().await; | ||
|
||
// create server configuration | ||
let server_port = 12346; | ||
let server_config = Config { | ||
local: Local { port: server_port }, | ||
filters: vec![Filter { | ||
name: "TestFilter".to_string(), | ||
config: serde_yaml::Value::Null, | ||
}], | ||
connections: ConnectionConfig::Server { | ||
endpoints: vec![EndPoint { | ||
name: "server".to_string(), | ||
address: echo, | ||
connection_ids: vec![], | ||
}], | ||
}, | ||
}; | ||
|
||
let mut registry = default_filters(&base_logger); | ||
registry.insert("TestFilter".to_string(), TestFilter {}); | ||
let close_server = run_proxy(&base_logger, registry, server_config); | ||
|
||
// create a local client | ||
let client_port = 12347; | ||
let client_config = Config { | ||
local: Local { port: client_port }, | ||
filters: vec![Filter { | ||
name: "TestFilter".to_string(), | ||
config: serde_yaml::Value::Null, | ||
}], | ||
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 mut registry = default_filters(&base_logger); | ||
registry.insert("TestFilter".to_string(), TestFilter {}); | ||
let close_client = run_proxy(&base_logger, registry, 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(); | ||
|
||
let result = recv_chan.recv().await.unwrap(); | ||
// since we don't know the ephemeral ip addresses in use, we'll search for | ||
// substrings for the results we expect that the TestFilter will inject in | ||
// the round-tripped packets. | ||
assert_eq!( | ||
2, | ||
result.matches("lrf").count(), | ||
"Should be 2 local_receive_filter calls in {}", | ||
result | ||
); | ||
assert_eq!( | ||
2, | ||
result.matches("lsf").count(), | ||
"Should be 2 local_send_filter calls in {}", | ||
result | ||
); | ||
assert_eq!( | ||
2, | ||
result.matches("esf").count(), | ||
"Should be 2 endpoint_send_filter calls in {}", | ||
result | ||
); | ||
assert_eq!( | ||
2, | ||
result.matches("erf").count(), | ||
"Should be 2 endpoint_receive_filter calls in {}", | ||
result | ||
); | ||
|
||
close_server(); | ||
close_client(); | ||
} | ||
} |