|
9 | 9 | use std::process::Command; |
10 | 10 |
|
11 | 11 | use crate::{get_bck_command, get_test_image, run_bcvk}; |
| 12 | +use regex::Regex; |
12 | 13 |
|
13 | 14 | /// Test that base disk is created and reused for multiple VMs |
14 | 15 | pub fn test_base_disk_creation_and_reuse() { |
@@ -131,6 +132,75 @@ pub fn test_base_disks_list_command() { |
131 | 132 | } |
132 | 133 | } |
133 | 134 |
|
| 135 | +/// Test base-disks list shows creation timestamp |
| 136 | +pub fn test_base_disks_list_shows_timestamp() { |
| 137 | + let test_image = get_test_image(); |
| 138 | + let bck = get_bck_command().unwrap(); |
| 139 | + |
| 140 | + println!("Testing base-disks list shows creation timestamp"); |
| 141 | + |
| 142 | + let timestamp = std::time::SystemTime::now() |
| 143 | + .duration_since(std::time::UNIX_EPOCH) |
| 144 | + .unwrap() |
| 145 | + .as_secs(); |
| 146 | + let vm_name = format!("test-base-timestamp-{}", timestamp); |
| 147 | + |
| 148 | + cleanup_domain(&vm_name); |
| 149 | + |
| 150 | + // Create a VM to ensure we have at least one base disk |
| 151 | + println!("Creating VM to generate base disk..."); |
| 152 | + let vm_output = run_bcvk(&[ |
| 153 | + "libvirt", |
| 154 | + "run", |
| 155 | + "--name", |
| 156 | + &vm_name, |
| 157 | + "--filesystem", |
| 158 | + "ext4", |
| 159 | + &test_image, |
| 160 | + ]) |
| 161 | + .expect("Failed to create VM"); |
| 162 | + |
| 163 | + if !vm_output.success() { |
| 164 | + cleanup_domain(&vm_name); |
| 165 | + panic!("Failed to create VM: {}", vm_output.stderr); |
| 166 | + } |
| 167 | + |
| 168 | + // Run base-disks list |
| 169 | + let output = Command::new(&bck) |
| 170 | + .args(["libvirt", "base-disks", "list"]) |
| 171 | + .output() |
| 172 | + .expect("Failed to run base-disks list"); |
| 173 | + |
| 174 | + let stdout = String::from_utf8_lossy(&output.stdout); |
| 175 | + let stderr = String::from_utf8_lossy(&output.stderr); |
| 176 | + |
| 177 | + cleanup_domain(&vm_name); |
| 178 | + |
| 179 | + if output.status.success() { |
| 180 | + println!("base-disks list output:\n{}", stdout); |
| 181 | + |
| 182 | + // Should have CREATED column in header |
| 183 | + assert!( |
| 184 | + stdout.contains("CREATED"), |
| 185 | + "Should show CREATED column in header" |
| 186 | + ); |
| 187 | + |
| 188 | + // Should show timestamp values (either a date or "unknown") |
| 189 | + // Timestamp format is YYYY-MM-DD HH:MM |
| 190 | + let re = Regex::new(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}|unknown").unwrap(); |
| 191 | + let has_timestamp = re.is_match(&stdout); |
| 192 | + assert!( |
| 193 | + has_timestamp, |
| 194 | + "Should show timestamp values in CREATED column" |
| 195 | + ); |
| 196 | + |
| 197 | + println!("✓ base-disks list shows creation timestamp"); |
| 198 | + } else { |
| 199 | + println!("base-disks list failed: {}", stderr); |
| 200 | + panic!("Failed to run base-disks list: {}", stderr); |
| 201 | + } |
| 202 | +} |
| 203 | + |
134 | 204 | /// Test base-disks prune command with dry-run |
135 | 205 | pub fn test_base_disks_prune_dry_run() { |
136 | 206 | let bck = get_bck_command().unwrap(); |
|
0 commit comments