helper

package
v1.12.3-rc.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckedClose

func CheckedClose(t require.TestingT, c io.Closer) func()

CheckedClose returns a function that can be used with a defer to check that a Closer's Close method does not return an error.

By using CheckedClose, the following code: defer func() { require.NoError(t, c.Close()) }() can be replaced by: defer CheckedClose(t, c)()

func CheckedCloseOnce

func CheckedCloseOnce(t require.TestingT, c io.Closer) func()

CheckedCloseOnce returns a function that will call Close on c and check for errors. The returned function has no effect after being called the first time. It can be used to replace code like the following:

c := NewSomeCloser()
defer func() {
	if c != nil {
		require.NoError(c.Close())
		c = nil
	}
}()
...
require.NoError(t, c.Close())
c = nil

Example:

closer := CheckedCloseOnce(t, c)
defer closer()
...
closer()

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL