#[tokio::test]
pub async fn test_list_devices() {
use crate::all_devices;
use log::LevelFilter;
use simple_logger::SimpleLogger;
SimpleLogger::new()
.with_level(LevelFilter::Info)
.init()
.unwrap();
let devices = all_devices().await.unwrap();
log::info!("{devices:?}")
}
#[tokio::test]
pub async fn test_wireless_devices() {
use crate::wireless_devices;
use log::LevelFilter;
use simple_logger::SimpleLogger;
SimpleLogger::new()
.with_level(LevelFilter::Info)
.init()
.unwrap();
let devices = wireless_devices().await.unwrap();
log::info!("{devices:?}")
}
#[tokio::test]
pub async fn test_scan_all_ssids() {
use crate::scan_all_ssids;
use crate::wireless_devices;
use log::LevelFilter;
use simple_logger::SimpleLogger;
SimpleLogger::new()
.with_level(LevelFilter::Info)
.init()
.unwrap();
let devices = wireless_devices().await.unwrap();
match devices.into_iter().find(|_d| true) {
None => {
log::info!("No wireless devices found");
}
Some(device) => {
let access_points = scan_all_ssids(device).await.unwrap();
log::info!("{access_points:#?}")
}
}
}
#[tokio::test]
pub async fn test_connect_to_ssid() {
use crate::connect_to_access_point;
use crate::wireless_devices;
use log::LevelFilter;
use simple_logger::SimpleLogger;
use std::env;
SimpleLogger::new()
.with_level(LevelFilter::Info)
.init()
.unwrap();
let devices = wireless_devices().await.unwrap();
match devices.into_iter().find(|_d| true) {
None => {
log::info!("No wireless devices found");
}
Some(device) => {
let ssid = env::var("SSID_NAME").unwrap();
log::info!("Connecting to {ssid:?}");
connect_to_access_point(device, ssid, env::var("SSID_PASS").ok(), None)
.await
.unwrap();
log::info!("Connected");
}
}
}
#[tokio::test]
pub async fn test_bad_connect_to_ssid() {
use crate::connect_to_access_point;
use crate::wireless_devices;
use log::LevelFilter;
use simple_logger::SimpleLogger;
use std::env;
SimpleLogger::new()
.with_level(LevelFilter::Info)
.init()
.unwrap();
let devices = wireless_devices().await.unwrap();
match devices.into_iter().find(|_d| true) {
None => {
log::info!("No wireless devices found");
}
Some(device) => {
let ssid = env::var("SSID_NAME").unwrap();
log::info!("Connecting to {ssid:?}");
if let Err(e) =
connect_to_access_point(device, ssid, Some("some_bad_value123!".to_string()), None)
.await
{
log::info!("Failed to Connect: {e}");
} else {
log::info!("Expected to Fail to Connect");
}
}
}
}
#[tokio::test]
pub async fn test_disconnect_device() {
use crate::disconnect;
use crate::wireless_devices;
use log::LevelFilter;
use simple_logger::SimpleLogger;
SimpleLogger::new()
.with_level(LevelFilter::Info)
.init()
.unwrap();
let devices = wireless_devices().await.unwrap();
match devices.into_iter().find(|_d| true) {
None => {
log::info!("No wireless devices found");
}
Some(device) => {
log::info!("Disconnecting");
disconnect(device).await.unwrap();
log::info!("Disconnected");
}
}
}
#[tokio::test]
pub async fn test_create_hotspot() {
use crate::create_hotspot;
use crate::wireless_devices;
use log::LevelFilter;
use simple_logger::SimpleLogger;
SimpleLogger::new()
.with_level(LevelFilter::Info)
.init()
.unwrap();
let devices = wireless_devices().await.unwrap();
match devices.into_iter().find(|_d| true) {
None => {
log::info!("No wireless devices found");
}
Some(device) => {
log::info!("Creating Hotspot");
create_hotspot(
device,
None,
"Example Hotspot".to_string(),
Some("Secure123!".to_string()),
)
.await
.unwrap();
log::info!("Hotspot Created");
}
}
}
#[tokio::test]
pub async fn test_destroy_hotspot() {
use crate::delete_connection;
use crate::find_all_hotspots;
use log::LevelFilter;
use simple_logger::SimpleLogger;
SimpleLogger::new()
.with_level(LevelFilter::Info)
.init()
.unwrap();
log::info!("Destroying Hotspot");
for con in find_all_hotspots().await.unwrap() {
delete_connection(con).await.unwrap();
}
log::info!("Hotspot Destroyed");
}
#[tokio::test]
pub async fn test_restart_hotspot() {
use crate::create_hotspot;
use crate::find_active_hotspots;
use crate::reset_active_connection;
use crate::wireless_devices;
use log::LevelFilter;
use simple_logger::SimpleLogger;
SimpleLogger::new()
.with_level(LevelFilter::Info)
.init()
.unwrap();
let devices = wireless_devices().await.unwrap();
match devices.into_iter().find(|_d| true) {
None => {
log::info!("No wireless devices found");
}
Some(device) => {
log::info!("Creating Hotspot");
create_hotspot(
device,
None,
"Example Hotspot".to_string(),
Some("Secure123!".to_string()),
)
.await
.unwrap();
log::info!("Hotspot Created");
log::info!("Restarting Hotspots");
let active_hotspots = find_active_hotspots().await.unwrap();
if active_hotspots.is_empty() {
panic!("No Active Hotspot Found")
} else {
for con in active_hotspots {
reset_active_connection(con).await.unwrap();
}
}
log::info!("Hotspot Restarted");
}
}
}