Skip to content

Commit 5edd217

Browse files
committed
feat(safety): added NoFileDescriptorLeak (linux)
This is a linux-only assertion to guard against file descritor leaks. Unlike goroutine leak checks, this one does not support parallel tests. tests: skip testable examples for NoFileDescriptorLeak on windows/macos Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent 53510cd commit 5edd217

31 files changed

Lines changed: 971 additions & 21 deletions

assert/assert_assertions.go

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assert_assertions_test.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assert_examples_test.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assert_format.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assert_format_test.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assert_forward.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assert_forward_test.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codegen/internal/generator/templates/assertion_examples_test.gotmpl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"net/http"
1010
"path/filepath"
11+
"runtime"
1112
"testing"
1213
"github.com/go-openapi/testify/v2/{{ .Package }}"
1314
{{ imports .Imports }}
@@ -25,6 +26,20 @@ import (
2526

2627
func Example{{ .Name }}() {
2728
{{- $fn := . }}
29+
{{- if eq $fn.Name "NoFileDescriptorLeak" }}{{/* handle special case for platform-specific assertion: example only runs on windows */}}
30+
if runtime.GOOS != "linux" {
31+
// This example is only runnable on linux. On other platforms, the assertion skips the test.
32+
// We force the expected output below, so that tests don't fail on other platforms.
33+
{{- if eq $pkg "require" }}
34+
fmt.Println("passed")
35+
{{- else }}
36+
fmt.Println("success: true")
37+
{{- end }}
38+
39+
return
40+
}
41+
{{ cr false }}
42+
{{- end }}
2843
{{- range .Tests }}
2944
{{- if .IsSuccess }}
3045
{{- cr .IsFirst }}

docs/doc-site/api/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Each domain contains assertions regrouped by their use case (e.g. http, json, er
4343
- [Number](./number.md) - Asserting Numbers (7)
4444
- [Ordering](./ordering.md) - Asserting How Collections Are Ordered (10)
4545
- [Panic](./panic.md) - Asserting A Panic Behavior (4)
46-
- [Safety](./safety.md) - Checks Against Leaked Resources (1)
46+
- [Safety](./safety.md) - Checks Against Leaked Resources (Goroutines, File Descriptors) (2)
4747
- [String](./string.md) - Asserting Strings (4)
4848
- [Testing](./testing.md) - Mimics Methods From The Testing Standard Library (2)
4949
- [Time](./time.md) - Asserting Times And Durations (2)

0 commit comments

Comments
 (0)