Skip to content

Commit

Permalink
genereate missing test code
Browse files Browse the repository at this point in the history
  • Loading branch information
kevindiu authored and actions-user committed Jun 11, 2020
1 parent 53c863a commit 99895a7
Showing 1 changed file with 146 additions and 0 deletions.
146 changes: 146 additions & 0 deletions internal/safety/safety_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package safety

import (
"reflect"
"testing"

"github.com/vdaas/vald/internal/errors"
Expand Down Expand Up @@ -159,3 +160,148 @@ func TestRecoverFunc(t *testing.T) {
})
}
}

func TestRecoverWithoutPanicFunc(t *testing.T) {
type args struct {
fn func() error
}
type want struct {
want func() error
}
type test struct {
name string
args args
want want
checkFunc func(want, func() error) error
beforeFunc func(args)
afterFunc func(args)
}
defaultCheckFunc := func(w want, got func() error) error {
if !reflect.DeepEqual(got, w.want) {
return errors.Errorf("got = %v, want %v", got, w.want)
}
return nil
}
tests := []test{
// TODO test cases
/*
{
name: "test_case_1",
args: args {
fn: nil,
},
want: want{},
checkFunc: defaultCheckFunc,
},
*/

// TODO test cases
/*
func() test {
return test {
name: "test_case_2",
args: args {
fn: nil,
},
want: want{},
checkFunc: defaultCheckFunc,
}
}(),
*/
}

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(tt)
if test.beforeFunc != nil {
test.beforeFunc(test.args)
}
if test.afterFunc != nil {
defer test.afterFunc(test.args)
}
if test.checkFunc == nil {
test.checkFunc = defaultCheckFunc
}

got := RecoverWithoutPanicFunc(test.args.fn)
if err := test.checkFunc(test.want, got); err != nil {
tt.Errorf("error = %v", err)
}

})
}
}

func Test_recoverFunc(t *testing.T) {
type args struct {
fn func() error
withPanic bool
}
type want struct {
want func() error
}
type test struct {
name string
args args
want want
checkFunc func(want, func() error) error
beforeFunc func(args)
afterFunc func(args)
}
defaultCheckFunc := func(w want, got func() error) error {
if !reflect.DeepEqual(got, w.want) {
return errors.Errorf("got = %v, want %v", got, w.want)
}
return nil
}
tests := []test{
// TODO test cases
/*
{
name: "test_case_1",
args: args {
fn: nil,
withPanic: false,
},
want: want{},
checkFunc: defaultCheckFunc,
},
*/

// TODO test cases
/*
func() test {
return test {
name: "test_case_2",
args: args {
fn: nil,
withPanic: false,
},
want: want{},
checkFunc: defaultCheckFunc,
}
}(),
*/
}

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(tt)
if test.beforeFunc != nil {
test.beforeFunc(test.args)
}
if test.afterFunc != nil {
defer test.afterFunc(test.args)
}
if test.checkFunc == nil {
test.checkFunc = defaultCheckFunc
}

got := recoverFunc(test.args.fn, test.args.withPanic)
if err := test.checkFunc(test.want, got); err != nil {
tt.Errorf("error = %v", err)
}

})
}
}

0 comments on commit 99895a7

Please sign in to comment.