github.com/moontrade/mdbx-go@v0.4.0/internal/capture/capture_test.go (about)

     1  package capture
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestCapture(t *testing.T) {
    11  	assert.NoError(t, SetRLimitFiles(10, func(limit uint64) {
    12  		// Use at least one more file descriptor than our current limit, so we make sure that there are no file descriptor leaks.
    13  		for i := 0; i <= int(limit); i++ {
    14  			testCapture(t)
    15  		}
    16  	}))
    17  }
    18  
    19  func TestCaptureWithPanic(t *testing.T) {
    20  	assert.Panics(t, func() {
    21  		_, _ = Capture(func() {
    22  			fmt.Println("abc")
    23  
    24  			panic("stop")
    25  		})
    26  	})
    27  }
    28  
    29  func TestCaptureWithCGo(t *testing.T) {
    30  	assert.NoError(t, SetRLimitFiles(10, func(limit uint64) {
    31  		// Use at least one more file descriptor than our current limit, so we make sure that there are no file descriptor leaks.
    32  		for i := 0; i <= int(limit); i++ {
    33  			testCaptureWithCGo(t)
    34  		}
    35  	}))
    36  }
    37  
    38  func TestCaptureWithCGoWithPanic(t *testing.T) {
    39  	assert.Panics(t, func() {
    40  		_, _ = CaptureWithCGo(func() {
    41  			fmt.Println("abc")
    42  
    43  			panic("stop")
    44  		})
    45  	})
    46  }