use std::sync::Once;
static INIT: Once = Once::new();
async fn set_up() -> openstack::Cloud {
INIT.call_once(|| {
env_logger::init();
});
openstack::Cloud::from_env()
.await
.expect("Failed to create an identity provider from the environment")
}
#[tokio::test]
async fn test_volume_create_get_delete_simple() {
let os = set_up().await;
let volume = os
.new_volume(1 as u64)
.create()
.await
.expect("Could not create volume");
let id = volume.id().clone();
assert!(volume.name().is_empty());
assert!(volume.description().is_none());
assert_eq!(volume.size(), 1 as u64);
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
let volume2 = os.get_volume(&id).await.expect("Could not get volume");
assert_eq!(volume2.id(), volume.id());
volume.delete().await.expect("Could not delete volume");
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
let volume3 = os.get_volume(id).await;
assert!(volume3.is_err());
}
#[tokio::test]
async fn test_volume_create_with_fields() {
let os = set_up().await;
let volume = os
.new_volume(1 as u64)
.with_name("test_volume".to_string())
.with_description("test_description")
.create()
.await
.expect("Could not create volume");
assert_eq!(volume.name(), "test_volume");
assert_eq!(*volume.description(), Some("test_description".to_string()));
assert_eq!(volume.size(), 1 as u64);
volume.delete().await.expect("Could not delete volume");
}