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()
type TaskGenerator interface {

View File

@ -6,9 +6,17 @@ import (
"time"
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) {
t.Parallel()
@ -38,9 +46,7 @@ func TestGlobalOptions(t *testing.T) {
"--no-lock",
}
if diff := deep.Equal(args, expected); diff != nil {
t.Errorf("args didn't match %v", diff)
}
AssertEqual(t, "args didn't match", expected, args)
}
func TestBackupOpts(t *testing.T) {
@ -61,9 +67,7 @@ func TestBackupOpts(t *testing.T) {
"--host", "steve",
}
if diff := deep.Equal(args, expected); diff != nil {
t.Errorf("args didn't match %v", diff)
}
AssertEqual(t, "args didn't match", expected, args)
}
func TestRestoreOpts(t *testing.T) {
@ -90,9 +94,7 @@ func TestRestoreOpts(t *testing.T) {
"--verify",
}
if diff := deep.Equal(args, expected); diff != nil {
t.Errorf("args didn't match %v", diff)
}
AssertEqual(t, "args didn't match", expected, args)
}
func TestForgetOpts(t *testing.T) {
@ -138,9 +140,7 @@ func TestForgetOpts(t *testing.T) {
"--prune",
}
if diff := deep.Equal(args, expected); diff != nil {
t.Errorf("args didn't match %v", diff)
}
AssertEqual(t, "args didn't match", expected, args)
}
func TestBuildEnv(t *testing.T) {
@ -178,9 +178,7 @@ func TestBuildEnv(t *testing.T) {
t.Run(c.name, func(t *testing.T) {
t.Parallel()
if diff := deep.Equal(c.expected, c.cmd.BuildEnv()); diff != nil {
t.Error(diff)
}
AssertEqual(t, "args didn't match", c.expected, c.cmd.BuildEnv())
})
}
}

View File

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