Skip to content

Commit 23b8420

Browse files
committed
Mark t.Helper() to avoid reporting wrong source info on failure
Signed-off-by: apostasie <[email protected]>
1 parent 3a35911 commit 23b8420

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

mod/tigron/test/helpers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,23 @@ type helpersInternal struct {
3232

3333
// Ensure will run a command and make sure it is successful.
3434
func (help *helpersInternal) Ensure(args ...string) {
35+
help.t.Helper()
3536
help.Command(args...).Run(&Expected{
3637
ExitCode: internal.ExitCodeSuccess,
3738
})
3839
}
3940

4041
// Anyhow will run a command regardless of outcome (may or may not fail).
4142
func (help *helpersInternal) Anyhow(args ...string) {
43+
help.t.Helper()
4244
help.Command(args...).Run(&Expected{
4345
ExitCode: internal.ExitCodeNoCheck,
4446
})
4547
}
4648

4749
// Fail will run a command and make sure it does fail.
4850
func (help *helpersInternal) Fail(args ...string) {
51+
help.t.Helper()
4952
help.Command(args...).Run(&Expected{
5053
ExitCode: internal.ExitCodeGenericFail,
5154
})
@@ -55,6 +58,7 @@ func (help *helpersInternal) Fail(args ...string) {
5558
func (help *helpersInternal) Capture(args ...string) string {
5659
var ret string
5760

61+
help.t.Helper()
5862
help.Command(args...).Run(&Expected{
5963
//nolint:thelper
6064
Output: func(stdout, _ string, _ *testing.T) {
@@ -67,6 +71,7 @@ func (help *helpersInternal) Capture(args ...string) string {
6771

6872
// Err will run a command with no expectation and return Stderr.
6973
func (help *helpersInternal) Err(args ...string) string {
74+
help.t.Helper()
7075
cmd := help.Command(args...)
7176
cmd.Run(nil)
7277

pkg/testutil/nerdtest/command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ type nerdCommand struct {
105105
}
106106

107107
func (nc *nerdCommand) Run(expect *test.Expected) {
108+
nc.T().Helper()
108109
nc.prep()
109110
if getTarget() == targetDocker {
110111
// We are not in the business of testing docker *error* output, so, spay expectation here

pkg/testutil/nerdtest/utilities.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func IsDocker() bool {
4545

4646
// InspectContainer is a helper that can be used inside custom commands or Setup
4747
func InspectContainer(helpers test.Helpers, name string) dockercompat.Container {
48+
helpers.T().Helper()
4849
var dc []dockercompat.Container
4950
cmd := helpers.Command("container", "inspect", name)
5051
cmd.Run(&test.Expected{
@@ -58,6 +59,7 @@ func InspectContainer(helpers test.Helpers, name string) dockercompat.Container
5859
}
5960

6061
func InspectVolume(helpers test.Helpers, name string) native.Volume {
62+
helpers.T().Helper()
6163
var dc []native.Volume
6264
cmd := helpers.Command("volume", "inspect", name)
6365
cmd.Run(&test.Expected{
@@ -71,6 +73,7 @@ func InspectVolume(helpers test.Helpers, name string) native.Volume {
7173
}
7274

7375
func InspectNetwork(helpers test.Helpers, name string) dockercompat.Network {
76+
helpers.T().Helper()
7477
var dc []dockercompat.Network
7578
cmd := helpers.Command("network", "inspect", name)
7679
cmd.Run(&test.Expected{
@@ -84,6 +87,7 @@ func InspectNetwork(helpers test.Helpers, name string) dockercompat.Network {
8487
}
8588

8689
func InspectImage(helpers test.Helpers, name string) dockercompat.Image {
90+
helpers.T().Helper()
8791
var dc []dockercompat.Image
8892
cmd := helpers.Command("image", "inspect", name)
8993
cmd.Run(&test.Expected{
@@ -102,6 +106,7 @@ const (
102106
)
103107

104108
func EnsureContainerStarted(helpers test.Helpers, con string) {
109+
helpers.T().Helper()
105110
started := false
106111
for i := 0; i < maxRetry && !started; i++ {
107112
helpers.Command("container", "inspect", con).

0 commit comments

Comments
 (0)