Enable using TLS on dbtest tests

next
Sayan Nandan 3 years ago
parent 2cd87fbc35
commit 4a075422de
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

@ -0,0 +1,2 @@
[env]
ROOT_DIR = { value = "", relative = true }

@ -1,5 +1,3 @@
# set ROOT_DIR as our test suite uses it
export ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# no additional software note
NO_ADDITIONAL_SOFTWARE := echo "No additional software required for this target"
# target argument

@ -64,6 +64,9 @@ mod tests;
const PATH: &str = ".sky_pid";
#[cfg(test)]
const ROOT_DIR: &str = env!("ROOT_DIR");
#[cfg(all(not(target_env = "msvc"), not(miri)))]
use jemallocator::Jemalloc;

@ -35,19 +35,14 @@ mod kvengine_encoding;
mod kvengine_list;
mod pipeline;
mod ssl {
use skytable::aio::TlsConnection;
use skytable::{Element, Query};
use std::env;
#[tokio::test]
async fn test_ssl() {
let mut path = env::var("ROOT_DIR").expect("ROOT_DIR unset");
path.push_str("/cert.pem");
let mut con = TlsConnection::new("127.0.0.1", 2004, &path).await.unwrap();
let q = Query::from("heya");
assert_eq!(
con.run_simple_query(&q).await.unwrap(),
Element::String("HEY!".to_owned())
mod tls {
use skytable::{query, Element};
#[sky_macros::dbtest_func(tls_cert = "cert.pem", port = 2004)]
async fn test_tls() {
runeq!(
con,
query!("heya", "abcd"),
Element::String("abcd".to_owned())
);
}
}

@ -33,6 +33,7 @@ pub struct DBTestFunctionConfig {
table_decl: String,
port: u16,
host: String,
tls_cert: Option<String>,
}
impl DBTestFunctionConfig {
@ -41,12 +42,28 @@ impl DBTestFunctionConfig {
table_decl: "keymap(str,str)".to_owned(),
port: 2003,
host: "127.0.0.1".to_owned(),
tls_cert: None,
}
}
pub fn get_connection_tokens(&self) -> impl quote::ToTokens {
let DBTestFunctionConfig { port, host, .. } = &self;
quote! {
let mut con = skytable::AsyncConnection::new(#host, #port).await.unwrap();
let DBTestFunctionConfig {
port,
host,
tls_cert,
..
} = &self;
match tls_cert {
Some(cert) => {
quote! {
let certpath = ::std::format!("{}/{}", crate::ROOT_DIR, #cert);
let mut con = skytable::aio::TlsConnection::new(
#host, #port, &certpath
).await.unwrap();
}
}
None => quote! {
let mut con = skytable::AsyncConnection::new(#host, #port).await.unwrap();
},
}
}
pub fn get_create_table_tokens(&self, table_name: &str) -> impl quote::ToTokens {
@ -84,6 +101,9 @@ pub fn parse_dbtest_func_args(
"host" => {
fcfg.host = util::parse_string(lit, span, "host").expect("Expected a string");
}
"tls_cert" => {
fcfg.tls_cert = Some(util::parse_string(lit, span, "host").expect("Expected a string"));
}
x => panic!("unknown attribute {x} specified"),
}
}

Loading…
Cancel
Save