Deep asserts

This commit is contained in:
IamTheFij 2022-03-24 10:09:33 -07:00
parent 3024a496c1
commit 870d19fd27
3 changed files with 17 additions and 19 deletions

View File

@ -174,7 +174,7 @@ func TestJobTaskScript(t *testing.T) {
} }
} }
func TestJobTaskMySQL(t *testing.T) { func TestJobTaskSql(t *testing.T) {
t.Parallel() t.Parallel()
type TaskGenerator interface { type TaskGenerator interface {

View File

@ -6,9 +6,17 @@ import (
"time" "time"
main "git.iamthefij.com/iamthefij/restic-scheduler" main "git.iamthefij.com/iamthefij/restic-scheduler"
"github.com/go-test/deep"
) )
func TestNoOpts(t *testing.T) {
t.Parallel()
args := main.NoOpts{}.ToArgs()
expected := []string{}
AssertEqual(t, "no opts returned some opts", expected, args)
}
func TestGlobalOptions(t *testing.T) { func TestGlobalOptions(t *testing.T) {
t.Parallel() t.Parallel()
@ -38,9 +46,7 @@ func TestGlobalOptions(t *testing.T) {
"--no-lock", "--no-lock",
} }
if diff := deep.Equal(args, expected); diff != nil { AssertEqual(t, "args didn't match", expected, args)
t.Errorf("args didn't match %v", diff)
}
} }
func TestBackupOpts(t *testing.T) { func TestBackupOpts(t *testing.T) {
@ -61,9 +67,7 @@ func TestBackupOpts(t *testing.T) {
"--host", "steve", "--host", "steve",
} }
if diff := deep.Equal(args, expected); diff != nil { AssertEqual(t, "args didn't match", expected, args)
t.Errorf("args didn't match %v", diff)
}
} }
func TestRestoreOpts(t *testing.T) { func TestRestoreOpts(t *testing.T) {
@ -90,9 +94,7 @@ func TestRestoreOpts(t *testing.T) {
"--verify", "--verify",
} }
if diff := deep.Equal(args, expected); diff != nil { AssertEqual(t, "args didn't match", expected, args)
t.Errorf("args didn't match %v", diff)
}
} }
func TestForgetOpts(t *testing.T) { func TestForgetOpts(t *testing.T) {
@ -138,9 +140,7 @@ func TestForgetOpts(t *testing.T) {
"--prune", "--prune",
} }
if diff := deep.Equal(args, expected); diff != nil { AssertEqual(t, "args didn't match", expected, args)
t.Errorf("args didn't match %v", diff)
}
} }
func TestBuildEnv(t *testing.T) { func TestBuildEnv(t *testing.T) {
@ -178,9 +178,7 @@ func TestBuildEnv(t *testing.T) {
t.Run(c.name, func(t *testing.T) { t.Run(c.name, func(t *testing.T) {
t.Parallel() t.Parallel()
if diff := deep.Equal(c.expected, c.cmd.BuildEnv()); diff != nil { AssertEqual(t, "args didn't match", c.expected, c.cmd.BuildEnv())
t.Error(diff)
}
}) })
} }
} }

View File

@ -10,8 +10,8 @@ import (
func AssertEqual(t *testing.T, message string, expected, actual interface{}) bool { func AssertEqual(t *testing.T, message string, expected, actual interface{}) bool {
t.Helper() t.Helper()
if expected != actual { if diff := deep.Equal(expected, actual); diff != nil {
t.Errorf("%s. expected: %v, actual: %v", message, expected, actual) t.Errorf("%s: %v", message, diff)
} }
return true return true