test: add regression test for native-tls crate

This commit is contained in:
Paul Campbell 2025-01-14 20:59:32 +00:00
parent 4bd50bdadf
commit e2f2015e06
3 changed files with 12 additions and 2 deletions

View file

@ -1,3 +1,13 @@
mod tls;
fn main() {
println!("Hello, world!");
tls::main();
}
#[cfg(test)]
mod tests {
#[test]
fn passes() {
println!("passes okay");
}
}

15
src/tls.rs Normal file
View file

@ -0,0 +1,15 @@
use native_tls::TlsConnector;
use std::io::{Read, Write};
use std::net::TcpStream;
pub fn main() {
let connector = TlsConnector::new().unwrap();
let stream = TcpStream::connect("google.com:443").unwrap();
let mut stream = connector.connect("google.com", stream).unwrap();
stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap();
let mut res = vec![];
stream.read_to_end(&mut res).unwrap();
println!("{}", String::from_utf8_lossy(&res));
}