diff --git a/go.mod b/go.mod index cd90ce285b4..fce36bdcdeb 100644 --- a/go.mod +++ b/go.mod @@ -23,6 +23,7 @@ require ( github.com/spf13/cobra v1.10.2 github.com/spf13/pflag v1.0.10 github.com/stretchr/testify v1.11.1 + go.uber.org/goleak v1.3.0 golang.org/x/crypto v0.54.0 golang.org/x/mod v0.38.0 golang.org/x/sync v0.22.0 diff --git a/go.sum b/go.sum index d8e098534f4..a923f20638f 100644 --- a/go.sum +++ b/go.sum @@ -227,6 +227,8 @@ go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRk go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA= go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk= go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= diff --git a/pkg/cli/test_main_test.go b/pkg/cli/test_main_test.go index c93b0fbb85c..2ce3c652e0a 100644 --- a/pkg/cli/test_main_test.go +++ b/pkg/cli/test_main_test.go @@ -6,6 +6,8 @@ import ( "os" "path/filepath" "testing" + + "go.uber.org/goleak" ) // TestMain provides setup and teardown for unit tests in the cli package @@ -17,15 +19,12 @@ func TestMain(m *testing.M) { panic("Failed to get current working directory: " + err.Error()) } - // Run all tests - code := m.Run() - - // Clean up any action cache files created during tests - // Tests may create .github/aw/actions-lock.json in the pkg/cli directory - actionCacheDir := filepath.Join(wd, ".github") - if _, err := os.Stat(actionCacheDir); err == nil { - _ = os.RemoveAll(actionCacheDir) - } - - os.Exit(code) + goleak.VerifyTestMain(m, goleak.Cleanup(func(_ int) { + // Clean up any action cache files created during tests + // Tests may create .github/aw/actions-lock.json in the pkg/cli directory + actionCacheDir := filepath.Join(wd, ".github") + if _, err := os.Stat(actionCacheDir); err == nil { + _ = os.RemoveAll(actionCacheDir) + } + })) } diff --git a/pkg/console/test_main_test.go b/pkg/console/test_main_test.go new file mode 100644 index 00000000000..c9ec8280a9f --- /dev/null +++ b/pkg/console/test_main_test.go @@ -0,0 +1,13 @@ +//go:build !integration + +package console + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +}