Skip to content

Commit 0c99b62

Browse files
committed
use defer to always run cleanup
Signed-off-by: chengweiguo <[email protected]>
1 parent bcaa1e3 commit 0c99b62

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tests/e2e/fluentd/label_selector_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package fluentd
33
import (
44
"context"
55
"fmt"
6+
"strings"
67
"sync"
78
"time"
89

@@ -175,6 +176,16 @@ func testFluentdLabelSelector(
175176
err := CreateObjs(ctx, objects)
176177
Expect(err).NotTo(HaveOccurred())
177178

179+
// Ensure cleanup runs even if the test fails
180+
DeferCleanup(func() {
181+
// Clean up all objects
182+
err := DeleteObjs(ctx, objects)
183+
if err != nil {
184+
// Log the error but don't fail the cleanup
185+
fmt.Printf("Warning: failed to cleanup objects: %v\n", err)
186+
}
187+
})
188+
178189
// Wait for reconciliation
179190
time.Sleep(time.Second * 3)
180191

@@ -187,11 +198,7 @@ func testFluentdLabelSelector(
187198
Expect(err).NotTo(HaveOccurred())
188199

189200
// Verify that the configuration matches expected
190-
Expect(string(expectedConfig)).To(Equal(config))
191-
192-
// Clean up
193-
err = DeleteObjs(ctx, objects)
194-
Expect(err).NotTo(HaveOccurred())
201+
Expect(strings.TrimRight(string(expectedConfig), "\r\n")).To(Equal(config))
195202
}
196203

197204
// This test verifies the fix for the bug where filterSelector and outputSelector

0 commit comments

Comments
 (0)