Skip to content

Commit

Permalink
Add wireless migration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jcronenberg committed Jan 29, 2024
1 parent 92f7770 commit 0ec3059
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions rust/migrate-wicked/src/wireless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,112 @@ impl TryFrom<&Network> for model::ConnectionConfig {
Ok(model::ConnectionConfig::Wireless(config))
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::interface::*;
use crate::MIGRATION_SETTINGS;

#[allow(dead_code)]
fn setup_default_migration_settings() {
let _ = MIGRATION_SETTINGS.set(crate::MigrationSettings {
continue_migration: false,
dry_run: false,
activate_connections: true,
});
}

#[test]
fn test_wireless_bands() {
let mut wireless_interface = Interface {
wireless: Some(Wireless {
networks: Some(vec![Network {
channel: Some(0),
essid: "testssid".to_string(),
scan_ssid: false,
mode: WickedWirelessMode::AP,
wpa_psk: None,
key_management: vec!["wpa-psk".to_string()],
access_point: None,
wep: None,
}]),
ap_scan: 0,
}),
..Default::default()
};
let ifc = wireless_interface.to_connection();
assert!(ifc.is_ok());
let ifc = &ifc.unwrap().connections[0];
let model::ConnectionConfig::Wireless(wireless) = &ifc.config else {
panic!()
};
assert_eq!(wireless.band, Some("bg".try_into().unwrap()));

wireless_interface
.wireless
.as_mut()
.unwrap()
.networks
.as_mut()
.unwrap()[0]
.channel = Some(32);
let ifc = wireless_interface.to_connection();
assert!(ifc.is_ok());
let ifc = &ifc.unwrap().connections[0];
let model::ConnectionConfig::Wireless(wireless) = &ifc.config else {
panic!()
};
assert_eq!(wireless.band, Some("a".try_into().unwrap()));
}

#[test]
fn test_wireless_migration() {
let wireless_interface = Interface {
wireless: Some(Wireless {
networks: Some(vec![Network {
essid: "testssid".to_string(),
scan_ssid: true,
mode: WickedWirelessMode::Infrastructure,
wpa_psk: Some(WpaPsk {
passphrase: "testpassword".to_string(),
}),
key_management: vec!["wpa-psk".to_string()],
channel: Some(14),
access_point: Some("12:34:56:78:9A:BC".to_string()),
wep: Some(Wep {
auth_algo: "open".to_string(),
default_key: 1,
key: vec!["01020304ff".to_string(), "s:hello".to_string()],
}),
}]),
ap_scan: 0,
}),
..Default::default()
};
let ifc = wireless_interface.to_connection();
assert!(ifc.is_ok());
let ifc = &ifc.unwrap().connections[0];
let model::ConnectionConfig::Wireless(wireless) = &ifc.config else {
panic!()
};
assert_eq!(wireless.ssid, SSID("testssid".as_bytes().to_vec()));
assert_eq!(wireless.mode, model::WirelessMode::Infra);
assert_eq!(wireless.password, Some("testpassword".to_string()));
assert_eq!(wireless.security, model::SecurityProtocol::WPA2);
assert_eq!(
wireless.bssid,
Some(MacAddr6::from_str("12:34:56:78:9A:BC").unwrap())
);
assert_eq!(
wireless.wep_security,
Some(WEPSecurity {
auth_alg: WEPAuthAlg::Open,
wep_key_type: WEPKeyType::Key,
keys: vec!["01020304ff".to_string(), "hello".to_string()],
wep_key_index: 1,
})
);
assert_eq!(wireless.band, Some("bg".try_into().unwrap()));
}
}

0 comments on commit 0ec3059

Please sign in to comment.