Skip to content

Commit 7d51e97

Browse files
committed
refactor: improve error messages in e2e_tests get_instance_ip function
Separate error handling for instance existence vs IP assignment. Now provides explicit error messages distinguishing between: - Instance not found in LXD - Instance exists but has no IPv4 address assigned - LXD query failures This improves debugging experience during E2E test failures.
1 parent 30b33e8 commit 7d51e97

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/bin/e2e_tests.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,19 @@ impl TestEnvironment {
315315
fn get_instance_ip(&self) -> Result<String> {
316316
// For E2E tests, we should rely on OpenTofu outputs since they already wait for network
317317
// This is a secondary validation that the instance is accessible via LXD
318-
let ip = self
318+
319+
// First, check if the instance exists
320+
let instance = self
319321
.lxd_client
320-
.get_instance_ip("torrust-vm")
321-
.context("Failed to get instance IP")?
322-
.ok_or_else(|| {
323-
anyhow::anyhow!("Instance 'torrust-vm' not found or has no IP address")
324-
})?;
322+
.get_instance_by_name("torrust-vm")
323+
.context("Failed to query LXD for instance information")?
324+
.ok_or_else(|| anyhow::anyhow!("Instance 'torrust-vm' was not found in LXD"))?;
325+
326+
// Then, check if the instance has an IP address
327+
let ip = instance.ip_address.ok_or_else(|| {
328+
anyhow::anyhow!("Instance 'torrust-vm' exists but has no IPv4 address assigned")
329+
})?;
330+
325331
Ok(ip.to_string())
326332
}
327333

0 commit comments

Comments
 (0)