Skip to content

Commit

Permalink
test: eliminate helper func
Browse files Browse the repository at this point in the history
super minor, but it annoys me when errors are far away from callers.
  • Loading branch information
thockin committed Sep 4, 2023
1 parent d0d35d7 commit 5f243cf
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions logr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,36 @@ func TestV(t *testing.T) {
}
return level
}
expectEqual(t, "V(0)", 0, logger.V(0).GetV())
expectEqual(t, "V(93)", adjust(93), logger.V(93).GetV())
expectEqual(t, "V(70).V(6)", adjust(76), logger.V(70).V(6).GetV())
expectEqual(t, "V(-1)", 0, logger.V(-1).GetV())
expectEqual(t, "V(1).V(-1)", adjust(1), logger.V(1).V(-1).GetV())
inputs := []struct {
name string
fn func() Logger
exp int
}{{
name: "V(0)",
fn: func() Logger { return logger.V(0) },
exp: 0,
}, {
name: "V(93)",
fn: func() Logger { return logger.V(93) },
exp: adjust(93),
}, {
name: "V(70).V(6)",
fn: func() Logger { return logger.V(70).V(6) },
exp: adjust(76),
}, {
name: "V(-1)",
fn: func() Logger { return logger.V(-1) },
exp: 0,
}, {
name: "V(1).V(-1)",
fn: func() Logger { return logger.V(1).V(-1) },
exp: adjust(1),
}}
for _, in := range inputs {
if want, got := in.exp, in.fn().GetV(); got != want {
t.Errorf("%q: expected %d, got %d", in.name, want, got)
}
}
})
}
}
Expand Down Expand Up @@ -442,12 +467,3 @@ func TestZeroValue(t *testing.T) {
l2.Error(errors.New("bar"), "some error")
_, _ = l.WithCallStackHelper()
}

func expectEqual[T comparable](tb testing.TB, msg string, expected, actual T) bool {
if expected == actual {
return true
}
tb.Helper()
tb.Errorf("Failure: %s: expected to get %v, got %v instead", msg, expected, actual)
return false
}

0 comments on commit 5f243cf

Please sign in to comment.