mirror of
https://github.com/restic/restic.git
synced 2026-02-17 06:23:56 +00:00
test: use generics in Equal function signature
This simplifies comparing a typed value against nil. Previously it was necessary to case nil into the proper type.
This commit is contained in:
@@ -29,7 +29,7 @@ func TestParse(t *testing.T) {
|
|||||||
u, err := location.Parse(registry, path)
|
u, err := location.Parse(registry, path)
|
||||||
test.OK(t, err)
|
test.OK(t, err)
|
||||||
test.Equals(t, "local", u.Scheme)
|
test.Equals(t, "local", u.Scheme)
|
||||||
test.Equals(t, &testConfig{loc: path}, u.Config)
|
test.Equals(t, any(&testConfig{loc: path}), u.Config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseFallback(t *testing.T) {
|
func TestParseFallback(t *testing.T) {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func TestDefaultLoad(t *testing.T) {
|
|||||||
|
|
||||||
return rd, nil
|
return rd, nil
|
||||||
}, func(ird io.Reader) error {
|
}, func(ird io.Reader) error {
|
||||||
rtest.Equals(t, rd, ird)
|
rtest.Equals(t, io.Reader(rd), ird)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func OKs(tb testing.TB, errs []error) {
|
|||||||
|
|
||||||
// Equals fails the test if exp is not equal to act.
|
// Equals fails the test if exp is not equal to act.
|
||||||
// msg is optional message to be printed, first param being format string and rest being arguments.
|
// msg is optional message to be printed, first param being format string and rest being arguments.
|
||||||
func Equals(tb testing.TB, exp, act interface{}, msgs ...string) {
|
func Equals[T any](tb testing.TB, exp, act T, msgs ...string) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
if !reflect.DeepEqual(exp, act) {
|
if !reflect.DeepEqual(exp, act) {
|
||||||
var msgString string
|
var msgString string
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ func TestRawInputOutput(t *testing.T) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
rtest.Equals(t, input, term.InputRaw())
|
rtest.Equals(t, input, term.InputRaw())
|
||||||
rtest.Equals(t, false, term.InputIsTerminal())
|
rtest.Equals(t, false, term.InputIsTerminal())
|
||||||
rtest.Equals(t, &output, term.OutputRaw())
|
rtest.Equals(t, io.Writer(&output), term.OutputRaw())
|
||||||
rtest.Equals(t, false, term.OutputIsTerminal())
|
rtest.Equals(t, false, term.OutputIsTerminal())
|
||||||
rtest.Equals(t, false, term.CanUpdateStatus())
|
rtest.Equals(t, false, term.CanUpdateStatus())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user