Skip to content

Commit

Permalink
fix: make gotests/gen
Browse files Browse the repository at this point in the history
Signed-off-by: hlts2 <hiroto.funakoshi.hiroto@gmail.com>
  • Loading branch information
hlts2 committed Jun 5, 2020
1 parent 41385b5 commit 2806dbc
Show file tree
Hide file tree
Showing 10 changed files with 2,081 additions and 174 deletions.
148 changes: 148 additions & 0 deletions internal/net/grpc/interceptor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
//
// Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt )
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Package grpc provides generic functionality for grpc
package grpc

import (
"reflect"
"testing"

"github.com/vdaas/vald/internal/errors"
"go.uber.org/goleak"
)

func TestRecoverInterceptor(t *testing.T) {
type want struct {
want UnaryServerInterceptor
}
type test struct {
name string
want want
checkFunc func(want, UnaryServerInterceptor) error
beforeFunc func()
afterFunc func()
}
defaultCheckFunc := func(w want, got UnaryServerInterceptor) 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",
want: want{},
checkFunc: defaultCheckFunc,
},
*/

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

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

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

})
}
}

func TestRecoverStreamInterceptor(t *testing.T) {
type want struct {
want StreamServerInterceptor
}
type test struct {
name string
want want
checkFunc func(want, StreamServerInterceptor) error
beforeFunc func()
afterFunc func()
}
defaultCheckFunc := func(w want, got StreamServerInterceptor) 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",
want: want{},
checkFunc: defaultCheckFunc,
},
*/

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

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

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

})
}
}
147 changes: 147 additions & 0 deletions internal/safety/safety_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
package safety

import (
"reflect"
"testing"

"github.com/vdaas/vald/internal/errors"
"github.com/vdaas/vald/internal/log"
"go.uber.org/goleak"
)

func TestRecoverFunc(t *testing.T) {
Expand Down Expand Up @@ -85,3 +87,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(t)
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(t)
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)
}

})
}
}
Loading

0 comments on commit 2806dbc

Please sign in to comment.