Skip to content

Commit

Permalink
[mdatagen] bugfix: fix generated package test when skipping goleak, b…
Browse files Browse the repository at this point in the history
…ecause os package import is forgotten (#10486)

#### Description

When `tests.goleak.skip` flag is set to true, the
generated_package_test.go is missing the `import os` statement. I
added the missing import in this PR.

#### Testing

Compare the generated generated_package_test.go when tests.goleak.skip
flag is toggle from false to true.

**before**

```diff
--- a/receiver/runnreceiver/generated_package_test.go
+++ b/receiver/runnreceiver/generated_package_test.go
@@ -3,10 +3,10 @@
 package runnreceiver

 import (
-       "go.uber.org/goleak"
        "testing"
 )

 func TestMain(m *testing.M) {
-       goleak.VerifyTestMain(m)
+       // skipping goleak test as per metadata.yml configuration
+       os.Exit(m.Run())
 }
```

**after**

```diff
--- a/receiver/runnreceiver/generated_package_test.go
+++ b/receiver/runnreceiver/generated_package_test.go
@@ -3,10 +3,11 @@
 package runnreceiver

 import (
-       "go.uber.org/goleak"
+       "os"
        "testing"
 )

 func TestMain(m *testing.M) {
-       goleak.VerifyTestMain(m)
+       // skipping goleak test as per metadata.yml configuration
+       os.Exit(m.Run())
 }
```
  • Loading branch information
Arthur1 committed Jul 5, 2024
1 parent 6fca9ee commit 5a8d039
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/mdatagen/templates/package_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
package {{ if isCommand -}}main{{ else }}{{ .Package }}{{- end }}

import (
{{- if .Tests.GoLeak.Skip }}
"os"
{{- end }}
"testing"

{{- if not .Tests.GoLeak.Skip }}
Expand Down

0 comments on commit 5a8d039

Please sign in to comment.