Skip to content

Commit

Permalink
regenerate test file for pkg/manager
Browse files Browse the repository at this point in the history
Signed-off-by: kevindiu <kevindiujp@gmail.com>
  • Loading branch information
kevindiu committed Nov 22, 2022
1 parent b048761 commit 9e11d1f
Show file tree
Hide file tree
Showing 11 changed files with 5,187 additions and 0 deletions.
116 changes: 116 additions & 0 deletions pkg/manager/index/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//
// Copyright (C) 2019-2022 vdaas.org vald team <vald@vdaas.org>
//
// 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 setting stores all server application settings
package config

import (
"reflect"
"testing"

"github.com/vdaas/vald/internal/errors"
"github.com/vdaas/vald/internal/test/goleak"
)

func TestNewConfig(t *testing.T) {
type args struct {
path string
}
type want struct {
wantCfg *Data
err error
}
type test struct {
name string
args args
want want
checkFunc func(want, *Data, error) error
beforeFunc func(*testing.T, args)
afterFunc func(*testing.T, args)
}
defaultCheckFunc := func(w want, gotCfg *Data, err error) error {
if !errors.Is(err, w.err) {
return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err)
}
if !reflect.DeepEqual(gotCfg, w.wantCfg) {
return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotCfg, w.wantCfg)
}
return nil
}
tests := []test{
// TODO test cases
/*
{
name: "test_case_1",
args: args {
path: "",
},
want: want{},
checkFunc: defaultCheckFunc,
beforeFunc: func(t *testing.T, args args) {
t.Helper()
},
afterFunc: func(t *testing.T, args args) {
t.Helper()
},
},
*/

// TODO test cases
/*
func() test {
return test {
name: "test_case_2",
args: args {
path: "",
},
want: want{},
checkFunc: defaultCheckFunc,
beforeFunc: func(t *testing.T, args args) {
t.Helper()
},
afterFunc: func(t *testing.T, args args) {
t.Helper()
},
}
}(),
*/
}

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

gotCfg, err := NewConfig(test.args.path)
if err := checkFunc(test.want, gotCfg, err); err != nil {
tt.Errorf("error = %v", err)
}

})
}
}
226 changes: 226 additions & 0 deletions pkg/manager/index/handler/grpc/handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
//
// Copyright (C) 2019-2022 vdaas.org vald team <vald@vdaas.org>
//
// 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 grpc server logic
package grpc

import (
"context"
"reflect"
"testing"

"github.com/vdaas/vald/apis/grpc/v1/manager/index"
"github.com/vdaas/vald/apis/grpc/v1/payload"
"github.com/vdaas/vald/internal/errors"
"github.com/vdaas/vald/internal/test/goleak"
"github.com/vdaas/vald/pkg/manager/index/service"
)

func TestNew(t *testing.T) {
type args struct {
opts []Option
}
type want struct {
want index.IndexServer
}
type test struct {
name string
args args
want want
checkFunc func(want, index.IndexServer) error
beforeFunc func(*testing.T, args)
afterFunc func(*testing.T, args)
}
defaultCheckFunc := func(w want, got index.IndexServer) error {
if !reflect.DeepEqual(got, w.want) {
return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want)
}
return nil
}
tests := []test{
// TODO test cases
/*
{
name: "test_case_1",
args: args {
opts: nil,
},
want: want{},
checkFunc: defaultCheckFunc,
beforeFunc: func(t *testing.T, args args) {
t.Helper()
},
afterFunc: func(t *testing.T, args args) {
t.Helper()
},
},
*/

// TODO test cases
/*
func() test {
return test {
name: "test_case_2",
args: args {
opts: nil,
},
want: want{},
checkFunc: defaultCheckFunc,
beforeFunc: func(t *testing.T, args args) {
t.Helper()
},
afterFunc: func(t *testing.T, args args) {
t.Helper()
},
}
}(),
*/
}

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

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

})
}
}

func Test_server_IndexInfo(t *testing.T) {
type args struct {
ctx context.Context
in1 *payload.Empty
}
type fields struct {
indexer service.Indexer
UnimplementedIndexServer index.UnimplementedIndexServer
}
type want struct {
wantRes *payload.Info_Index_Count
err error
}
type test struct {
name string
args args
fields fields
want want
checkFunc func(want, *payload.Info_Index_Count, error) error
beforeFunc func(*testing.T, args)
afterFunc func(*testing.T, args)
}
defaultCheckFunc := func(w want, gotRes *payload.Info_Index_Count, err error) error {
if !errors.Is(err, w.err) {
return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err)
}
if !reflect.DeepEqual(gotRes, w.wantRes) {
return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotRes, w.wantRes)
}
return nil
}
tests := []test{
// TODO test cases
/*
{
name: "test_case_1",
args: args {
ctx: nil,
in1: nil,
},
fields: fields {
indexer: nil,
UnimplementedIndexServer: nil,
},
want: want{},
checkFunc: defaultCheckFunc,
beforeFunc: func(t *testing.T, args args) {
t.Helper()
},
afterFunc: func(t *testing.T, args args) {
t.Helper()
},
},
*/

// TODO test cases
/*
func() test {
return test {
name: "test_case_2",
args: args {
ctx: nil,
in1: nil,
},
fields: fields {
indexer: nil,
UnimplementedIndexServer: nil,
},
want: want{},
checkFunc: defaultCheckFunc,
beforeFunc: func(t *testing.T, args args) {
t.Helper()
},
afterFunc: func(t *testing.T, args args) {
t.Helper()
},
}
}(),
*/
}

for _, tc := range tests {
test := tc
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()
defer goleak.VerifyNone(tt, goleak.IgnoreCurrent())
if test.beforeFunc != nil {
test.beforeFunc(tt, test.args)
}
if test.afterFunc != nil {
defer test.afterFunc(tt, test.args)
}
checkFunc := test.checkFunc
if test.checkFunc == nil {
checkFunc = defaultCheckFunc
}
s := &server{
indexer: test.fields.indexer,
UnimplementedIndexServer: test.fields.UnimplementedIndexServer,
}

gotRes, err := s.IndexInfo(test.args.ctx, test.args.in1)
if err := checkFunc(test.want, gotRes, err); err != nil {
tt.Errorf("error = %v", err)
}

})
}
}
Loading

0 comments on commit 9e11d1f

Please sign in to comment.