You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* fix: wrap error returns with setFailureResult helper function to properly set failure
* fix: add manual debugging guidance when job ID unavailable and correct undeployment terminology
* docs: add test failure handling and resource cleanup troubleshooting guide
* add DoNotDestroyOnFailure helper for test resource preservation
* refactor: centralize DO_NOT_DESTROY_ON_FAILURE check and add teardown logging
* fix: remove terraform destroy call to preserve failed test resources
When a test fails, the framework uses three different mechanisms to track and report the failure. Understanding these helps when debugging issues like resources being cleaned up when they shouldn't be.
406
+
407
+
### The Three Failure Mechanisms
408
+
409
+
| Mechanism | What it does | What it affects |
410
+
|-----------|--------------|-----------------|
411
+
|`options.Testing.Fail()`| Marks the Go test as failed | Controls `DO_NOT_DESTROY_ON_FAILURE` behavior and actual test pass/fail |
412
+
|`options.Logger.MarkFailed()`| Marks the logger as failed | Controls whether buffered logs are flushed to output |
413
+
|`setFailureResult()`| Sets internal result string | Controls the "TEST EXECUTION END: RESULT" message |
414
+
415
+
### How They Work Together
416
+
417
+
When an error occurs, the framework calls all three:
418
+
419
+
```go
420
+
options.Logger.MarkFailed() // 1. Prepare to flush buffered logs
421
+
options.Logger.FlushOnFailure() // 2. Output the buffered logs
422
+
options.Testing.Fail() // 3. Mark Go test as failed
423
+
returnsetFailureResult(err, "STAGE") // 4. Set result for logging
424
+
```
425
+
426
+
### DO_NOT_DESTROY_ON_FAILURE Behavior
427
+
428
+
The `DO_NOT_DESTROY_ON_FAILURE` environment variable prevents resource cleanup when tests fail, allowing you to debug in the IBM Cloud console.
429
+
430
+
```bash
431
+
export DO_NOT_DESTROY_ON_FAILURE=true
432
+
```
433
+
434
+
**How it works:** During teardown, the framework checks:
435
+
436
+
```go
437
+
if options.Testing.Failed() && DO_NOT_DESTROY_ON_FAILURE == "true" {
438
+
// Skip cleanup - resources are preserved for debugging
439
+
}
440
+
```
441
+
442
+
**Important:** This only works if `options.Testing.Fail()` was called before teardown runs. If you see resources being deleted despite this setting, check that the error path properly calls `Testing.Fail()`.
443
+
444
+
### Troubleshooting Resource Cleanup Issues
445
+
446
+
If resources are deleted when `DO_NOT_DESTROY_ON_FAILURE=true`:
447
+
448
+
1.**Verify the environment variable is set:**
449
+
```bash
450
+
echo$DO_NOT_DESTROY_ON_FAILURE# Should print: true
451
+
```
452
+
453
+
2.**Check the test result log:** Look for `TEST EXECUTION END`:
454
+
-`RESULT: PASSED` - The test didn't register as failed (missing `Testing.Fail()` call)
455
+
-`RESULT: FAILED_AT_<STAGE>` - Test failed correctly at that stage
456
+
457
+
3.**Check for the skip message:** When working correctly, you should see:
458
+
```
459
+
Terratest failed. Debug the Test and delete resources manually.
0 commit comments