diff --git a/Makefile.d/kind.mk b/Makefile.d/kind.mk index 1d48796fcac..2ff905fb711 100644 --- a/Makefile.d/kind.mk +++ b/Makefile.d/kind.mk @@ -50,12 +50,14 @@ kind/stop: ## start kind (kubernetes in docker) multi node cluster kind/cluster/start: kind create cluster --name $(NAME)-cluster --config $(ROOTDIR)/k8s/debug/kind/config.yaml - @make kind/login + kubectl apply -f https://projectcontour.io/quickstart/contour.yaml + kubectl patch daemonsets -n projectcontour envoy -p '{"spec":{"template":{"spec":{"nodeSelector":{"ingress-ready":"true"},"tolerations":[{"key":"node-role.kubernetes.io/master","operator":"Equal","effect":"NoSchedule"}]}}}}' .PHONY: kind/cluster/stop ## stop kind (kubernetes in docker) multi node cluster kind/cluster/stop: + kubectl delete -f https://projectcontour.io/quickstart/contour.yaml kind delete cluster --name $(NAME)-cluster .PHONY: kind/cluster/login diff --git a/a b/a new file mode 100644 index 00000000000..1517a0fbd31 --- /dev/null +++ b/a @@ -0,0 +1,2378 @@ +diff --git c/pkg/gateway/vald/config/config_test.go w/pkg/gateway/vald/config/config_test.go +deleted file mode 100644 +index e8090717..00000000 +--- c/pkg/gateway/vald/config/config_test.go ++++ /dev/null +@@ -1,101 +0,0 @@ +-// +-// 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 setting stores all server application settings +-package config +- +-import ( +- "reflect" +- "testing" +- +- "github.com/vdaas/vald/internal/errors" +- "go.uber.org/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(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, gotCfg *Data, err error) error { +- if !errors.Is(err, w.err) { +- return errors.Errorf("got error = %v, want %v", err, w.err) +- } +- if !reflect.DeepEqual(gotCfg, w.wantCfg) { +- return errors.Errorf("got = %v, want %v", gotCfg, w.wantCfg) +- } +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- args: args { +- path: "", +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- path: "", +- }, +- 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 +- } +- +- gotCfg, err := NewConfig(test.args.path) +- if err := test.checkFunc(test.want, gotCfg, err); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +diff --git c/pkg/gateway/vald/handler/grpc/checklist_test.go w/pkg/gateway/vald/handler/grpc/checklist_test.go +deleted file mode 100644 +index 805308ea..00000000 +--- c/pkg/gateway/vald/handler/grpc/checklist_test.go ++++ /dev/null +@@ -1,601 +0,0 @@ +-// +-// 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 +- +-import ( +- "reflect" +- "sync" +- "sync/atomic" +- "testing" +- "unsafe" +- +- "github.com/vdaas/vald/internal/errors" +-) +- +-func Test_checkList_Exists(t *testing.T) { +- type args struct { +- key string +- } +- type fields struct { +- mu sync.Mutex +- read atomic.Value +- dirty map[string]*entryCheckList +- misses int +- } +- type want struct { +- want bool +- } +- type test struct { +- name string +- args args +- fields fields +- want want +- checkFunc func(want, bool) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, got bool) 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 { +- key: "", +- }, +- fields: fields { +- mu: sync.Mutex{}, +- read: nil, +- dirty: nil, +- misses: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- key: "", +- }, +- fields: fields { +- mu: sync.Mutex{}, +- read: nil, +- dirty: nil, +- misses: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- } +- }(), +- */ +- } +- +- for _, test := range tests { +- t.Run(test.name, func(tt *testing.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 +- } +- m := &checkList{ +- mu: test.fields.mu, +- read: test.fields.read, +- dirty: test.fields.dirty, +- misses: test.fields.misses, +- } +- +- got := m.Exists(test.args.key) +- if err := test.checkFunc(test.want, got); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +- +-func Test_checkList_Check(t *testing.T) { +- type args struct { +- key string +- } +- type fields struct { +- mu sync.Mutex +- read atomic.Value +- dirty map[string]*entryCheckList +- misses int +- } +- type want struct { +- } +- type test struct { +- name string +- args args +- fields fields +- want want +- checkFunc func(want) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want) error { +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- args: args { +- key: "", +- }, +- fields: fields { +- mu: sync.Mutex{}, +- read: nil, +- dirty: nil, +- misses: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- key: "", +- }, +- fields: fields { +- mu: sync.Mutex{}, +- read: nil, +- dirty: nil, +- misses: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- } +- }(), +- */ +- } +- +- for _, test := range tests { +- t.Run(test.name, func(tt *testing.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 +- } +- m := &checkList{ +- mu: test.fields.mu, +- read: test.fields.read, +- dirty: test.fields.dirty, +- misses: test.fields.misses, +- } +- +- m.Check(test.args.key) +- if err := test.checkFunc(test.want); err != nil { +- tt.Errorf("error = %v", err) +- } +- }) +- } +-} +- +-func Test_entryCheckList_tryStore(t *testing.T) { +- type args struct { +- i *struct{} +- } +- type fields struct { +- p unsafe.Pointer +- } +- type want struct { +- want bool +- } +- type test struct { +- name string +- args args +- fields fields +- want want +- checkFunc func(want, bool) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, got bool) 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 { +- i: struct{}{}, +- }, +- fields: fields { +- p: nil, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- i: struct{}{}, +- }, +- fields: fields { +- p: nil, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- } +- }(), +- */ +- } +- +- for _, test := range tests { +- t.Run(test.name, func(tt *testing.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 +- } +- e := &entryCheckList{ +- p: test.fields.p, +- } +- +- got := e.tryStore(test.args.i) +- if err := test.checkFunc(test.want, got); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +- +-func Test_entryCheckList_unexpungeLocked(t *testing.T) { +- type fields struct { +- p unsafe.Pointer +- } +- type want struct { +- wantWasExpunged bool +- } +- type test struct { +- name string +- fields fields +- want want +- checkFunc func(want, bool) error +- beforeFunc func() +- afterFunc func() +- } +- defaultCheckFunc := func(w want, gotWasExpunged bool) error { +- if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { +- return errors.Errorf("got = %v, want %v", gotWasExpunged, w.wantWasExpunged) +- } +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- fields: fields { +- p: nil, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- fields: fields { +- p: nil, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- } +- }(), +- */ +- } +- +- for _, test := range tests { +- t.Run(test.name, func(tt *testing.T) { +- if test.beforeFunc != nil { +- test.beforeFunc() +- } +- if test.afterFunc != nil { +- defer test.afterFunc() +- } +- if test.checkFunc == nil { +- test.checkFunc = defaultCheckFunc +- } +- e := &entryCheckList{ +- p: test.fields.p, +- } +- +- gotWasExpunged := e.unexpungeLocked() +- if err := test.checkFunc(test.want, gotWasExpunged); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +- +-func Test_checkList_missLocked(t *testing.T) { +- type fields struct { +- mu sync.Mutex +- read atomic.Value +- dirty map[string]*entryCheckList +- misses int +- } +- type want struct { +- } +- type test struct { +- name string +- fields fields +- want want +- checkFunc func(want) error +- beforeFunc func() +- afterFunc func() +- } +- defaultCheckFunc := func(w want) error { +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- fields: fields { +- mu: sync.Mutex{}, +- read: nil, +- dirty: nil, +- misses: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- fields: fields { +- mu: sync.Mutex{}, +- read: nil, +- dirty: nil, +- misses: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- } +- }(), +- */ +- } +- +- for _, test := range tests { +- t.Run(test.name, func(tt *testing.T) { +- if test.beforeFunc != nil { +- test.beforeFunc() +- } +- if test.afterFunc != nil { +- defer test.afterFunc() +- } +- if test.checkFunc == nil { +- test.checkFunc = defaultCheckFunc +- } +- m := &checkList{ +- mu: test.fields.mu, +- read: test.fields.read, +- dirty: test.fields.dirty, +- misses: test.fields.misses, +- } +- +- m.missLocked() +- if err := test.checkFunc(test.want); err != nil { +- tt.Errorf("error = %v", err) +- } +- }) +- } +-} +- +-func Test_checkList_dirtyLocked(t *testing.T) { +- type fields struct { +- mu sync.Mutex +- read atomic.Value +- dirty map[string]*entryCheckList +- misses int +- } +- type want struct { +- } +- type test struct { +- name string +- fields fields +- want want +- checkFunc func(want) error +- beforeFunc func() +- afterFunc func() +- } +- defaultCheckFunc := func(w want) error { +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- fields: fields { +- mu: sync.Mutex{}, +- read: nil, +- dirty: nil, +- misses: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- fields: fields { +- mu: sync.Mutex{}, +- read: nil, +- dirty: nil, +- misses: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- } +- }(), +- */ +- } +- +- for _, test := range tests { +- t.Run(test.name, func(tt *testing.T) { +- if test.beforeFunc != nil { +- test.beforeFunc() +- } +- if test.afterFunc != nil { +- defer test.afterFunc() +- } +- if test.checkFunc == nil { +- test.checkFunc = defaultCheckFunc +- } +- m := &checkList{ +- mu: test.fields.mu, +- read: test.fields.read, +- dirty: test.fields.dirty, +- misses: test.fields.misses, +- } +- +- m.dirtyLocked() +- if err := test.checkFunc(test.want); err != nil { +- tt.Errorf("error = %v", err) +- } +- }) +- } +-} +- +-func Test_entryCheckList_tryExpungeLocked(t *testing.T) { +- type fields struct { +- p unsafe.Pointer +- } +- type want struct { +- wantIsExpunged bool +- } +- type test struct { +- name string +- fields fields +- want want +- checkFunc func(want, bool) error +- beforeFunc func() +- afterFunc func() +- } +- defaultCheckFunc := func(w want, gotIsExpunged bool) error { +- if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { +- return errors.Errorf("got = %v, want %v", gotIsExpunged, w.wantIsExpunged) +- } +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- fields: fields { +- p: nil, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- fields: fields { +- p: nil, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- } +- }(), +- */ +- } +- +- for _, test := range tests { +- t.Run(test.name, func(tt *testing.T) { +- if test.beforeFunc != nil { +- test.beforeFunc() +- } +- if test.afterFunc != nil { +- defer test.afterFunc() +- } +- if test.checkFunc == nil { +- test.checkFunc = defaultCheckFunc +- } +- e := &entryCheckList{ +- p: test.fields.p, +- } +- +- gotIsExpunged := e.tryExpungeLocked() +- if err := test.checkFunc(test.want, gotIsExpunged); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +diff --git c/pkg/gateway/vald/handler/grpc/handler.go w/pkg/gateway/vald/handler/grpc/handler.go +index 7dac4a2f..b7b3832d 100644 +--- c/pkg/gateway/vald/handler/grpc/handler.go ++++ w/pkg/gateway/vald/handler/grpc/handler.go +@@ -27,7 +27,6 @@ import ( + "time" +  + "github.com/kpango/fuid" +- agent "github.com/vdaas/vald/apis/grpc/agent/core" + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "github.com/vdaas/vald/apis/grpc/payload" + "github.com/vdaas/vald/internal/errgroup" +@@ -87,9 +86,12 @@ func (s *server) Search(ctx context.Context, req *payload.Search_Request) (res * + span.End() + } + }() ++ if len(req.Vector) < 2 { ++ return nil, errors.ErrInvalidDimensionSize(len(req.Vector), 0) ++ } + return s.search(ctx, req.GetConfig(), +- func(ctx context.Context, ac agent.AgentClient, copts ...grpc.CallOption) (*payload.Search_Response, error) { +- return ac.Search(ctx, req, copts...) ++ func(ctx context.Context, vc vald.ValdClient, copts ...grpc.CallOption) (*payload.Search_Response, error) { ++ return vc.Search(ctx, req, copts...) + }) + } +  +@@ -112,13 +114,13 @@ func (s *server) SearchByID(ctx context.Context, req *payload.Search_IDRequest) + return nil, status.WrapWithNotFound(fmt.Sprintf("SearchByID API meta %s's uuid not found", metaID), err, req, info.Get()) + } + return s.search(ctx, req.GetConfig(), +- func(ctx context.Context, ac agent.AgentClient, copts ...grpc.CallOption) (*payload.Search_Response, error) { +- return ac.SearchByID(ctx, req, copts...) ++ func(ctx context.Context, vc vald.ValdClient, copts ...grpc.CallOption) (*payload.Search_Response, error) { ++ return vc.SearchByID(ctx, req, copts...) + }) + } +  + func (s *server) search(ctx context.Context, cfg *payload.Search_Config, +- f func(ctx context.Context, ac agent.AgentClient, copts ...grpc.CallOption) (*payload.Search_Response, error)) ( ++ f func(ctx context.Context, vc vald.ValdClient, copts ...grpc.CallOption) (*payload.Search_Response, error)) ( + res *payload.Search_Response, err error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.search") + defer func() { +@@ -126,6 +128,7 @@ func (s *server) search(ctx context.Context, cfg *payload.Search_Config, + span.End() + } + }() ++ + maxDist := uint32(math.MaxUint32) + num := int(cfg.GetNum()) + res = new(payload.Search_Response) +@@ -146,8 +149,8 @@ func (s *server) search(ctx context.Context, cfg *payload.Search_Config, + // cl := new(checkList) + visited := make(map[string]bool, len(res.Results)) + mu := sync.RWMutex{} +- return s.gateway.BroadCast(ectx, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error { +- r, err := f(ctx, ac, copts...) ++ return s.gateway.BroadCast(ectx, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error { ++ r, err := f(ctx, vc, copts...) + if err != nil { + log.Debug(err) + return nil +@@ -283,13 +286,16 @@ func (s *server) StreamSearchByID(stream vald.Vald_StreamSearchByIDServer) error + }) + } +  +-func (s *server) Insert(ctx context.Context, vec *payload.Object_Vector) (ce *payload.Empty, err error) { ++func (s *server) Insert(ctx context.Context, vec *payload.Object_Vector) (ce *payload.Object_Location, err error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.Insert") + defer func() { + if span != nil { + span.End() + } + }() ++ if len(vec.Vector) < 2 { ++ return nil, errors.ErrInvalidDimensionSize(len(vec.Vector), 0) ++ } + meta := vec.GetId() + exists, err := s.metadata.Exists(ctx, meta) + if err != nil { +@@ -320,8 +326,8 @@ func (s *server) Insert(ctx context.Context, vec *payload.Object_Vector) (ce *pa + vec.Id = uuid + mu := new(sync.Mutex) + targets := make([]string, 0, s.replica) +- err = s.gateway.DoMulti(ctx, s.replica, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) (err error) { +- _, err = ac.Insert(ctx, vec, copts...) ++ err = s.gateway.DoMulti(ctx, s.replica, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) (err error) { ++ _, err = vc.Insert(ctx, vec, copts...) + if err != nil { + if err == errors.ErrRPCCallFailed(target, context.Canceled) { + return nil +@@ -345,7 +351,6 @@ func (s *server) Insert(ctx context.Context, vec *payload.Object_Vector) (ce *pa + if s.backup != nil { + vecs := &payload.Backup_MetaVector{ + Uuid: uuid, +- Meta: meta, + Ips: targets, + } + if vec != nil { +@@ -362,7 +367,7 @@ func (s *server) Insert(ctx context.Context, vec *payload.Object_Vector) (ce *pa + } + } + log.Debugf("Insert API insert succeeded to %v", targets) +- return new(payload.Empty), nil ++ return new(payload.Object_Location), nil + } +  + func (s *server) StreamInsert(stream vald.Vald_StreamInsertServer) error { +@@ -379,7 +384,7 @@ func (s *server) StreamInsert(stream vald.Vald_StreamInsertServer) error { + }) + } +  +-func (s *server) MultiInsert(ctx context.Context, vecs *payload.Object_Vectors) (res *payload.Empty, err error) { ++func (s *server) MultiInsert(ctx context.Context, vecs *payload.Object_Vectors) (res *payload.Object_Locations, err error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.MultiInsert") + defer func() { + if span != nil { +@@ -425,8 +430,8 @@ func (s *server) MultiInsert(ctx context.Context, vecs *payload.Object_Vectors) +  + mu := new(sync.Mutex) + targets := make([]string, 0, s.replica) +- gerr := s.gateway.DoMulti(ctx, s.replica, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) (err error) { +- _, err = ac.MultiInsert(ctx, vecs, copts...) ++ gerr := s.gateway.DoMulti(ctx, s.replica, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) (err error) { ++ _, err = vc.MultiInsert(ctx, vecs, copts...) + if err != nil { + return err + } +@@ -450,7 +455,6 @@ func (s *server) MultiInsert(ctx context.Context, vecs *payload.Object_Vectors) + uuid := vec.GetId() + mvecs.Vectors = append(mvecs.Vectors, &payload.Backup_MetaVector{ + Uuid: uuid, +- Meta: metaMap[uuid], + Vector: vec.GetVector(), + Ips: targets, + }) +@@ -463,10 +467,10 @@ func (s *server) MultiInsert(ctx context.Context, vecs *payload.Object_Vectors) + return nil, status.WrapWithInternal(fmt.Sprintf("MultiInsert API failed RegisterMultiple %#v", mvecs), err, info.Get()) + } + } +- return new(payload.Empty), nil ++ return new(payload.Object_Locations), nil + } +  +-func (s *server) Update(ctx context.Context, vec *payload.Object_Vector) (res *payload.Empty, err error) { ++func (s *server) Update(ctx context.Context, vec *payload.Object_Vector) (res *payload.Object_Location, err error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.Update") + defer func() { + if span != nil { +@@ -493,11 +497,11 @@ func (s *server) Update(ctx context.Context, vec *payload.Object_Vector) (res *p + for _, loc := range locs { + lmap[loc] = struct{}{} + } +- err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error { ++ err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error { + target = strings.SplitN(target, ":", 2)[0] + _, ok := lmap[target] + if ok { +- _, err = ac.Update(ctx, vec, copts...) ++ _, err = vc.Update(ctx, vec, copts...) + if err != nil { + return err + } +@@ -510,13 +514,11 @@ func (s *server) Update(ctx context.Context, vec *payload.Object_Vector) (res *p + } + return nil, status.WrapWithInternal(fmt.Sprintf("Update API failed request %#v", vec), err, info.Get()) + } +- mvec := &payload.Backup_MetaVector{ ++ err = s.backup.Register(ctx, &payload.Backup_MetaVector{ + Uuid: uuid, +- Meta: meta, + Vector: vec.GetVector(), + Ips: locs, +- } +- err = s.backup.Register(ctx, mvec) ++ }) + if err != nil { + if span != nil { + span.SetStatus(trace.StatusCodeInternal(err.Error())) +@@ -524,7 +526,7 @@ func (s *server) Update(ctx context.Context, vec *payload.Object_Vector) (res *p + return nil, status.WrapWithInternal(fmt.Sprintf("Update API failed backup %#v", vec), err, info.Get()) + } +  +- return new(payload.Empty), nil ++ return new(payload.Object_Location), nil + } +  + func (s *server) StreamUpdate(stream vald.Vald_StreamUpdateServer) error { +@@ -541,7 +543,7 @@ func (s *server) StreamUpdate(stream vald.Vald_StreamUpdateServer) error { + }) + } +  +-func (s *server) MultiUpdate(ctx context.Context, vecs *payload.Object_Vectors) (res *payload.Empty, err error) { ++func (s *server) MultiUpdate(ctx context.Context, vecs *payload.Object_Vectors) (res *payload.Object_Locations, err error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.MultiUpdate") + defer func() { + if span != nil { +@@ -568,10 +570,10 @@ func (s *server) MultiUpdate(ctx context.Context, vecs *payload.Object_Vectors) + } + return nil, status.WrapWithInternal(fmt.Sprintf("MultiUpdate API failed Insert request %#v", vecs), err, info.Get()) + } +- return new(payload.Empty), nil ++ return new(payload.Object_Locations), nil + } +  +-func (s *server) Upsert(ctx context.Context, vec *payload.Object_Vector) (*payload.Empty, error) { ++func (s *server) Upsert(ctx context.Context, vec *payload.Object_Vector) (*payload.Object_Location, error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.Upsert") + defer func() { + if span != nil { +@@ -600,7 +602,7 @@ func (s *server) Upsert(ctx context.Context, vec *payload.Object_Vector) (*paylo + } + } +  +- return new(payload.Empty), errs ++ return new(payload.Object_Location), errs + } +  + func (s *server) StreamUpsert(stream vald.Vald_StreamUpsertServer) error { +@@ -617,7 +619,7 @@ func (s *server) StreamUpsert(stream vald.Vald_StreamUpsertServer) error { + }) + } +  +-func (s *server) MultiUpsert(ctx context.Context, vecs *payload.Object_Vectors) (*payload.Empty, error) { ++func (s *server) MultiUpsert(ctx context.Context, vecs *payload.Object_Vectors) (*payload.Object_Locations, error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.MultiUpsert") + defer func() { + if span != nil { +@@ -674,10 +676,10 @@ func (s *server) MultiUpsert(ctx context.Context, vecs *payload.Object_Vectors) + return nil, status.WrapWithInternal("MultiUpsert API failed", errs, info.Get()) + } +  +- return new(payload.Empty), errs ++ return new(payload.Object_Locations), errs + } +  +-func (s *server) Remove(ctx context.Context, id *payload.Object_ID) (*payload.Empty, error) { ++func (s *server) Remove(ctx context.Context, id *payload.Object_ID) (*payload.Object_Location, error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.Remove") + defer func() { + if span != nil { +@@ -703,10 +705,10 @@ func (s *server) Remove(ctx context.Context, id *payload.Object_ID) (*payload.Em + for _, loc := range locs { + lmap[loc] = struct{}{} + } +- err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error { ++ err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error { + _, ok := lmap[target] + if ok { +- _, err = ac.Remove(ctx, &payload.Object_ID{ ++ _, err = vc.Remove(ctx, &payload.Object_ID{ + Id: uuid, + }, copts...) + if err != nil { +@@ -735,7 +737,7 @@ func (s *server) Remove(ctx context.Context, id *payload.Object_ID) (*payload.Em + } + return nil, status.WrapWithInternal(fmt.Sprintf("Remove API failed to Remove backup uuid = %s", uuid), err, info.Get()) + } +- return new(payload.Empty), nil ++ return new(payload.Object_Location), nil + } +  + func (s *server) StreamRemove(stream vald.Vald_StreamRemoveServer) error { +@@ -752,7 +754,7 @@ func (s *server) StreamRemove(stream vald.Vald_StreamRemoveServer) error { + }) + } +  +-func (s *server) MultiRemove(ctx context.Context, ids *payload.Object_IDs) (res *payload.Empty, err error) { ++func (s *server) MultiRemove(ctx context.Context, ids *payload.Object_IDs) (res *payload.Object_Locations, err error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.MultiRemove") + defer func() { + if span != nil { +@@ -776,10 +778,10 @@ func (s *server) MultiRemove(ctx context.Context, ids *payload.Object_IDs) (res + lmap[loc] = append(lmap[loc], uuid) + } + } +- err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error { ++ err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error { + uuids, ok := lmap[target] + if ok { +- _, err := ac.MultiRemove(ctx, &payload.Object_IDs{ ++ _, err := vc.MultiRemove(ctx, &payload.Object_IDs{ + Ids: uuids, + }, copts...) + if err != nil { +@@ -808,10 +810,10 @@ func (s *server) MultiRemove(ctx context.Context, ids *payload.Object_IDs) (res + } + return nil, status.WrapWithInternal(fmt.Sprintf("MultiRemove API failed to Remove backup uuids %v ", uuids), err, info.Get()) + } +- return new(payload.Empty), nil ++ return new(payload.Object_Locations), nil + } +  +-func (s *server) GetObject(ctx context.Context, id *payload.Object_ID) (vec *payload.Backup_MetaVector, err error) { ++func (s *server) GetObject(ctx context.Context, id *payload.Object_ID) (vec *payload.Object_Vector, err error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.GetObject") + defer func() { + if span != nil { +@@ -826,13 +828,17 @@ func (s *server) GetObject(ctx context.Context, id *payload.Object_ID) (vec *pay + } + return nil, status.WrapWithNotFound(fmt.Sprintf("GetObject API meta %s's uuid not found", meta), err, info.Get()) + } +- vec, err = s.backup.GetObject(ctx, uuid) ++ mvec, err := s.backup.GetObject(ctx, uuid) + if err != nil { + if span != nil { + span.SetStatus(trace.StatusCodeNotFound(err.Error())) + } + return nil, status.WrapWithNotFound(fmt.Sprintf("GetObject API meta %s uuid %s Object not found", meta, uuid), err, info.Get()) + } ++ vec = &payload.Object_Vector{ ++ Id: mvec.GetUuid(), ++ Vector: mvec.GetVector(), ++ } + return vec, nil + } +  +diff --git c/pkg/gateway/vald/handler/grpc/handler_test.go w/pkg/gateway/vald/handler/grpc/handler_test.go +deleted file mode 100644 +index b2d6bb98..00000000 +--- c/pkg/gateway/vald/handler/grpc/handler_test.go ++++ /dev/null +@@ -1,2440 +0,0 @@ +-// +-// 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 grpc server logic +-package grpc +- +-import ( +- "context" +- "reflect" +- "testing" +- "time" +- +- agent "github.com/vdaas/vald/apis/grpc/agent/core" +- "github.com/vdaas/vald/apis/grpc/gateway/vald" +- "github.com/vdaas/vald/apis/grpc/payload" +- "github.com/vdaas/vald/internal/errgroup" +- "github.com/vdaas/vald/internal/errors" +- "github.com/vdaas/vald/internal/net/grpc" +- "github.com/vdaas/vald/pkg/gateway/vald/service" +- +- "go.uber.org/goleak" +-) +- +-func TestNew(t *testing.T) { +- type args struct { +- opts []Option +- } +- type want struct { +- want vald.ValdServer +- } +- type test struct { +- name string +- args args +- want want +- checkFunc func(want, vald.ValdServer) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, got vald.ValdServer) 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 { +- opts: nil, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- opts: 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 := New(test.args.opts...) +- if err := test.checkFunc(test.want, got); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +- +-func Test_server_Exists(t *testing.T) { +- type args struct { +- ctx context.Context +- meta *payload.Object_ID +- } +- type fields struct { +- eg errgroup.Group +- gateway service.Gateway +- metadata service.Meta +- backup service.Backup +- timeout time.Duration +- filter service.Filter +- replica int +- streamConcurrency int +- } +- type want struct { +- want *payload.Object_ID +- err error +- } +- type test struct { +- name string +- args args +- fields fields +- want want +- checkFunc func(want, *payload.Object_ID, error) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, got *payload.Object_ID, err error) error { +- if !errors.Is(err, w.err) { +- return errors.Errorf("got error = %v, want %v", err, w.err) +- } +- 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 { +- ctx: nil, +- meta: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- ctx: nil, +- meta: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- 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 +- } +- s := &server{ +- eg: test.fields.eg, +- gateway: test.fields.gateway, +- metadata: test.fields.metadata, +- backup: test.fields.backup, +- timeout: test.fields.timeout, +- filter: test.fields.filter, +- replica: test.fields.replica, +- streamConcurrency: test.fields.streamConcurrency, +- } +- +- got, err := s.Exists(test.args.ctx, test.args.meta) +- if err := test.checkFunc(test.want, got, err); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +- +-func Test_server_Search(t *testing.T) { +- type args struct { +- ctx context.Context +- req *payload.Search_Request +- } +- type fields struct { +- eg errgroup.Group +- gateway service.Gateway +- metadata service.Meta +- backup service.Backup +- timeout time.Duration +- filter service.Filter +- replica int +- streamConcurrency int +- } +- type want struct { +- wantRes *payload.Search_Response +- err error +- } +- type test struct { +- name string +- args args +- fields fields +- want want +- checkFunc func(want, *payload.Search_Response, error) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { +- if !errors.Is(err, w.err) { +- return errors.Errorf("got error = %v, want %v", err, w.err) +- } +- if !reflect.DeepEqual(gotRes, w.wantRes) { +- return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) +- } +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- args: args { +- ctx: nil, +- req: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- ctx: nil, +- req: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- 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 +- } +- s := &server{ +- eg: test.fields.eg, +- gateway: test.fields.gateway, +- metadata: test.fields.metadata, +- backup: test.fields.backup, +- timeout: test.fields.timeout, +- filter: test.fields.filter, +- replica: test.fields.replica, +- streamConcurrency: test.fields.streamConcurrency, +- } +- +- gotRes, err := s.Search(test.args.ctx, test.args.req) +- if err := test.checkFunc(test.want, gotRes, err); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +- +-func Test_server_SearchByID(t *testing.T) { +- type args struct { +- ctx context.Context +- req *payload.Search_IDRequest +- } +- type fields struct { +- eg errgroup.Group +- gateway service.Gateway +- metadata service.Meta +- backup service.Backup +- timeout time.Duration +- filter service.Filter +- replica int +- streamConcurrency int +- } +- type want struct { +- wantRes *payload.Search_Response +- err error +- } +- type test struct { +- name string +- args args +- fields fields +- want want +- checkFunc func(want, *payload.Search_Response, error) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { +- if !errors.Is(err, w.err) { +- return errors.Errorf("got error = %v, want %v", err, w.err) +- } +- if !reflect.DeepEqual(gotRes, w.wantRes) { +- return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) +- } +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- args: args { +- ctx: nil, +- req: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- ctx: nil, +- req: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- 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 +- } +- s := &server{ +- eg: test.fields.eg, +- gateway: test.fields.gateway, +- metadata: test.fields.metadata, +- backup: test.fields.backup, +- timeout: test.fields.timeout, +- filter: test.fields.filter, +- replica: test.fields.replica, +- streamConcurrency: test.fields.streamConcurrency, +- } +- +- gotRes, err := s.SearchByID(test.args.ctx, test.args.req) +- if err := test.checkFunc(test.want, gotRes, err); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +- +-func Test_server_search(t *testing.T) { +- type args struct { +- ctx context.Context +- cfg *payload.Search_Config +- f func(ctx context.Context, ac agent.AgentClient, copts ...grpc.CallOption) (*payload.Search_Response, error) +- } +- type fields struct { +- eg errgroup.Group +- gateway service.Gateway +- metadata service.Meta +- backup service.Backup +- timeout time.Duration +- filter service.Filter +- replica int +- streamConcurrency int +- } +- type want struct { +- wantRes *payload.Search_Response +- err error +- } +- type test struct { +- name string +- args args +- fields fields +- want want +- checkFunc func(want, *payload.Search_Response, error) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { +- if !errors.Is(err, w.err) { +- return errors.Errorf("got error = %v, want %v", err, w.err) +- } +- if !reflect.DeepEqual(gotRes, w.wantRes) { +- return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) +- } +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- args: args { +- ctx: nil, +- cfg: nil, +- f: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- ctx: nil, +- cfg: nil, +- f: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- 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 +- } +- s := &server{ +- eg: test.fields.eg, +- gateway: test.fields.gateway, +- metadata: test.fields.metadata, +- backup: test.fields.backup, +- timeout: test.fields.timeout, +- filter: test.fields.filter, +- replica: test.fields.replica, +- streamConcurrency: test.fields.streamConcurrency, +- } +- +- gotRes, err := s.search(test.args.ctx, test.args.cfg, test.args.f) +- if err := test.checkFunc(test.want, gotRes, err); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +- +-func Test_server_StreamSearch(t *testing.T) { +- type args struct { +- stream vald.Vald_StreamSearchServer +- } +- type fields struct { +- eg errgroup.Group +- gateway service.Gateway +- metadata service.Meta +- backup service.Backup +- timeout time.Duration +- filter service.Filter +- replica int +- streamConcurrency int +- } +- type want struct { +- err error +- } +- type test struct { +- name string +- args args +- fields fields +- want want +- checkFunc func(want, error) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, err error) error { +- if !errors.Is(err, w.err) { +- return errors.Errorf("got error = %v, want %v", err, w.err) +- } +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- args: args { +- stream: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- stream: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- 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 +- } +- s := &server{ +- eg: test.fields.eg, +- gateway: test.fields.gateway, +- metadata: test.fields.metadata, +- backup: test.fields.backup, +- timeout: test.fields.timeout, +- filter: test.fields.filter, +- replica: test.fields.replica, +- streamConcurrency: test.fields.streamConcurrency, +- } +- +- err := s.StreamSearch(test.args.stream) +- if err := test.checkFunc(test.want, err); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +- +-func Test_server_StreamSearchByID(t *testing.T) { +- type args struct { +- stream vald.Vald_StreamSearchByIDServer +- } +- type fields struct { +- eg errgroup.Group +- gateway service.Gateway +- metadata service.Meta +- backup service.Backup +- timeout time.Duration +- filter service.Filter +- replica int +- streamConcurrency int +- } +- type want struct { +- err error +- } +- type test struct { +- name string +- args args +- fields fields +- want want +- checkFunc func(want, error) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, err error) error { +- if !errors.Is(err, w.err) { +- return errors.Errorf("got error = %v, want %v", err, w.err) +- } +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- args: args { +- stream: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- stream: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- 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 +- } +- s := &server{ +- eg: test.fields.eg, +- gateway: test.fields.gateway, +- metadata: test.fields.metadata, +- backup: test.fields.backup, +- timeout: test.fields.timeout, +- filter: test.fields.filter, +- replica: test.fields.replica, +- streamConcurrency: test.fields.streamConcurrency, +- } +- +- err := s.StreamSearchByID(test.args.stream) +- if err := test.checkFunc(test.want, err); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +- +-func Test_server_Insert(t *testing.T) { +- type args struct { +- ctx context.Context +- vec *payload.Object_Vector +- } +- type fields struct { +- eg errgroup.Group +- gateway service.Gateway +- metadata service.Meta +- backup service.Backup +- timeout time.Duration +- filter service.Filter +- replica int +- streamConcurrency int +- } +- type want struct { +- wantCe *payload.Empty +- err error +- } +- type test struct { +- name string +- args args +- fields fields +- want want +- checkFunc func(want, *payload.Empty, error) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, gotCe *payload.Empty, err error) error { +- if !errors.Is(err, w.err) { +- return errors.Errorf("got error = %v, want %v", err, w.err) +- } +- if !reflect.DeepEqual(gotCe, w.wantCe) { +- return errors.Errorf("got = %v, want %v", gotCe, w.wantCe) +- } +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- args: args { +- ctx: nil, +- vec: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- ctx: nil, +- vec: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- 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 +- } +- s := &server{ +- eg: test.fields.eg, +- gateway: test.fields.gateway, +- metadata: test.fields.metadata, +- backup: test.fields.backup, +- timeout: test.fields.timeout, +- filter: test.fields.filter, +- replica: test.fields.replica, +- streamConcurrency: test.fields.streamConcurrency, +- } +- +- gotCe, err := s.Insert(test.args.ctx, test.args.vec) +- if err := test.checkFunc(test.want, gotCe, err); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +- +-func Test_server_StreamInsert(t *testing.T) { +- type args struct { +- stream vald.Vald_StreamInsertServer +- } +- type fields struct { +- eg errgroup.Group +- gateway service.Gateway +- metadata service.Meta +- backup service.Backup +- timeout time.Duration +- filter service.Filter +- replica int +- streamConcurrency int +- } +- type want struct { +- err error +- } +- type test struct { +- name string +- args args +- fields fields +- want want +- checkFunc func(want, error) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, err error) error { +- if !errors.Is(err, w.err) { +- return errors.Errorf("got error = %v, want %v", err, w.err) +- } +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- args: args { +- stream: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- stream: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- 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 +- } +- s := &server{ +- eg: test.fields.eg, +- gateway: test.fields.gateway, +- metadata: test.fields.metadata, +- backup: test.fields.backup, +- timeout: test.fields.timeout, +- filter: test.fields.filter, +- replica: test.fields.replica, +- streamConcurrency: test.fields.streamConcurrency, +- } +- +- err := s.StreamInsert(test.args.stream) +- if err := test.checkFunc(test.want, err); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +- +-func Test_server_MultiInsert(t *testing.T) { +- type args struct { +- ctx context.Context +- vecs *payload.Object_Vectors +- } +- type fields struct { +- eg errgroup.Group +- gateway service.Gateway +- metadata service.Meta +- backup service.Backup +- timeout time.Duration +- filter service.Filter +- replica int +- streamConcurrency int +- } +- type want struct { +- wantRes *payload.Empty +- err error +- } +- type test struct { +- name string +- args args +- fields fields +- want want +- checkFunc func(want, *payload.Empty, error) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, gotRes *payload.Empty, err error) error { +- if !errors.Is(err, w.err) { +- return errors.Errorf("got error = %v, want %v", err, w.err) +- } +- if !reflect.DeepEqual(gotRes, w.wantRes) { +- return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) +- } +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- args: args { +- ctx: nil, +- vecs: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- ctx: nil, +- vecs: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- 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 +- } +- s := &server{ +- eg: test.fields.eg, +- gateway: test.fields.gateway, +- metadata: test.fields.metadata, +- backup: test.fields.backup, +- timeout: test.fields.timeout, +- filter: test.fields.filter, +- replica: test.fields.replica, +- streamConcurrency: test.fields.streamConcurrency, +- } +- +- gotRes, err := s.MultiInsert(test.args.ctx, test.args.vecs) +- if err := test.checkFunc(test.want, gotRes, err); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +- +-func Test_server_Update(t *testing.T) { +- type args struct { +- ctx context.Context +- vec *payload.Object_Vector +- } +- type fields struct { +- eg errgroup.Group +- gateway service.Gateway +- metadata service.Meta +- backup service.Backup +- timeout time.Duration +- filter service.Filter +- replica int +- streamConcurrency int +- } +- type want struct { +- wantRes *payload.Empty +- err error +- } +- type test struct { +- name string +- args args +- fields fields +- want want +- checkFunc func(want, *payload.Empty, error) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, gotRes *payload.Empty, err error) error { +- if !errors.Is(err, w.err) { +- return errors.Errorf("got error = %v, want %v", err, w.err) +- } +- if !reflect.DeepEqual(gotRes, w.wantRes) { +- return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) +- } +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- args: args { +- ctx: nil, +- vec: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { +- ctx: nil, +- vec: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- 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 +- } +- s := &server{ +- eg: test.fields.eg, +- gateway: test.fields.gateway, +- metadata: test.fields.metadata, +- backup: test.fields.backup, +- timeout: test.fields.timeout, +- filter: test.fields.filter, +- replica: test.fields.replica, +- streamConcurrency: test.fields.streamConcurrency, +- } +- +- gotRes, err := s.Update(test.args.ctx, test.args.vec) +- if err := test.checkFunc(test.want, gotRes, err); err != nil { +- tt.Errorf("error = %v", err) +- } +- +- }) +- } +-} +- +-func Test_server_StreamUpdate(t *testing.T) { +- type args struct { +- stream vald.Vald_StreamUpdateServer +- } +- type fields struct { +- eg errgroup.Group +- gateway service.Gateway +- metadata service.Meta +- backup service.Backup +- timeout time.Duration +- filter service.Filter +- replica int +- streamConcurrency int +- } +- type want struct { +- err error +- } +- type test struct { +- name string +- args args +- fields fields +- want want +- checkFunc func(want, error) error +- beforeFunc func(args) +- afterFunc func(args) +- } +- defaultCheckFunc := func(w want, err error) error { +- if !errors.Is(err, w.err) { +- return errors.Errorf("got error = %v, want %v", err, w.err) +- } +- return nil +- } +- tests := []test{ +- // TODO test cases +- /* +- { +- name: "test_case_1", +- args: args { +- stream: nil, +- }, +- fields: fields { +- eg: nil, +- gateway: nil, +- metadata: nil, +- backup: nil, +- timeout: nil, +- filter: nil, +- replica: 0, +- streamConcurrency: 0, +- }, +- want: want{}, +- checkFunc: defaultCheckFunc, +- }, +- */ +- +- // TODO test cases +- /* +- func() test { +- return test { +- name: "test_case_2", +- args: args { \ No newline at end of file diff --git a/go.mod b/go.mod index 2cb47e29eb0..38c2aeb8820 100755 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ replace ( github.com/docker/docker => github.com/moby/moby v17.12.0-ce-rc1.0.20200531234253-77e06fda0c94+incompatible github.com/envoyproxy/protoc-gen-validate => github.com/envoyproxy/protoc-gen-validate v0.3.0-java github.com/go-sql-driver/mysql => github.com/go-sql-driver/mysql v1.5.1-0.20200531100419-12508c83901b - github.com/gocql/gocql => github.com/gocql/gocql v0.0.0-20200608162118-cb62e193e52b + github.com/gocql/gocql => github.com/gocql/gocql v0.0.0-20200613210051-80dc62113c6d github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.1 github.com/gophercloud/gophercloud => github.com/gophercloud/gophercloud v0.11.0 github.com/gorilla/mux => github.com/gorilla/mux v1.7.5-0.20200517040254-948bec34b516 @@ -60,7 +60,7 @@ require ( golang.org/x/mod v0.3.0 // indirect golang.org/x/net v0.0.0-20200226121028-0de0cce0169b golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 - golang.org/x/tools v0.0.0-20200612184736-e8084ff2bf72 // indirect + golang.org/x/tools v0.0.0-20200612220849-54c614fe050c // indirect gonum.org/v1/hdf5 v0.0.0-20200504100616-496fefe91614 gonum.org/v1/netlib v0.0.0-20200603212716-16abd5ac5bc7 // indirect gonum.org/v1/plot v0.7.0 diff --git a/go.sum b/go.sum index 2d155d6ff3d..dc27e13e627 100644 --- a/go.sum +++ b/go.sum @@ -199,8 +199,8 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= -github.com/gocql/gocql v0.0.0-20200608162118-cb62e193e52b h1:ehjJsmZzqcE3nGO1uKvEKOIflkdUyEjTDP7fA2m7f2c= -github.com/gocql/gocql v0.0.0-20200608162118-cb62e193e52b/go.mod h1:DL0ekTmBSTdlNF25Orwt/JMzqIq3EJ4MVa/J/uK64OY= +github.com/gocql/gocql v0.0.0-20200613210051-80dc62113c6d h1:R3kjNu2wYkhRIBWg0r7vXIssrnduTwZ4camGrmP4FnM= +github.com/gocql/gocql v0.0.0-20200613210051-80dc62113c6d/go.mod h1:DL0ekTmBSTdlNF25Orwt/JMzqIq3EJ4MVa/J/uK64OY= github.com/gocraft/dbr/v2 v2.7.0 h1:x+UnhSBYPFBBdtikLSMLQ9KPuquSUj4yBijsQAhhNZo= github.com/gocraft/dbr/v2 v2.7.0/go.mod h1:wQdbxPBSloo2OlSedMxfNW0mgk0GXys9O1VFmQiwcx4= github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -669,8 +669,8 @@ golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191203134012-c197fd4bf371/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200612184736-e8084ff2bf72 h1:rZAbum9mjcbc5rFLG1zbCFiTAYotr57xtYD0TlSGcDQ= -golang.org/x/tools v0.0.0-20200612184736-e8084ff2bf72/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200612220849-54c614fe050c h1:g6oFfz6Cmw68izP3xsdud3Oxu145IPkeFzyRg58AKHM= +golang.org/x/tools v0.0.0-20200612220849-54c614fe050c/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= diff --git a/k8s/debug/kind/config.yaml b/k8s/debug/kind/config.yaml index 9b7364754f0..34fff8f51da 100644 --- a/k8s/debug/kind/config.yaml +++ b/k8s/debug/kind/config.yaml @@ -19,6 +19,19 @@ apiVersion: kind.x-k8s.io/v1alpha4 # AllBeta: false nodes: - role: control-plane + kubeadmConfigPatches: + - | + kind: InitConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "ingress-ready=true" + extraPortMappings: + - containerPort: 80 + hostPort: 8080 + protocol: TCP + - containerPort: 443 + hostPort: 4443 + protocol: TCP - role: worker - role: worker - role: worker diff --git a/pkg/gateway/backup/config/config_test.go b/pkg/gateway/backup/config/config_test.go new file mode 100644 index 00000000000..d9ccf63cfe9 --- /dev/null +++ b/pkg/gateway/backup/config/config_test.go @@ -0,0 +1,100 @@ +// +// 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 setting stores all server application settings +package config + +import ( + "reflect" + "testing" + + "go.uber.org/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(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCfg *Data, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCfg, w.wantCfg) { + return errors.Errorf("got = %v, want %v", gotCfg, w.wantCfg) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + path: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + path: "", + }, + 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 + } + + gotCfg, err := NewConfig(test.args.path) + if err := test.checkFunc(test.want, gotCfg, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/backup/handler/grpc/checklist_test.go b/pkg/gateway/backup/handler/grpc/checklist_test.go new file mode 100644 index 00000000000..0fb9c171933 --- /dev/null +++ b/pkg/gateway/backup/handler/grpc/checklist_test.go @@ -0,0 +1,608 @@ +// +// 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 + +import ( + "reflect" + "sync" + "sync/atomic" + "testing" + "unsafe" + + "go.uber.org/goleak" +) + +func Test_checkList_Exists(t *testing.T) { + type args struct { + key string + } + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + want bool + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got bool) 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 { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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 + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + got := m.Exists(test.args.key) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_checkList_Check(t *testing.T) { + type args struct { + key string + } + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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 + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.Check(test.args.key) + if err := test.checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_entryCheckList_tryStore(t *testing.T) { + type args struct { + i *struct{} + } + type fields struct { + p unsafe.Pointer + } + type want struct { + want bool + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got bool) 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 { + i: struct{}{}, + }, + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + i: struct{}{}, + }, + fields: fields { + p: 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 + } + e := &entryCheckList{ + p: test.fields.p, + } + + got := e.tryStore(test.args.i) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_entryCheckList_unexpungeLocked(t *testing.T) { + type fields struct { + p unsafe.Pointer + } + type want struct { + wantWasExpunged bool + } + type test struct { + name string + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want, gotWasExpunged bool) error { + if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { + return errors.Errorf("got = %v, want %v", gotWasExpunged, w.wantWasExpunged) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + p: 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + e := &entryCheckList{ + p: test.fields.p, + } + + gotWasExpunged := e.unexpungeLocked() + if err := test.checkFunc(test.want, gotWasExpunged); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_checkList_missLocked(t *testing.T) { + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + } + type test struct { + name string + fields fields + want want + checkFunc func(want) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.missLocked() + if err := test.checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_checkList_dirtyLocked(t *testing.T) { + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + } + type test struct { + name string + fields fields + want want + checkFunc func(want) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.dirtyLocked() + if err := test.checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_entryCheckList_tryExpungeLocked(t *testing.T) { + type fields struct { + p unsafe.Pointer + } + type want struct { + wantIsExpunged bool + } + type test struct { + name string + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want, gotIsExpunged bool) error { + if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { + return errors.Errorf("got = %v, want %v", gotIsExpunged, w.wantIsExpunged) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + p: 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + e := &entryCheckList{ + p: test.fields.p, + } + + gotIsExpunged := e.tryExpungeLocked() + if err := test.checkFunc(test.want, gotIsExpunged); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/backup/handler/grpc/handler_test.go b/pkg/gateway/backup/handler/grpc/handler_test.go new file mode 100644 index 00000000000..be3a4edc22f --- /dev/null +++ b/pkg/gateway/backup/handler/grpc/handler_test.go @@ -0,0 +1,2439 @@ +// +// 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 grpc server logic +package grpc + +import ( + "context" + "reflect" + "testing" + "time" + + agent "github.com/vdaas/vald/apis/grpc/agent/core" + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "github.com/vdaas/vald/apis/grpc/payload" + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "github.com/vdaas/vald/pkg/gateway/backup/service" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want vald.ValdServer + } + type test struct { + name string + args args + want want + checkFunc func(want, vald.ValdServer) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got vald.ValdServer) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Exists(t *testing.T) { + type args struct { + ctx context.Context + meta *payload.Object_ID + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_ID + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_ID, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_ID, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + meta: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.Exists(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Search(t *testing.T) { + type args struct { + ctx context.Context + req *payload.Search_Request + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.Search(test.args.ctx, test.args.req) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_SearchByID(t *testing.T) { + type args struct { + ctx context.Context + req *payload.Search_IDRequest + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.SearchByID(test.args.ctx, test.args.req) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_search(t *testing.T) { + type args struct { + ctx context.Context + cfg *payload.Search_Config + f func(ctx context.Context, ac agent.AgentClient, copts ...grpc.CallOption) (*payload.Search_Response, error) + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + cfg: nil, + f: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + cfg: nil, + f: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.search(test.args.ctx, test.args.cfg, test.args.f) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamSearch(t *testing.T) { + type args struct { + stream vald.Vald_StreamSearchServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamSearch(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamSearchByID(t *testing.T) { + type args struct { + stream vald.Vald_StreamSearchByIDServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamSearchByID(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Insert(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantCe *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCe *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCe, w.wantCe) { + return errors.Errorf("got = %v, want %v", gotCe, w.wantCe) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotCe, err := s.Insert(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, gotCe, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamInsert(t *testing.T) { + type args struct { + stream vald.Vald_StreamInsertServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamInsert(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiInsert(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiInsert(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Update(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.Update(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamUpdate(t *testing.T) { + type args struct { + stream vald.Vald_StreamUpdateServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamUpdate(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiUpdate(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiUpdate(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Upsert(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.Upsert(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamUpsert(t *testing.T) { + type args struct { + stream vald.Vald_StreamUpsertServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamUpsert(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiUpsert(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.MultiUpsert(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Remove(t *testing.T) { + type args struct { + ctx context.Context + id *payload.Object_ID + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.Remove(test.args.ctx, test.args.id) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamRemove(t *testing.T) { + type args struct { + stream vald.Vald_StreamRemoveServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamRemove(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiRemove(t *testing.T) { + type args struct { + ctx context.Context + ids *payload.Object_IDs + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + ids: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + ids: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiRemove(test.args.ctx, test.args.ids) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_GetObject(t *testing.T) { + type args struct { + ctx context.Context + id *payload.Object_ID + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantVec *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotVec *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotVec, w.wantVec) { + return errors.Errorf("got = %v, want %v", gotVec, w.wantVec) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotVec, err := s.GetObject(test.args.ctx, test.args.id) + if err := test.checkFunc(test.want, gotVec, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamGetObject(t *testing.T) { + type args struct { + stream vald.Vald_StreamGetObjectServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamGetObject(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/backup/handler/grpc/option_test.go b/pkg/gateway/backup/handler/grpc/option_test.go new file mode 100644 index 00000000000..77c90a29e2a --- /dev/null +++ b/pkg/gateway/backup/handler/grpc/option_test.go @@ -0,0 +1,938 @@ +// +// 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 grpc server logic +package grpc + +import ( + "testing" + + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/pkg/gateway/backup/service" + "go.uber.org/goleak" +) + +func TestWithGateway(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + g service.Gateway + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + g: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + g: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithGateway(test.args.g) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithGateway(test.args.g) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMeta(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + m service.Meta + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + m: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + m: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMeta(test.args.m) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMeta(test.args.m) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithBackup(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + b service.Backup + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + b: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + b: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithBackup(test.args.b) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithBackup(test.args.b) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithFilters(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + filter service.Filter + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + filter: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + filter: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithFilters(test.args.filter) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithFilters(test.args.filter) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithErrGroup(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + eg errgroup.Group + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithErrGroup(test.args.eg) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithErrGroup(test.args.eg) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithTimeout(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + dur string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithTimeout(test.args.dur) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithTimeout(test.args.dur) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithReplicationCount(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + rep int + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + rep: 0, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + rep: 0, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithReplicationCount(test.args.rep) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithReplicationCount(test.args.rep) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithStreamConcurrency(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + c int + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + c: 0, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + c: 0, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithStreamConcurrency(test.args.c) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithStreamConcurrency(test.args.c) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/backup/handler/rest/handler_test.go b/pkg/gateway/backup/handler/rest/handler_test.go new file mode 100644 index 00000000000..b0a7e7cebb5 --- /dev/null +++ b/pkg/gateway/backup/handler/rest/handler_test.go @@ -0,0 +1,1099 @@ +// +// 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 rest provides rest api logic +package rest + +import ( + "net/http" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want Handler + } + type test struct { + name string + args args + want want + checkFunc func(want, Handler) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got Handler) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Index(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + want int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + got, err := h.Index(test.args.w, test.args.r) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Search(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Search(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_SearchByID(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.SearchByID(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Insert(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Insert(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiInsert(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiInsert(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Update(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Update(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiUpdate(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiUpdate(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Remove(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Remove(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiRemove(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiRemove(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_GetObject(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.GetObject(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Exists(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Exists(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/backup/handler/rest/option_test.go b/pkg/gateway/backup/handler/rest/option_test.go new file mode 100644 index 00000000000..d45859d8dbd --- /dev/null +++ b/pkg/gateway/backup/handler/rest/option_test.go @@ -0,0 +1,139 @@ +// +// 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 rest provides rest api logic +package rest + +import ( + "testing" + + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "go.uber.org/goleak" +) + +func TestWithVald(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + v vald.ValdServer + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + v: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + v: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithVald(test.args.v) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithVald(test.args.v) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/backup/router/option_test.go b/pkg/gateway/backup/router/option_test.go new file mode 100644 index 00000000000..e22643e1ae9 --- /dev/null +++ b/pkg/gateway/backup/router/option_test.go @@ -0,0 +1,253 @@ +// +// 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 router provides implementation of Go API for routing http Handler wrapped by rest.Func +package router + +import ( + "testing" + + "github.com/vdaas/vald/pkg/gateway/backup/handler/rest" + "go.uber.org/goleak" +) + +func TestWithHandler(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + h rest.Handler + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + h: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + h: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithHandler(test.args.h) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithHandler(test.args.h) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithTimeout(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + timeout string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + timeout: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + timeout: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithTimeout(test.args.timeout) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithTimeout(test.args.timeout) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/backup/router/router_test.go b/pkg/gateway/backup/router/router_test.go new file mode 100644 index 00000000000..62ea7131477 --- /dev/null +++ b/pkg/gateway/backup/router/router_test.go @@ -0,0 +1,97 @@ +// +// 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 router provides implementation of Go API for routing http Handler wrapped by rest.Func +package router + +import ( + "net/http" + "reflect" + "testing" + + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want http.Handler + } + type test struct { + name string + args args + want want + checkFunc func(want, http.Handler) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got http.Handler) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/backup/service/backup_test.go b/pkg/gateway/backup/service/backup_test.go new file mode 100644 index 00000000000..9b46e1cfa57 --- /dev/null +++ b/pkg/gateway/backup/service/backup_test.go @@ -0,0 +1,749 @@ +// +// 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 service + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/payload" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestNewBackup(t *testing.T) { + type args struct { + opts []BackupOption + } + type want struct { + wantBu Backup + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Backup, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotBu Backup, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotBu, w.wantBu) { + return errors.Errorf("got = %v, want %v", gotBu, w.wantBu) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 + } + + gotBu, err := NewBackup(test.args.opts...) + if err := test.checkFunc(test.want, gotBu, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + got, err := b.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_GetObject(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + wantVec *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotVec *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotVec, w.wantVec) { + return errors.Errorf("got = %v, want %v", gotVec, w.wantVec) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + gotVec, err := b.GetObject(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotVec, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_GetLocation(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + wantIpList []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotIpList []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotIpList, w.wantIpList) { + return errors.Errorf("got = %v, want %v", gotIpList, w.wantIpList) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + gotIpList, err := b.GetLocation(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotIpList, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_Register(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Locations + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.Register(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_RegisterMultiple(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Locationss + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.RegisterMultiple(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_Remove(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.Remove(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_RemoveMultiple(t *testing.T) { + type args struct { + ctx context.Context + uuids []string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.RemoveMultiple(test.args.ctx, test.args.uuids...) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/backup/service/option_test.go b/pkg/gateway/backup/service/option_test.go new file mode 100644 index 00000000000..27be1d2b098 --- /dev/null +++ b/pkg/gateway/backup/service/option_test.go @@ -0,0 +1,253 @@ +// +// 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 service +package service + +import ( + "testing" + + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestWithBackupAddr(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + addr string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithBackupAddr(test.args.addr) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithBackupAddr(test.args.addr) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithBackupClient(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + client grpc.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithBackupClient(test.args.client) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithBackupClient(test.args.client) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/backup/usecase/vald_test.go b/pkg/gateway/backup/usecase/vald_test.go new file mode 100644 index 00000000000..f9d2b2ea9ee --- /dev/null +++ b/pkg/gateway/backup/usecase/vald_test.go @@ -0,0 +1,611 @@ +// +// 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 usecase + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/observability" + "github.com/vdaas/vald/internal/runner" + "github.com/vdaas/vald/internal/servers/starter" + "github.com/vdaas/vald/pkg/gateway/backup/config" + "github.com/vdaas/vald/pkg/gateway/backup/service" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + cfg *config.Data + } + type want struct { + wantR runner.Runner + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, runner.Runner, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotR runner.Runner, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotR, w.wantR) { + return errors.Errorf("got = %v, want %v", gotR, w.wantR) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + cfg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + cfg: 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 + } + + gotR, err := New(test.args.cfg) + if err := test.checkFunc(test.want, gotR, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PreStart(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + backup: test.fields.backup, + } + + err := r.PreStart(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + backup service.Backup + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + backup: test.fields.backup, + } + + got, err := r.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PreStop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + backup: test.fields.backup, + } + + err := r.PreStop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_Stop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + backup: test.fields.backup, + } + + err := r.Stop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PostStop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + backup: test.fields.backup, + } + + err := r.PostStop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/filter/config/config_test.go b/pkg/gateway/filter/config/config_test.go new file mode 100644 index 00000000000..d9ccf63cfe9 --- /dev/null +++ b/pkg/gateway/filter/config/config_test.go @@ -0,0 +1,100 @@ +// +// 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 setting stores all server application settings +package config + +import ( + "reflect" + "testing" + + "go.uber.org/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(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCfg *Data, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCfg, w.wantCfg) { + return errors.Errorf("got = %v, want %v", gotCfg, w.wantCfg) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + path: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + path: "", + }, + 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 + } + + gotCfg, err := NewConfig(test.args.path) + if err := test.checkFunc(test.want, gotCfg, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/filter/handler/grpc/checklist_test.go b/pkg/gateway/filter/handler/grpc/checklist_test.go new file mode 100644 index 00000000000..0fb9c171933 --- /dev/null +++ b/pkg/gateway/filter/handler/grpc/checklist_test.go @@ -0,0 +1,608 @@ +// +// 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 + +import ( + "reflect" + "sync" + "sync/atomic" + "testing" + "unsafe" + + "go.uber.org/goleak" +) + +func Test_checkList_Exists(t *testing.T) { + type args struct { + key string + } + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + want bool + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got bool) 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 { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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 + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + got := m.Exists(test.args.key) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_checkList_Check(t *testing.T) { + type args struct { + key string + } + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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 + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.Check(test.args.key) + if err := test.checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_entryCheckList_tryStore(t *testing.T) { + type args struct { + i *struct{} + } + type fields struct { + p unsafe.Pointer + } + type want struct { + want bool + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got bool) 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 { + i: struct{}{}, + }, + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + i: struct{}{}, + }, + fields: fields { + p: 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 + } + e := &entryCheckList{ + p: test.fields.p, + } + + got := e.tryStore(test.args.i) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_entryCheckList_unexpungeLocked(t *testing.T) { + type fields struct { + p unsafe.Pointer + } + type want struct { + wantWasExpunged bool + } + type test struct { + name string + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want, gotWasExpunged bool) error { + if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { + return errors.Errorf("got = %v, want %v", gotWasExpunged, w.wantWasExpunged) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + p: 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + e := &entryCheckList{ + p: test.fields.p, + } + + gotWasExpunged := e.unexpungeLocked() + if err := test.checkFunc(test.want, gotWasExpunged); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_checkList_missLocked(t *testing.T) { + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + } + type test struct { + name string + fields fields + want want + checkFunc func(want) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.missLocked() + if err := test.checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_checkList_dirtyLocked(t *testing.T) { + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + } + type test struct { + name string + fields fields + want want + checkFunc func(want) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.dirtyLocked() + if err := test.checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_entryCheckList_tryExpungeLocked(t *testing.T) { + type fields struct { + p unsafe.Pointer + } + type want struct { + wantIsExpunged bool + } + type test struct { + name string + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want, gotIsExpunged bool) error { + if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { + return errors.Errorf("got = %v, want %v", gotIsExpunged, w.wantIsExpunged) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + p: 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + e := &entryCheckList{ + p: test.fields.p, + } + + gotIsExpunged := e.tryExpungeLocked() + if err := test.checkFunc(test.want, gotIsExpunged); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/filter/handler/grpc/handler_test.go b/pkg/gateway/filter/handler/grpc/handler_test.go new file mode 100644 index 00000000000..62e2cb29c5e --- /dev/null +++ b/pkg/gateway/filter/handler/grpc/handler_test.go @@ -0,0 +1,2439 @@ +// +// 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 grpc server logic +package grpc + +import ( + "context" + "reflect" + "testing" + "time" + + agent "github.com/vdaas/vald/apis/grpc/agent/core" + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "github.com/vdaas/vald/apis/grpc/payload" + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "github.com/vdaas/vald/pkg/gateway/filter/service" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want vald.ValdServer + } + type test struct { + name string + args args + want want + checkFunc func(want, vald.ValdServer) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got vald.ValdServer) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Exists(t *testing.T) { + type args struct { + ctx context.Context + meta *payload.Object_ID + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_ID + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_ID, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_ID, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + meta: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.Exists(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Search(t *testing.T) { + type args struct { + ctx context.Context + req *payload.Search_Request + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.Search(test.args.ctx, test.args.req) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_SearchByID(t *testing.T) { + type args struct { + ctx context.Context + req *payload.Search_IDRequest + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.SearchByID(test.args.ctx, test.args.req) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_search(t *testing.T) { + type args struct { + ctx context.Context + cfg *payload.Search_Config + f func(ctx context.Context, ac agent.AgentClient, copts ...grpc.CallOption) (*payload.Search_Response, error) + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + cfg: nil, + f: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + cfg: nil, + f: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.search(test.args.ctx, test.args.cfg, test.args.f) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamSearch(t *testing.T) { + type args struct { + stream vald.Vald_StreamSearchServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamSearch(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamSearchByID(t *testing.T) { + type args struct { + stream vald.Vald_StreamSearchByIDServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamSearchByID(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Insert(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantCe *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCe *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCe, w.wantCe) { + return errors.Errorf("got = %v, want %v", gotCe, w.wantCe) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotCe, err := s.Insert(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, gotCe, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamInsert(t *testing.T) { + type args struct { + stream vald.Vald_StreamInsertServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamInsert(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiInsert(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiInsert(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Update(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.Update(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamUpdate(t *testing.T) { + type args struct { + stream vald.Vald_StreamUpdateServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamUpdate(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiUpdate(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiUpdate(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Upsert(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.Upsert(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamUpsert(t *testing.T) { + type args struct { + stream vald.Vald_StreamUpsertServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamUpsert(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiUpsert(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.MultiUpsert(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Remove(t *testing.T) { + type args struct { + ctx context.Context + id *payload.Object_ID + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.Remove(test.args.ctx, test.args.id) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamRemove(t *testing.T) { + type args struct { + stream vald.Vald_StreamRemoveServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamRemove(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiRemove(t *testing.T) { + type args struct { + ctx context.Context + ids *payload.Object_IDs + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + ids: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + ids: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiRemove(test.args.ctx, test.args.ids) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_GetObject(t *testing.T) { + type args struct { + ctx context.Context + id *payload.Object_ID + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantVec *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotVec *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotVec, w.wantVec) { + return errors.Errorf("got = %v, want %v", gotVec, w.wantVec) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotVec, err := s.GetObject(test.args.ctx, test.args.id) + if err := test.checkFunc(test.want, gotVec, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamGetObject(t *testing.T) { + type args struct { + stream vald.Vald_StreamGetObjectServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamGetObject(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/filter/handler/grpc/option_test.go b/pkg/gateway/filter/handler/grpc/option_test.go new file mode 100644 index 00000000000..cfc0cb5e857 --- /dev/null +++ b/pkg/gateway/filter/handler/grpc/option_test.go @@ -0,0 +1,938 @@ +// +// 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 grpc server logic +package grpc + +import ( + "testing" + + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/pkg/gateway/filter/service" + "go.uber.org/goleak" +) + +func TestWithGateway(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + g service.Gateway + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + g: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + g: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithGateway(test.args.g) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithGateway(test.args.g) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMeta(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + m service.Meta + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + m: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + m: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMeta(test.args.m) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMeta(test.args.m) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithBackup(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + b service.Backup + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + b: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + b: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithBackup(test.args.b) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithBackup(test.args.b) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithFilters(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + filter service.Filter + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + filter: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + filter: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithFilters(test.args.filter) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithFilters(test.args.filter) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithErrGroup(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + eg errgroup.Group + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithErrGroup(test.args.eg) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithErrGroup(test.args.eg) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithTimeout(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + dur string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithTimeout(test.args.dur) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithTimeout(test.args.dur) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithReplicationCount(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + rep int + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + rep: 0, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + rep: 0, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithReplicationCount(test.args.rep) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithReplicationCount(test.args.rep) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithStreamConcurrency(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + c int + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + c: 0, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + c: 0, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithStreamConcurrency(test.args.c) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithStreamConcurrency(test.args.c) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/filter/handler/rest/handler_test.go b/pkg/gateway/filter/handler/rest/handler_test.go new file mode 100644 index 00000000000..b0a7e7cebb5 --- /dev/null +++ b/pkg/gateway/filter/handler/rest/handler_test.go @@ -0,0 +1,1099 @@ +// +// 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 rest provides rest api logic +package rest + +import ( + "net/http" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want Handler + } + type test struct { + name string + args args + want want + checkFunc func(want, Handler) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got Handler) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Index(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + want int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + got, err := h.Index(test.args.w, test.args.r) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Search(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Search(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_SearchByID(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.SearchByID(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Insert(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Insert(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiInsert(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiInsert(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Update(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Update(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiUpdate(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiUpdate(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Remove(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Remove(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiRemove(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiRemove(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_GetObject(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.GetObject(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Exists(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Exists(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/filter/handler/rest/option_test.go b/pkg/gateway/filter/handler/rest/option_test.go new file mode 100644 index 00000000000..d45859d8dbd --- /dev/null +++ b/pkg/gateway/filter/handler/rest/option_test.go @@ -0,0 +1,139 @@ +// +// 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 rest provides rest api logic +package rest + +import ( + "testing" + + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "go.uber.org/goleak" +) + +func TestWithVald(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + v vald.ValdServer + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + v: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + v: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithVald(test.args.v) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithVald(test.args.v) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/filter/router/option_test.go b/pkg/gateway/filter/router/option_test.go new file mode 100644 index 00000000000..659ba14d983 --- /dev/null +++ b/pkg/gateway/filter/router/option_test.go @@ -0,0 +1,253 @@ +// +// 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 router provides implementation of Go API for routing http Handler wrapped by rest.Func +package router + +import ( + "testing" + + "github.com/vdaas/vald/pkg/gateway/filter/handler/rest" + "go.uber.org/goleak" +) + +func TestWithHandler(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + h rest.Handler + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + h: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + h: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithHandler(test.args.h) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithHandler(test.args.h) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithTimeout(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + timeout string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + timeout: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + timeout: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithTimeout(test.args.timeout) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithTimeout(test.args.timeout) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/filter/router/router_test.go b/pkg/gateway/filter/router/router_test.go new file mode 100644 index 00000000000..62ea7131477 --- /dev/null +++ b/pkg/gateway/filter/router/router_test.go @@ -0,0 +1,97 @@ +// +// 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 router provides implementation of Go API for routing http Handler wrapped by rest.Func +package router + +import ( + "net/http" + "reflect" + "testing" + + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want http.Handler + } + type test struct { + name string + args args + want want + checkFunc func(want, http.Handler) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got http.Handler) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/filter/service/backup_option_test.go b/pkg/gateway/filter/service/backup_option_test.go new file mode 100644 index 00000000000..27be1d2b098 --- /dev/null +++ b/pkg/gateway/filter/service/backup_option_test.go @@ -0,0 +1,253 @@ +// +// 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 service +package service + +import ( + "testing" + + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestWithBackupAddr(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + addr string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithBackupAddr(test.args.addr) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithBackupAddr(test.args.addr) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithBackupClient(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + client grpc.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithBackupClient(test.args.client) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithBackupClient(test.args.client) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/filter/service/backup_test.go b/pkg/gateway/filter/service/backup_test.go new file mode 100644 index 00000000000..9b46e1cfa57 --- /dev/null +++ b/pkg/gateway/filter/service/backup_test.go @@ -0,0 +1,749 @@ +// +// 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 service + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/payload" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestNewBackup(t *testing.T) { + type args struct { + opts []BackupOption + } + type want struct { + wantBu Backup + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Backup, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotBu Backup, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotBu, w.wantBu) { + return errors.Errorf("got = %v, want %v", gotBu, w.wantBu) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 + } + + gotBu, err := NewBackup(test.args.opts...) + if err := test.checkFunc(test.want, gotBu, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + got, err := b.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_GetObject(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + wantVec *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotVec *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotVec, w.wantVec) { + return errors.Errorf("got = %v, want %v", gotVec, w.wantVec) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + gotVec, err := b.GetObject(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotVec, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_GetLocation(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + wantIpList []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotIpList []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotIpList, w.wantIpList) { + return errors.Errorf("got = %v, want %v", gotIpList, w.wantIpList) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + gotIpList, err := b.GetLocation(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotIpList, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_Register(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Locations + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.Register(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_RegisterMultiple(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Locationss + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.RegisterMultiple(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_Remove(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.Remove(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_RemoveMultiple(t *testing.T) { + type args struct { + ctx context.Context + uuids []string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.RemoveMultiple(test.args.ctx, test.args.uuids...) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/filter/service/filter_option_test.go b/pkg/gateway/filter/service/filter_option_test.go new file mode 100644 index 00000000000..7d941b6e8ce --- /dev/null +++ b/pkg/gateway/filter/service/filter_option_test.go @@ -0,0 +1,139 @@ +// +// 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 service +package service + +import ( + "testing" + + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestWithFilterClient(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + client grpc.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithFilterClient(test.args.client) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithFilterClient(test.args.client) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/filter/service/filter_test.go b/pkg/gateway/filter/service/filter_test.go new file mode 100644 index 00000000000..defabd62e3b --- /dev/null +++ b/pkg/gateway/filter/service/filter_test.go @@ -0,0 +1,282 @@ +// +// 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 service + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/payload" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestNewFilter(t *testing.T) { + type args struct { + opts []FilterOption + } + type want struct { + wantEf Filter + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Filter, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotEf Filter, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotEf, w.wantEf) { + return errors.Errorf("got = %v, want %v", gotEf, w.wantEf) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 + } + + gotEf, err := NewFilter(test.args.opts...) + if err := test.checkFunc(test.want, gotEf, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_filter_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + client grpc.Client + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + client: 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 + } + f := &filter{ + client: test.fields.client, + } + + got, err := f.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_filter_FilterSearch(t *testing.T) { + type args struct { + ctx context.Context + res *payload.Search_Response + } + type fields struct { + client grpc.Client + } + type want struct { + want *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + res: nil, + }, + fields: fields { + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + res: nil, + }, + fields: fields { + client: 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 + } + f := &filter{ + client: test.fields.client, + } + + got, err := f.FilterSearch(test.args.ctx, test.args.res) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/filter/service/gateway_option_test.go b/pkg/gateway/filter/service/gateway_option_test.go new file mode 100644 index 00000000000..6ac318982a7 --- /dev/null +++ b/pkg/gateway/filter/service/gateway_option_test.go @@ -0,0 +1,254 @@ +// +// 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 service +package service + +import ( + "testing" + + "github.com/vdaas/vald/internal/client/discoverer" + "github.com/vdaas/vald/internal/errgroup" + "go.uber.org/goleak" +) + +func TestWithDiscoverer(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + c discoverer.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + c: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + c: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithDiscoverer(test.args.c) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithDiscoverer(test.args.c) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithErrGroup(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + eg errgroup.Group + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithErrGroup(test.args.eg) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithErrGroup(test.args.eg) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/filter/service/gateway_test.go b/pkg/gateway/filter/service/gateway_test.go new file mode 100644 index 00000000000..54f3db58af2 --- /dev/null +++ b/pkg/gateway/filter/service/gateway_test.go @@ -0,0 +1,562 @@ +// +// 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 service +package service + +import ( + "context" + "reflect" + "testing" + + agent "github.com/vdaas/vald/apis/grpc/agent/core" + "github.com/vdaas/vald/internal/client/discoverer" + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestNewGateway(t *testing.T) { + type args struct { + opts []GWOption + } + type want struct { + wantGw Gateway + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Gateway, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotGw Gateway, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotGw, w.wantGw) { + return errors.Errorf("got = %v, want %v", gotGw, w.wantGw) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 + } + + gotGw, err := NewGateway(test.args.opts...) + if err := test.checkFunc(test.want, gotGw, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + got, err := g.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_BroadCast(t *testing.T) { + type args struct { + ctx context.Context + f func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + f: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + f: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + err := g.BroadCast(test.args.ctx, test.args.f) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_Do(t *testing.T) { + type args struct { + ctx context.Context + f func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + f: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + f: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + err := g.Do(test.args.ctx, test.args.f) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_DoMulti(t *testing.T) { + type args struct { + ctx context.Context + num int + f func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + num: 0, + f: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + num: 0, + f: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + err := g.DoMulti(test.args.ctx, test.args.num, test.args.f) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_GetAgentCount(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + want int + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got int) 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 { + ctx: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + got := g.GetAgentCount(test.args.ctx) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/filter/service/meta_option_test.go b/pkg/gateway/filter/service/meta_option_test.go new file mode 100644 index 00000000000..9c022ce4983 --- /dev/null +++ b/pkg/gateway/filter/service/meta_option_test.go @@ -0,0 +1,827 @@ +// +// 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 service +package service + +import ( + "testing" + + "github.com/vdaas/vald/internal/cache" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestWithMetaAddr(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + addr string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaAddr(test.args.addr) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaAddr(test.args.addr) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaHostPort(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + host string + port int + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + host: "", + port: 0, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + host: "", + port: 0, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaHostPort(test.args.host, test.args.port) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaHostPort(test.args.host, test.args.port) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaClient(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + client grpc.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaClient(test.args.client) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaClient(test.args.client) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCacheEnabled(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + flg bool + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + flg: false, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + flg: false, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCacheEnabled(test.args.flg) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCacheEnabled(test.args.flg) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCache(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + c cache.Cache + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + c: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + c: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCache(test.args.c) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCache(test.args.c) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCacheExpireDuration(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + dur string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCacheExpireDuration(test.args.dur) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCacheExpireDuration(test.args.dur) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCacheExpiredCheckDuration(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + dur string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCacheExpiredCheckDuration(test.args.dur) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCacheExpiredCheckDuration(test.args.dur) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/filter/service/meta_test.go b/pkg/gateway/filter/service/meta_test.go new file mode 100644 index 00000000000..2f6c63542ed --- /dev/null +++ b/pkg/gateway/filter/service/meta_test.go @@ -0,0 +1,1428 @@ +// +// 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 service provides meta service +package service + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/internal/cache" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestNewMeta(t *testing.T) { + type args struct { + opts []MetaOption + } + type want struct { + wantMi Meta + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Meta, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotMi Meta, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotMi, w.wantMi) { + return errors.Errorf("got = %v, want %v", gotMi, w.wantMi) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 + } + + gotMi, err := NewMeta(test.args.opts...) + if err := test.checkFunc(test.want, gotMi, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_Exists(t *testing.T) { + type args struct { + ctx context.Context + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want bool + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, bool, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got bool, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.Exists(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetMeta(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + wantV string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotV string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotV, w.wantV) { + return errors.Errorf("got = %v, want %v", gotV, w.wantV) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + gotV, err := m.GetMeta(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotV, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetMetas(t *testing.T) { + type args struct { + ctx context.Context + uuids []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.GetMetas(test.args.ctx, test.args.uuids...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetUUID(t *testing.T) { + type args struct { + ctx context.Context + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + wantK string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotK string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotK, w.wantK) { + return errors.Errorf("got = %v, want %v", gotK, w.wantK) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + gotK, err := m.GetUUID(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, gotK, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetUUIDs(t *testing.T) { + type args struct { + ctx context.Context + metas []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.GetUUIDs(test.args.ctx, test.args.metas...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_SetUUIDandMeta(t *testing.T) { + type args struct { + ctx context.Context + uuid string + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + err := m.SetUUIDandMeta(test.args.ctx, test.args.uuid, test.args.meta) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_SetUUIDandMetas(t *testing.T) { + type args struct { + ctx context.Context + kvs map[string]string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + kvs: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + kvs: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + err := m.SetUUIDandMetas(test.args.ctx, test.args.kvs) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteMeta(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + wantV string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotV string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotV, w.wantV) { + return errors.Errorf("got = %v, want %v", gotV, w.wantV) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + gotV, err := m.DeleteMeta(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotV, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteMetas(t *testing.T) { + type args struct { + ctx context.Context + uuids []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.DeleteMetas(test.args.ctx, test.args.uuids...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteUUID(t *testing.T) { + type args struct { + ctx context.Context + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.DeleteUUID(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteUUIDs(t *testing.T) { + type args struct { + ctx context.Context + metas []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.DeleteUUIDs(test.args.ctx, test.args.metas...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/filter/usecase/vald_test.go b/pkg/gateway/filter/usecase/vald_test.go new file mode 100644 index 00000000000..e5cd240c375 --- /dev/null +++ b/pkg/gateway/filter/usecase/vald_test.go @@ -0,0 +1,671 @@ +// +// 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 usecase + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/observability" + "github.com/vdaas/vald/internal/runner" + "github.com/vdaas/vald/internal/servers/starter" + "github.com/vdaas/vald/pkg/gateway/filter/config" + "github.com/vdaas/vald/pkg/gateway/filter/service" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + cfg *config.Data + } + type want struct { + wantR runner.Runner + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, runner.Runner, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotR runner.Runner, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotR, w.wantR) { + return errors.Errorf("got = %v, want %v", gotR, w.wantR) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + cfg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + cfg: 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 + } + + gotR, err := New(test.args.cfg) + if err := test.checkFunc(test.want, gotR, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PreStart(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + err := r.PreStart(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + got, err := r.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PreStop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + err := r.PreStop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_Stop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + err := r.Stop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PostStop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + err := r.PostStop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/lb/config/config_test.go b/pkg/gateway/lb/config/config_test.go new file mode 100644 index 00000000000..d9ccf63cfe9 --- /dev/null +++ b/pkg/gateway/lb/config/config_test.go @@ -0,0 +1,100 @@ +// +// 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 setting stores all server application settings +package config + +import ( + "reflect" + "testing" + + "go.uber.org/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(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCfg *Data, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCfg, w.wantCfg) { + return errors.Errorf("got = %v, want %v", gotCfg, w.wantCfg) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + path: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + path: "", + }, + 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 + } + + gotCfg, err := NewConfig(test.args.path) + if err := test.checkFunc(test.want, gotCfg, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/lb/handler/grpc/checklist_test.go b/pkg/gateway/lb/handler/grpc/checklist_test.go new file mode 100644 index 00000000000..0fb9c171933 --- /dev/null +++ b/pkg/gateway/lb/handler/grpc/checklist_test.go @@ -0,0 +1,608 @@ +// +// 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 + +import ( + "reflect" + "sync" + "sync/atomic" + "testing" + "unsafe" + + "go.uber.org/goleak" +) + +func Test_checkList_Exists(t *testing.T) { + type args struct { + key string + } + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + want bool + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got bool) 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 { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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 + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + got := m.Exists(test.args.key) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_checkList_Check(t *testing.T) { + type args struct { + key string + } + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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 + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.Check(test.args.key) + if err := test.checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_entryCheckList_tryStore(t *testing.T) { + type args struct { + i *struct{} + } + type fields struct { + p unsafe.Pointer + } + type want struct { + want bool + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got bool) 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 { + i: struct{}{}, + }, + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + i: struct{}{}, + }, + fields: fields { + p: 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 + } + e := &entryCheckList{ + p: test.fields.p, + } + + got := e.tryStore(test.args.i) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_entryCheckList_unexpungeLocked(t *testing.T) { + type fields struct { + p unsafe.Pointer + } + type want struct { + wantWasExpunged bool + } + type test struct { + name string + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want, gotWasExpunged bool) error { + if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { + return errors.Errorf("got = %v, want %v", gotWasExpunged, w.wantWasExpunged) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + p: 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + e := &entryCheckList{ + p: test.fields.p, + } + + gotWasExpunged := e.unexpungeLocked() + if err := test.checkFunc(test.want, gotWasExpunged); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_checkList_missLocked(t *testing.T) { + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + } + type test struct { + name string + fields fields + want want + checkFunc func(want) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.missLocked() + if err := test.checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_checkList_dirtyLocked(t *testing.T) { + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + } + type test struct { + name string + fields fields + want want + checkFunc func(want) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.dirtyLocked() + if err := test.checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_entryCheckList_tryExpungeLocked(t *testing.T) { + type fields struct { + p unsafe.Pointer + } + type want struct { + wantIsExpunged bool + } + type test struct { + name string + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want, gotIsExpunged bool) error { + if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { + return errors.Errorf("got = %v, want %v", gotIsExpunged, w.wantIsExpunged) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + p: 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + e := &entryCheckList{ + p: test.fields.p, + } + + gotIsExpunged := e.tryExpungeLocked() + if err := test.checkFunc(test.want, gotIsExpunged); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/lb/handler/grpc/handler.go b/pkg/gateway/lb/handler/grpc/handler.go index 9a7f65ee64a..156e8ddf06b 100644 --- a/pkg/gateway/lb/handler/grpc/handler.go +++ b/pkg/gateway/lb/handler/grpc/handler.go @@ -27,7 +27,6 @@ import ( "time" "github.com/kpango/fuid" - agent "github.com/vdaas/vald/apis/grpc/agent/core" "github.com/vdaas/vald/apis/grpc/gateway/vald" "github.com/vdaas/vald/apis/grpc/payload" "github.com/vdaas/vald/internal/errgroup" @@ -44,10 +43,7 @@ import ( type server struct { eg errgroup.Group gateway service.Gateway - metadata service.Meta - backup service.Backup timeout time.Duration - filter service.Filter replica int streamConcurrency int } @@ -61,71 +57,90 @@ func New(opts ...Option) vald.ValdServer { return s } -func (s *server) Exists(ctx context.Context, meta *payload.Object_ID) (*payload.Object_ID, error) { - ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.Exists") +func (s *server) Exists(ctx context.Context, meta *payload.Object_ID) (id *payload.Object_ID, err error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-lb.Exists") defer func() { if span != nil { span.End() } }() - uuid, err := s.metadata.GetUUID(ctx, meta.GetId()) - if err != nil { + var cancel context.CancelFunc + ctx, cancel = context.WithCancel(ctx) + var once sync.Once + err = s.gateway.BroadCast(ctx, func(ctx context.Context, tgt string, vc vald.ValdClient, copts ...grpc.CallOption) error { + oid, err := vc.Exists(ctx, meta, copts...) + if err != nil { + return nil + } + if oid != nil && oid.Id != "" { + once.Do(func() { + id = new(payload.Object_ID) + id.Id = oid.Id + cancel() + }) + } + return nil + }) + if err != nil || id == nil || id.Id == "" { if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } return nil, status.WrapWithNotFound(fmt.Sprintf("Exists API meta %s's uuid not found", meta.GetId()), err, meta.GetId(), info.Get()) } - return &payload.Object_ID{ - Id: uuid, - }, nil + return id, nil } func (s *server) Search(ctx context.Context, req *payload.Search_Request) (res *payload.Search_Response, err error) { - ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.Search") + ctx, span := trace.StartSpan(ctx, "vald/gateway-lb.Search") defer func() { if span != nil { span.End() } }() + if len(req.Vector) < 2 { + err = errors.ErrInvalidDimensionSize(len(req.Vector), 0) + if span != nil { + span.SetStatus(trace.StatusCodeInvalidArgument(err.Error())) + } + return nil, status.WrapWithInvalidArgument("Search API invalid vector argument", err, req, info.Get()) + } return s.search(ctx, req.GetConfig(), - func(ctx context.Context, ac agent.AgentClient, copts ...grpc.CallOption) (*payload.Search_Response, error) { - return ac.Search(ctx, req, copts...) + func(ctx context.Context, vc vald.ValdClient, copts ...grpc.CallOption) (*payload.Search_Response, error) { + return vc.Search(ctx, req, copts...) }) } func (s *server) SearchByID(ctx context.Context, req *payload.Search_IDRequest) ( res *payload.Search_Response, err error) { - ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.SearchByID") + ctx, span := trace.StartSpan(ctx, "vald/gateway-lb.SearchByID") defer func() { if span != nil { span.End() } }() - metaID := req.GetId() - req.Id, err = s.metadata.GetUUID(ctx, metaID) - if err != nil { - req.Id = metaID - log.Errorf("error at SearchByID\t%v", err) + if len(req.GetId()) == 0 { + err = errors.ErrInvalidMetaDataConfig if span != nil { - span.SetStatus(trace.StatusCodeNotFound(err.Error())) + span.SetStatus(trace.StatusCodeInvalidArgument(err.Error())) } - return nil, status.WrapWithNotFound(fmt.Sprintf("SearchByID API meta %s's uuid not found", metaID), err, req, info.Get()) + return nil, status.WrapWithInvalidArgument("SearchByID API invalid uuid", err, req, info.Get()) } return s.search(ctx, req.GetConfig(), - func(ctx context.Context, ac agent.AgentClient, copts ...grpc.CallOption) (*payload.Search_Response, error) { - return ac.SearchByID(ctx, req, copts...) + func(ctx context.Context, vc vald.ValdClient, copts ...grpc.CallOption) (*payload.Search_Response, error) { + return vc.SearchByID(ctx, req, copts...) }) } func (s *server) search(ctx context.Context, cfg *payload.Search_Config, - f func(ctx context.Context, ac agent.AgentClient, copts ...grpc.CallOption) (*payload.Search_Response, error)) ( + f func(ctx context.Context, vc vald.ValdClient, copts ...grpc.CallOption) (*payload.Search_Response, error)) ( res *payload.Search_Response, err error) { - ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.search") + ctx, span := trace.StartSpan(ctx, "vald/gateway-lb.search") defer func() { if span != nil { span.End() } }() + maxDist := uint32(math.MaxUint32) num := int(cfg.GetNum()) res = new(payload.Search_Response) @@ -146,8 +161,8 @@ func (s *server) search(ctx context.Context, cfg *payload.Search_Config, // cl := new(checkList) visited := make(map[string]bool, len(res.Results)) mu := sync.RWMutex{} - return s.gateway.BroadCast(ectx, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error { - r, err := f(ctx, ac, copts...) + return s.gateway.BroadCast(ectx, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error { + r, err := f(ctx, vc, copts...) if err != nil { log.Debug(err) return nil @@ -167,10 +182,6 @@ func (s *server) search(ctx context.Context, cfg *payload.Search_Config, } else { mu.RUnlock() } - // if !cl.Exists(id) { - // dch <- dist - // cl.Check(id) - // } } return nil }) @@ -183,36 +194,9 @@ func (s *server) search(ctx context.Context, cfg *payload.Search_Config, log.Error(err) } close(dch) - if len(res.GetResults()) > num && num != 0 { + if num != 0 && len(res.GetResults()) > num { res.Results = res.Results[:num] } - uuids := make([]string, 0, len(res.Results)) - for _, r := range res.Results { - uuids = append(uuids, r.GetId()) - } - if s.metadata != nil { - metas, merr := s.metadata.GetMetas(ctx, uuids...) - if merr != nil { - log.Error(merr) - err = errors.Wrap(err, merr.Error()) - } - for i, k := range metas { - if len(k) != 0 { - res.Results[i].Id = k - } - } - } - if s.filter != nil { - r, ferr := s.filter.FilterSearch(ctx, res) - if ferr == nil { - res = r - } else { - err = errors.Wrap(err, ferr.Error()) - } - } - if err != nil { - return res, status.WrapWithInternal(fmt.Sprintf("failed to search request %#v", cfg), err, info.Get()) - } return res, nil case dist := <-dch: if len(res.GetResults()) >= num && @@ -256,7 +240,7 @@ func (s *server) search(ctx context.Context, cfg *payload.Search_Config, } func (s *server) StreamSearch(stream vald.Vald_StreamSearchServer) error { - ctx, span := trace.StartSpan(stream.Context(), "vald/gateway-vald.StreamSearch") + ctx, span := trace.StartSpan(stream.Context(), "vald/gateway-lb.StreamSearch") defer func() { if span != nil { span.End() @@ -270,7 +254,7 @@ func (s *server) StreamSearch(stream vald.Vald_StreamSearchServer) error { } func (s *server) StreamSearchByID(stream vald.Vald_StreamSearchByIDServer) error { - ctx, span := trace.StartSpan(stream.Context(), "vald/gateway-vald.StreamSearchByID") + ctx, span := trace.StartSpan(stream.Context(), "vald/gateway-lb.StreamSearchByID") defer func() { if span != nil { span.End() @@ -283,45 +267,24 @@ func (s *server) StreamSearchByID(stream vald.Vald_StreamSearchByIDServer) error }) } -func (s *server) Insert(ctx context.Context, vec *payload.Object_Vector) (ce *payload.Object_Locations, err error) { - ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.Insert") +func (s *server) Insert(ctx context.Context, vec *payload.Object_Vector) (ce *payload.Object_Location, err error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-lb.Insert") defer func() { if span != nil { span.End() } }() - meta := vec.GetId() - exists, err := s.metadata.Exists(ctx, meta) - if err != nil { - log.Error(err) - if span != nil { - span.SetStatus(trace.StatusCodeInternal(err.Error())) - } - return nil, status.WrapWithInternal( - fmt.Sprintf("Insert API meta %s couldn't check meta already exists or not", meta), err, info.Get()) - } - if exists { - err = errors.Wrap(err, errors.ErrMetaDataAlreadyExists(meta).Error()) + if len(vec.Vector) < 2 { + err = errors.ErrInvalidDimensionSize(len(vec.Vector), 0) if span != nil { - span.SetStatus(trace.StatusCodeAlreadyExists(err.Error())) + span.SetStatus(trace.StatusCodeInvalidArgument(err.Error())) } - return nil, status.WrapWithAlreadyExists(fmt.Sprintf("Insert API meta %s already exists", meta), err, info.Get()) + return nil, status.WrapWithInvalidArgument("Search API invalid vector argument", err, vec, info.Get()) } - - uuid := fuid.String() - err = s.metadata.SetUUIDandMeta(ctx, uuid, meta) - if err != nil { - log.Error(err) - if span != nil { - span.SetStatus(trace.StatusCodeInternal(err.Error())) - } - return nil, status.WrapWithInternal(fmt.Sprintf("Insert API meta %s & uuid %s couldn't store", meta, uuid), err, info.Get()) - } - vec.Id = uuid mu := new(sync.Mutex) targets := make([]string, 0, s.replica) - err = s.gateway.DoMulti(ctx, s.replica, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) (err error) { - _, err = ac.Insert(ctx, vec, copts...) + err = s.gateway.DoMulti(ctx, s.replica, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) (err error) { + _, err = vc.Insert(ctx, vec, copts...) if err != nil { if err == errors.ErrRPCCallFailed(target, context.Canceled) { return nil @@ -335,38 +298,22 @@ func (s *server) Insert(ctx context.Context, vec *payload.Object_Vector) (ce *pa return nil }) if err != nil { - err = errors.Wrapf(err, "Insert API (do multiple) failed to Insert uuid = %s\tmeta = %s\t info = %#v", uuid, meta, info.Get()) + err = errors.Wrapf(err, "Insert API (do multiple) failed to Insert uuid = %s\t info = %#v", vec.GetId(), info.Get()) log.Error(err) if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) } return nil, status.WrapWithInternal(fmt.Sprintf("Insert API failed to Execute DoMulti error = %s", err.Error()), err, info.Get()) } - if s.backup != nil { - vecs := &payload.Object_Locations{ - Uuid: uuid, - Meta: meta, - Ips: targets, - } - if vec != nil { - vecs.Vector = vec.GetVector() - } - err = s.backup.Register(ctx, vecs) - if err != nil { - err = errors.Wrapf(err, "Insert API (backup.Register) failed to Backup Vectors = %#v\t info = %#v", vecs, info.Get()) - log.Error(err) - if span != nil { - span.SetStatus(trace.StatusCodeInternal(err.Error())) - } - return nil, status.WrapWithInternal(err.Error(), err) - } - } log.Debugf("Insert API insert succeeded to %v", targets) - return new(payload.Object_Locations), nil + return &payload.Object_Location{ + Uuid: vec.GetId(), + Ips: targets, + }, nil } func (s *server) StreamInsert(stream vald.Vald_StreamInsertServer) error { - ctx, span := trace.StartSpan(stream.Context(), "vald/gateway-vald.StreamInsert") + ctx, span := trace.StartSpan(stream.Context(), "vald/gateway-lb.StreamInsert") defer func() { if span != nil { span.End() @@ -380,7 +327,7 @@ func (s *server) StreamInsert(stream vald.Vald_StreamInsertServer) error { } func (s *server) MultiInsert(ctx context.Context, vecs *payload.Object_Vectors) (res *payload.Object_Locations, err error) { - ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.MultiInsert") + ctx, span := trace.StartSpan(ctx, "vald/gateway-lb.MultiInsert") defer func() { if span != nil { span.End() @@ -425,8 +372,8 @@ func (s *server) MultiInsert(ctx context.Context, vecs *payload.Object_Vectors) mu := new(sync.Mutex) targets := make([]string, 0, s.replica) - gerr := s.gateway.DoMulti(ctx, s.replica, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) (err error) { - _, err = ac.MultiInsert(ctx, vecs, copts...) + gerr := s.gateway.DoMulti(ctx, s.replica, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) (err error) { + _, err = vc.MultiInsert(ctx, vecs, copts...) if err != nil { return err } @@ -444,13 +391,12 @@ func (s *server) MultiInsert(ctx context.Context, vecs *payload.Object_Vectors) } if s.backup != nil { - mvecs := new(payload.Object_Locationss) - mvecs.Vectors = make([]*payload.Object_Locations, 0, len(vecs.GetVectors())) + mvecs := new(payload.Backup_MetaVectors) + mvecs.Vectors = make([]*payload.Backup_MetaVector, 0, len(vecs.GetVectors())) for _, vec := range vecs.GetVectors() { uuid := vec.GetId() - mvecs.Vectors = append(mvecs.Vectors, &payload.Object_Locations{ + mvecs.Vectors = append(mvecs.Vectors, &payload.Backup_MetaVector{ Uuid: uuid, - Meta: metaMap[uuid], Vector: vec.GetVector(), Ips: targets, }) @@ -466,8 +412,8 @@ func (s *server) MultiInsert(ctx context.Context, vecs *payload.Object_Vectors) return new(payload.Object_Locations), nil } -func (s *server) Update(ctx context.Context, vec *payload.Object_Vector) (res *payload.Object_Locations, err error) { - ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.Update") +func (s *server) Update(ctx context.Context, vec *payload.Object_Vector) (res *payload.Object_Location, err error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-lb.Update") defer func() { if span != nil { span.End() @@ -493,11 +439,11 @@ func (s *server) Update(ctx context.Context, vec *payload.Object_Vector) (res *p for _, loc := range locs { lmap[loc] = struct{}{} } - err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error { + err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error { target = strings.SplitN(target, ":", 2)[0] _, ok := lmap[target] if ok { - _, err = ac.Update(ctx, vec, copts...) + _, err = vc.Update(ctx, vec, copts...) if err != nil { return err } @@ -510,13 +456,11 @@ func (s *server) Update(ctx context.Context, vec *payload.Object_Vector) (res *p } return nil, status.WrapWithInternal(fmt.Sprintf("Update API failed request %#v", vec), err, info.Get()) } - mvec := &payload.Object_Locations{ + err = s.backup.Register(ctx, &payload.Backup_MetaVector{ Uuid: uuid, - Meta: meta, Vector: vec.GetVector(), Ips: locs, - } - err = s.backup.Register(ctx, mvec) + }) if err != nil { if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) @@ -524,11 +468,11 @@ func (s *server) Update(ctx context.Context, vec *payload.Object_Vector) (res *p return nil, status.WrapWithInternal(fmt.Sprintf("Update API failed backup %#v", vec), err, info.Get()) } - return new(payload.Object_Locations), nil + return new(payload.Object_Location), nil } func (s *server) StreamUpdate(stream vald.Vald_StreamUpdateServer) error { - ctx, span := trace.StartSpan(stream.Context(), "vald/gateway-vald.StreamUpdate") + ctx, span := trace.StartSpan(stream.Context(), "vald/gateway-lb.StreamUpdate") defer func() { if span != nil { span.End() @@ -542,7 +486,7 @@ func (s *server) StreamUpdate(stream vald.Vald_StreamUpdateServer) error { } func (s *server) MultiUpdate(ctx context.Context, vecs *payload.Object_Vectors) (res *payload.Object_Locations, err error) { - ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.MultiUpdate") + ctx, span := trace.StartSpan(ctx, "vald/gateway-lb.MultiUpdate") defer func() { if span != nil { span.End() @@ -571,8 +515,8 @@ func (s *server) MultiUpdate(ctx context.Context, vecs *payload.Object_Vectors) return new(payload.Object_Locations), nil } -func (s *server) Upsert(ctx context.Context, vec *payload.Object_Vector) (*payload.Object_Locations, error) { - ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.Upsert") +func (s *server) Upsert(ctx context.Context, vec *payload.Object_Vector) (*payload.Object_Location, error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-lb.Upsert") defer func() { if span != nil { span.End() @@ -600,11 +544,11 @@ func (s *server) Upsert(ctx context.Context, vec *payload.Object_Vector) (*paylo } } - return new(payload.Object_Locations), errs + return new(payload.Object_Location), errs } func (s *server) StreamUpsert(stream vald.Vald_StreamUpsertServer) error { - ctx, span := trace.StartSpan(stream.Context(), "vald/gateway-vald.StreamUpsert") + ctx, span := trace.StartSpan(stream.Context(), "vald/gateway-lb.StreamUpsert") defer func() { if span != nil { span.End() @@ -618,7 +562,7 @@ func (s *server) StreamUpsert(stream vald.Vald_StreamUpsertServer) error { } func (s *server) MultiUpsert(ctx context.Context, vecs *payload.Object_Vectors) (*payload.Object_Locations, error) { - ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.MultiUpsert") + ctx, span := trace.StartSpan(ctx, "vald/gateway-lb.MultiUpsert") defer func() { if span != nil { span.End() @@ -677,8 +621,8 @@ func (s *server) MultiUpsert(ctx context.Context, vecs *payload.Object_Vectors) return new(payload.Object_Locations), errs } -func (s *server) Remove(ctx context.Context, id *payload.Object_ID) (*payload.Object_Locations, error) { - ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.Remove") +func (s *server) Remove(ctx context.Context, id *payload.Object_ID) (*payload.Object_Location, error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-lb.Remove") defer func() { if span != nil { span.End() @@ -703,10 +647,10 @@ func (s *server) Remove(ctx context.Context, id *payload.Object_ID) (*payload.Ob for _, loc := range locs { lmap[loc] = struct{}{} } - err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error { + err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error { _, ok := lmap[target] if ok { - _, err = ac.Remove(ctx, &payload.Object_ID{ + _, err = vc.Remove(ctx, &payload.Object_ID{ Id: uuid, }, copts...) if err != nil { @@ -735,11 +679,11 @@ func (s *server) Remove(ctx context.Context, id *payload.Object_ID) (*payload.Ob } return nil, status.WrapWithInternal(fmt.Sprintf("Remove API failed to Remove backup uuid = %s", uuid), err, info.Get()) } - return new(payload.Object_Locations), nil + return new(payload.Object_Location), nil } func (s *server) StreamRemove(stream vald.Vald_StreamRemoveServer) error { - ctx, span := trace.StartSpan(stream.Context(), "vald/gateway-vald.StreamRemove") + ctx, span := trace.StartSpan(stream.Context(), "vald/gateway-lb.StreamRemove") defer func() { if span != nil { span.End() @@ -753,7 +697,7 @@ func (s *server) StreamRemove(stream vald.Vald_StreamRemoveServer) error { } func (s *server) MultiRemove(ctx context.Context, ids *payload.Object_IDs) (res *payload.Object_Locations, err error) { - ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.MultiRemove") + ctx, span := trace.StartSpan(ctx, "vald/gateway-lb.MultiRemove") defer func() { if span != nil { span.End() @@ -776,10 +720,10 @@ func (s *server) MultiRemove(ctx context.Context, ids *payload.Object_IDs) (res lmap[loc] = append(lmap[loc], uuid) } } - err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error { + err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error { uuids, ok := lmap[target] if ok { - _, err := ac.MultiRemove(ctx, &payload.Object_IDs{ + _, err := vc.MultiRemove(ctx, &payload.Object_IDs{ Ids: uuids, }, copts...) if err != nil { @@ -811,8 +755,8 @@ func (s *server) MultiRemove(ctx context.Context, ids *payload.Object_IDs) (res return new(payload.Object_Locations), nil } -func (s *server) GetObject(ctx context.Context, id *payload.Object_ID) (vec *payload.Object_Locations, err error) { - ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.GetObject") +func (s *server) GetObject(ctx context.Context, id *payload.Object_ID) (vec *payload.Object_Vector, err error) { + ctx, span := trace.StartSpan(ctx, "vald/gateway-lb.GetObject") defer func() { if span != nil { span.End() @@ -826,18 +770,22 @@ func (s *server) GetObject(ctx context.Context, id *payload.Object_ID) (vec *pay } return nil, status.WrapWithNotFound(fmt.Sprintf("GetObject API meta %s's uuid not found", meta), err, info.Get()) } - vec, err = s.backup.GetObject(ctx, uuid) + mvec, err := s.backup.GetObject(ctx, uuid) if err != nil { if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } return nil, status.WrapWithNotFound(fmt.Sprintf("GetObject API meta %s uuid %s Object not found", meta, uuid), err, info.Get()) } + vec = &payload.Object_Vector{ + Id: mvec.GetUuid(), + Vector: mvec.GetVector(), + } return vec, nil } func (s *server) StreamGetObject(stream vald.Vald_StreamGetObjectServer) error { - ctx, span := trace.StartSpan(stream.Context(), "vald/gateway-vald.StreamGetObject") + ctx, span := trace.StartSpan(stream.Context(), "vald/gateway-lb.StreamGetObject") defer func() { if span != nil { span.End() diff --git a/pkg/gateway/lb/handler/grpc/handler_test.go b/pkg/gateway/lb/handler/grpc/handler_test.go new file mode 100644 index 00000000000..879a4a92480 --- /dev/null +++ b/pkg/gateway/lb/handler/grpc/handler_test.go @@ -0,0 +1,2198 @@ +// +// 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 grpc server logic +package grpc + +import ( + "context" + "reflect" + "testing" + "time" + + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "github.com/vdaas/vald/apis/grpc/payload" + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "github.com/vdaas/vald/pkg/gateway/lb/service" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want vald.ValdServer + } + type test struct { + name string + args args + want want + checkFunc func(want, vald.ValdServer) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got vald.ValdServer) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Exists(t *testing.T) { + type args struct { + ctx context.Context + meta *payload.Object_ID + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + wantId *payload.Object_ID + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_ID, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotId *payload.Object_ID, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotId, w.wantId) { + return errors.Errorf("got = %v, want %v", gotId, w.wantId) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + meta: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotId, err := s.Exists(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, gotId, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Search(t *testing.T) { + type args struct { + ctx context.Context + req *payload.Search_Request + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.Search(test.args.ctx, test.args.req) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_SearchByID(t *testing.T) { + type args struct { + ctx context.Context + req *payload.Search_IDRequest + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.SearchByID(test.args.ctx, test.args.req) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_search(t *testing.T) { + type args struct { + ctx context.Context + cfg *payload.Search_Config + f func(ctx context.Context, vc vald.ValdClient, copts ...grpc.CallOption) (*payload.Search_Response, error) + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + cfg: nil, + f: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + cfg: nil, + f: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.search(test.args.ctx, test.args.cfg, test.args.f) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamSearch(t *testing.T) { + type args struct { + stream vald.Vald_StreamSearchServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamSearch(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamSearchByID(t *testing.T) { + type args struct { + stream vald.Vald_StreamSearchByIDServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamSearchByID(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Insert(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + wantCe *payload.Object_Location + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Location, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCe *payload.Object_Location, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCe, w.wantCe) { + return errors.Errorf("got = %v, want %v", gotCe, w.wantCe) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotCe, err := s.Insert(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, gotCe, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamInsert(t *testing.T) { + type args struct { + stream vald.Vald_StreamInsertServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamInsert(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiInsert(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiInsert(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Update(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Location + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Location, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Location, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.Update(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamUpdate(t *testing.T) { + type args struct { + stream vald.Vald_StreamUpdateServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamUpdate(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiUpdate(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiUpdate(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Upsert(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_Location + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Location, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_Location, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.Upsert(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamUpsert(t *testing.T) { + type args struct { + stream vald.Vald_StreamUpsertServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamUpsert(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiUpsert(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.MultiUpsert(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Remove(t *testing.T) { + type args struct { + ctx context.Context + id *payload.Object_ID + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_Location + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Location, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_Location, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.Remove(test.args.ctx, test.args.id) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamRemove(t *testing.T) { + type args struct { + stream vald.Vald_StreamRemoveServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamRemove(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiRemove(t *testing.T) { + type args struct { + ctx context.Context + ids *payload.Object_IDs + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + ids: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + ids: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiRemove(test.args.ctx, test.args.ids) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_GetObject(t *testing.T) { + type args struct { + ctx context.Context + id *payload.Object_ID + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + wantVec *payload.Object_Vector + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Vector, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotVec *payload.Object_Vector, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotVec, w.wantVec) { + return errors.Errorf("got = %v, want %v", gotVec, w.wantVec) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotVec, err := s.GetObject(test.args.ctx, test.args.id) + if err := test.checkFunc(test.want, gotVec, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamGetObject(t *testing.T) { + type args struct { + stream vald.Vald_StreamGetObjectServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + timeout time.Duration + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + timeout: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + timeout: test.fields.timeout, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamGetObject(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/lb/handler/grpc/option.go b/pkg/gateway/lb/handler/grpc/option.go index 876b902f1fd..9e0727494d3 100644 --- a/pkg/gateway/lb/handler/grpc/option.go +++ b/pkg/gateway/lb/handler/grpc/option.go @@ -44,30 +44,6 @@ func WithGateway(g service.Gateway) Option { } } -func WithMeta(m service.Meta) Option { - return func(s *server) { - if m != nil { - s.metadata = m - } - } -} - -func WithBackup(b service.Backup) Option { - return func(s *server) { - if b != nil { - s.backup = b - } - } -} - -func WithFilters(filter service.Filter) Option { - return func(s *server) { - if filter != nil { - s.filter = filter - } - } -} - func WithErrGroup(eg errgroup.Group) Option { return func(s *server) { if eg != nil { diff --git a/pkg/gateway/lb/handler/grpc/option_test.go b/pkg/gateway/lb/handler/grpc/option_test.go new file mode 100644 index 00000000000..5582837c27a --- /dev/null +++ b/pkg/gateway/lb/handler/grpc/option_test.go @@ -0,0 +1,596 @@ +// +// 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 grpc server logic +package grpc + +import ( + "testing" + + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/pkg/gateway/lb/service" + "go.uber.org/goleak" +) + +func TestWithGateway(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + g service.Gateway + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + g: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + g: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithGateway(test.args.g) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithGateway(test.args.g) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithErrGroup(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + eg errgroup.Group + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithErrGroup(test.args.eg) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithErrGroup(test.args.eg) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithTimeout(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + dur string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithTimeout(test.args.dur) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithTimeout(test.args.dur) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithReplicationCount(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + rep int + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + rep: 0, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + rep: 0, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithReplicationCount(test.args.rep) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithReplicationCount(test.args.rep) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithStreamConcurrency(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + c int + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + c: 0, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + c: 0, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithStreamConcurrency(test.args.c) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithStreamConcurrency(test.args.c) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/lb/handler/rest/handler_test.go b/pkg/gateway/lb/handler/rest/handler_test.go new file mode 100644 index 00000000000..b0a7e7cebb5 --- /dev/null +++ b/pkg/gateway/lb/handler/rest/handler_test.go @@ -0,0 +1,1099 @@ +// +// 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 rest provides rest api logic +package rest + +import ( + "net/http" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want Handler + } + type test struct { + name string + args args + want want + checkFunc func(want, Handler) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got Handler) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Index(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + want int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + got, err := h.Index(test.args.w, test.args.r) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Search(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Search(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_SearchByID(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.SearchByID(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Insert(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Insert(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiInsert(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiInsert(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Update(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Update(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiUpdate(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiUpdate(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Remove(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Remove(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiRemove(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiRemove(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_GetObject(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.GetObject(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Exists(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Exists(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/lb/handler/rest/option_test.go b/pkg/gateway/lb/handler/rest/option_test.go new file mode 100644 index 00000000000..d45859d8dbd --- /dev/null +++ b/pkg/gateway/lb/handler/rest/option_test.go @@ -0,0 +1,139 @@ +// +// 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 rest provides rest api logic +package rest + +import ( + "testing" + + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "go.uber.org/goleak" +) + +func TestWithVald(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + v vald.ValdServer + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + v: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + v: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithVald(test.args.v) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithVald(test.args.v) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/lb/router/option_test.go b/pkg/gateway/lb/router/option_test.go new file mode 100644 index 00000000000..154c3593f31 --- /dev/null +++ b/pkg/gateway/lb/router/option_test.go @@ -0,0 +1,253 @@ +// +// 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 router provides implementation of Go API for routing http Handler wrapped by rest.Func +package router + +import ( + "testing" + + "github.com/vdaas/vald/pkg/gateway/lb/handler/rest" + "go.uber.org/goleak" +) + +func TestWithHandler(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + h rest.Handler + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + h: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + h: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithHandler(test.args.h) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithHandler(test.args.h) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithTimeout(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + timeout string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + timeout: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + timeout: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithTimeout(test.args.timeout) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithTimeout(test.args.timeout) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/lb/router/router_test.go b/pkg/gateway/lb/router/router_test.go new file mode 100644 index 00000000000..62ea7131477 --- /dev/null +++ b/pkg/gateway/lb/router/router_test.go @@ -0,0 +1,97 @@ +// +// 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 router provides implementation of Go API for routing http Handler wrapped by rest.Func +package router + +import ( + "net/http" + "reflect" + "testing" + + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want http.Handler + } + type test struct { + name string + args args + want want + checkFunc func(want, http.Handler) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got http.Handler) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/lb/service/backup.go b/pkg/gateway/lb/service/backup.go index 68a4b259f4f..305980f073d 100644 --- a/pkg/gateway/lb/service/backup.go +++ b/pkg/gateway/lb/service/backup.go @@ -28,10 +28,10 @@ import ( type Backup interface { Start(ctx context.Context) (<-chan error, error) - GetObject(ctx context.Context, uuid string) (*payload.Object_Locations, error) + GetObject(ctx context.Context, uuid string) (*payload.Backup_MetaVector, error) GetLocation(ctx context.Context, uuid string) ([]string, error) - Register(ctx context.Context, vec *payload.Object_Locations) error - RegisterMultiple(ctx context.Context, vecs *payload.Object_Locationss) error + Register(ctx context.Context, vec *payload.Backup_MetaVector) error + RegisterMultiple(ctx context.Context, vecs *payload.Backup_MetaVectors) error Remove(ctx context.Context, uuid string) error RemoveMultiple(ctx context.Context, uuids ...string) error } @@ -56,7 +56,7 @@ func (b *backup) Start(ctx context.Context) (<-chan error, error) { return b.client.StartConnectionMonitor(ctx) } -func (b *backup) GetObject(ctx context.Context, uuid string) (vec *payload.Object_Locations, err error) { +func (b *backup) GetObject(ctx context.Context, uuid string) (vec *payload.Backup_MetaVector, err error) { _, err = b.client.Do(ctx, b.addr, func(ctx context.Context, conn *grpc.ClientConn, copts ...grpc.CallOption) (i interface{}, err error) { vec, err = compressor.NewBackupClient(conn).GetVector(ctx, &payload.Backup_GetVector_Request{ @@ -65,9 +65,12 @@ func (b *backup) GetObject(ctx context.Context, uuid string) (vec *payload.Objec if err != nil { return nil, err } - return + return vec, nil }) - return + if err != nil { + return nil, err + } + return vec, nil } func (b *backup) GetLocation(ctx context.Context, uuid string) (ipList []string, err error) { @@ -85,7 +88,7 @@ func (b *backup) GetLocation(ctx context.Context, uuid string) (ipList []string, return } -func (b *backup) Register(ctx context.Context, vec *payload.Object_Locations) (err error) { +func (b *backup) Register(ctx context.Context, vec *payload.Backup_MetaVector) (err error) { _, err = b.client.Do(ctx, b.addr, func(ctx context.Context, conn *grpc.ClientConn, copts ...grpc.CallOption) (i interface{}, err error) { _, err = compressor.NewBackupClient(conn).Register(ctx, vec, copts...) @@ -97,7 +100,7 @@ func (b *backup) Register(ctx context.Context, vec *payload.Object_Locations) (e return } -func (b *backup) RegisterMultiple(ctx context.Context, vecs *payload.Object_Locationss) (err error) { +func (b *backup) RegisterMultiple(ctx context.Context, vecs *payload.Backup_MetaVectors) (err error) { _, err = b.client.Do(ctx, b.addr, func(ctx context.Context, conn *grpc.ClientConn, copts ...grpc.CallOption) (i interface{}, err error) { _, err = compressor.NewBackupClient(conn).RegisterMulti(ctx, vecs, copts...) diff --git a/pkg/gateway/lb/service/backup_option_test.go b/pkg/gateway/lb/service/backup_option_test.go new file mode 100644 index 00000000000..27be1d2b098 --- /dev/null +++ b/pkg/gateway/lb/service/backup_option_test.go @@ -0,0 +1,253 @@ +// +// 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 service +package service + +import ( + "testing" + + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestWithBackupAddr(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + addr string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithBackupAddr(test.args.addr) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithBackupAddr(test.args.addr) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithBackupClient(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + client grpc.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithBackupClient(test.args.client) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithBackupClient(test.args.client) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/lb/service/backup_test.go b/pkg/gateway/lb/service/backup_test.go new file mode 100644 index 00000000000..8021ffc8b15 --- /dev/null +++ b/pkg/gateway/lb/service/backup_test.go @@ -0,0 +1,749 @@ +// +// 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 service + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/payload" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestNewBackup(t *testing.T) { + type args struct { + opts []BackupOption + } + type want struct { + wantBu Backup + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Backup, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotBu Backup, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotBu, w.wantBu) { + return errors.Errorf("got = %v, want %v", gotBu, w.wantBu) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 + } + + gotBu, err := NewBackup(test.args.opts...) + if err := test.checkFunc(test.want, gotBu, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + got, err := b.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_GetObject(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + wantVec *payload.Backup_MetaVector + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Backup_MetaVector, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotVec *payload.Backup_MetaVector, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotVec, w.wantVec) { + return errors.Errorf("got = %v, want %v", gotVec, w.wantVec) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + gotVec, err := b.GetObject(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotVec, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_GetLocation(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + wantIpList []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotIpList []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotIpList, w.wantIpList) { + return errors.Errorf("got = %v, want %v", gotIpList, w.wantIpList) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + gotIpList, err := b.GetLocation(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotIpList, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_Register(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Backup_MetaVector + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.Register(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_RegisterMultiple(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Backup_MetaVectors + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.RegisterMultiple(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_Remove(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.Remove(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_RemoveMultiple(t *testing.T) { + type args struct { + ctx context.Context + uuids []string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.RemoveMultiple(test.args.ctx, test.args.uuids...) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/lb/service/filter_option_test.go b/pkg/gateway/lb/service/filter_option_test.go new file mode 100644 index 00000000000..7d941b6e8ce --- /dev/null +++ b/pkg/gateway/lb/service/filter_option_test.go @@ -0,0 +1,139 @@ +// +// 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 service +package service + +import ( + "testing" + + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestWithFilterClient(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + client grpc.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithFilterClient(test.args.client) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithFilterClient(test.args.client) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/lb/service/filter_test.go b/pkg/gateway/lb/service/filter_test.go new file mode 100644 index 00000000000..defabd62e3b --- /dev/null +++ b/pkg/gateway/lb/service/filter_test.go @@ -0,0 +1,282 @@ +// +// 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 service + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/payload" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestNewFilter(t *testing.T) { + type args struct { + opts []FilterOption + } + type want struct { + wantEf Filter + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Filter, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotEf Filter, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotEf, w.wantEf) { + return errors.Errorf("got = %v, want %v", gotEf, w.wantEf) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 + } + + gotEf, err := NewFilter(test.args.opts...) + if err := test.checkFunc(test.want, gotEf, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_filter_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + client grpc.Client + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + client: 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 + } + f := &filter{ + client: test.fields.client, + } + + got, err := f.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_filter_FilterSearch(t *testing.T) { + type args struct { + ctx context.Context + res *payload.Search_Response + } + type fields struct { + client grpc.Client + } + type want struct { + want *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + res: nil, + }, + fields: fields { + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + res: nil, + }, + fields: fields { + client: 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 + } + f := &filter{ + client: test.fields.client, + } + + got, err := f.FilterSearch(test.args.ctx, test.args.res) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/lb/service/gateway_option_test.go b/pkg/gateway/lb/service/gateway_option_test.go new file mode 100644 index 00000000000..6ac318982a7 --- /dev/null +++ b/pkg/gateway/lb/service/gateway_option_test.go @@ -0,0 +1,254 @@ +// +// 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 service +package service + +import ( + "testing" + + "github.com/vdaas/vald/internal/client/discoverer" + "github.com/vdaas/vald/internal/errgroup" + "go.uber.org/goleak" +) + +func TestWithDiscoverer(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + c discoverer.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + c: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + c: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithDiscoverer(test.args.c) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithDiscoverer(test.args.c) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithErrGroup(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + eg errgroup.Group + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithErrGroup(test.args.eg) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithErrGroup(test.args.eg) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/lb/service/gateway_test.go b/pkg/gateway/lb/service/gateway_test.go new file mode 100644 index 00000000000..54f3db58af2 --- /dev/null +++ b/pkg/gateway/lb/service/gateway_test.go @@ -0,0 +1,562 @@ +// +// 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 service +package service + +import ( + "context" + "reflect" + "testing" + + agent "github.com/vdaas/vald/apis/grpc/agent/core" + "github.com/vdaas/vald/internal/client/discoverer" + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestNewGateway(t *testing.T) { + type args struct { + opts []GWOption + } + type want struct { + wantGw Gateway + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Gateway, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotGw Gateway, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotGw, w.wantGw) { + return errors.Errorf("got = %v, want %v", gotGw, w.wantGw) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 + } + + gotGw, err := NewGateway(test.args.opts...) + if err := test.checkFunc(test.want, gotGw, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + got, err := g.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_BroadCast(t *testing.T) { + type args struct { + ctx context.Context + f func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + f: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + f: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + err := g.BroadCast(test.args.ctx, test.args.f) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_Do(t *testing.T) { + type args struct { + ctx context.Context + f func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + f: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + f: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + err := g.Do(test.args.ctx, test.args.f) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_DoMulti(t *testing.T) { + type args struct { + ctx context.Context + num int + f func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + num: 0, + f: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + num: 0, + f: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + err := g.DoMulti(test.args.ctx, test.args.num, test.args.f) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_GetAgentCount(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + want int + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got int) 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 { + ctx: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + got := g.GetAgentCount(test.args.ctx) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/lb/service/meta_option_test.go b/pkg/gateway/lb/service/meta_option_test.go new file mode 100644 index 00000000000..9c022ce4983 --- /dev/null +++ b/pkg/gateway/lb/service/meta_option_test.go @@ -0,0 +1,827 @@ +// +// 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 service +package service + +import ( + "testing" + + "github.com/vdaas/vald/internal/cache" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestWithMetaAddr(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + addr string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaAddr(test.args.addr) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaAddr(test.args.addr) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaHostPort(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + host string + port int + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + host: "", + port: 0, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + host: "", + port: 0, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaHostPort(test.args.host, test.args.port) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaHostPort(test.args.host, test.args.port) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaClient(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + client grpc.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaClient(test.args.client) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaClient(test.args.client) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCacheEnabled(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + flg bool + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + flg: false, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + flg: false, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCacheEnabled(test.args.flg) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCacheEnabled(test.args.flg) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCache(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + c cache.Cache + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + c: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + c: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCache(test.args.c) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCache(test.args.c) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCacheExpireDuration(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + dur string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCacheExpireDuration(test.args.dur) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCacheExpireDuration(test.args.dur) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCacheExpiredCheckDuration(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + dur string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCacheExpiredCheckDuration(test.args.dur) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCacheExpiredCheckDuration(test.args.dur) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/lb/service/meta_test.go b/pkg/gateway/lb/service/meta_test.go new file mode 100644 index 00000000000..2f6c63542ed --- /dev/null +++ b/pkg/gateway/lb/service/meta_test.go @@ -0,0 +1,1428 @@ +// +// 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 service provides meta service +package service + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/internal/cache" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestNewMeta(t *testing.T) { + type args struct { + opts []MetaOption + } + type want struct { + wantMi Meta + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Meta, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotMi Meta, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotMi, w.wantMi) { + return errors.Errorf("got = %v, want %v", gotMi, w.wantMi) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 + } + + gotMi, err := NewMeta(test.args.opts...) + if err := test.checkFunc(test.want, gotMi, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_Exists(t *testing.T) { + type args struct { + ctx context.Context + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want bool + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, bool, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got bool, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.Exists(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetMeta(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + wantV string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotV string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotV, w.wantV) { + return errors.Errorf("got = %v, want %v", gotV, w.wantV) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + gotV, err := m.GetMeta(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotV, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetMetas(t *testing.T) { + type args struct { + ctx context.Context + uuids []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.GetMetas(test.args.ctx, test.args.uuids...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetUUID(t *testing.T) { + type args struct { + ctx context.Context + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + wantK string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotK string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotK, w.wantK) { + return errors.Errorf("got = %v, want %v", gotK, w.wantK) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + gotK, err := m.GetUUID(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, gotK, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetUUIDs(t *testing.T) { + type args struct { + ctx context.Context + metas []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.GetUUIDs(test.args.ctx, test.args.metas...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_SetUUIDandMeta(t *testing.T) { + type args struct { + ctx context.Context + uuid string + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + err := m.SetUUIDandMeta(test.args.ctx, test.args.uuid, test.args.meta) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_SetUUIDandMetas(t *testing.T) { + type args struct { + ctx context.Context + kvs map[string]string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + kvs: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + kvs: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + err := m.SetUUIDandMetas(test.args.ctx, test.args.kvs) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteMeta(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + wantV string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotV string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotV, w.wantV) { + return errors.Errorf("got = %v, want %v", gotV, w.wantV) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + gotV, err := m.DeleteMeta(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotV, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteMetas(t *testing.T) { + type args struct { + ctx context.Context + uuids []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.DeleteMetas(test.args.ctx, test.args.uuids...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteUUID(t *testing.T) { + type args struct { + ctx context.Context + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.DeleteUUID(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteUUIDs(t *testing.T) { + type args struct { + ctx context.Context + metas []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.DeleteUUIDs(test.args.ctx, test.args.metas...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/lb/usecase/vald_test.go b/pkg/gateway/lb/usecase/vald_test.go new file mode 100644 index 00000000000..ec743f63cfe --- /dev/null +++ b/pkg/gateway/lb/usecase/vald_test.go @@ -0,0 +1,671 @@ +// +// 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 usecase + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/observability" + "github.com/vdaas/vald/internal/runner" + "github.com/vdaas/vald/internal/servers/starter" + "github.com/vdaas/vald/pkg/gateway/lb/config" + "github.com/vdaas/vald/pkg/gateway/lb/service" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + cfg *config.Data + } + type want struct { + wantR runner.Runner + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, runner.Runner, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotR runner.Runner, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotR, w.wantR) { + return errors.Errorf("got = %v, want %v", gotR, w.wantR) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + cfg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + cfg: 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 + } + + gotR, err := New(test.args.cfg) + if err := test.checkFunc(test.want, gotR, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PreStart(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + err := r.PreStart(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + got, err := r.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PreStop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + err := r.PreStop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_Stop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + err := r.Stop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PostStop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + err := r.PostStop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/meta/config/config_test.go b/pkg/gateway/meta/config/config_test.go new file mode 100644 index 00000000000..d9ccf63cfe9 --- /dev/null +++ b/pkg/gateway/meta/config/config_test.go @@ -0,0 +1,100 @@ +// +// 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 setting stores all server application settings +package config + +import ( + "reflect" + "testing" + + "go.uber.org/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(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCfg *Data, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCfg, w.wantCfg) { + return errors.Errorf("got = %v, want %v", gotCfg, w.wantCfg) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + path: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + path: "", + }, + 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 + } + + gotCfg, err := NewConfig(test.args.path) + if err := test.checkFunc(test.want, gotCfg, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/meta/handler/grpc/handler.go b/pkg/gateway/meta/handler/grpc/handler.go index 90475409541..6998a722f88 100644 --- a/pkg/gateway/meta/handler/grpc/handler.go +++ b/pkg/gateway/meta/handler/grpc/handler.go @@ -561,6 +561,7 @@ func (s *server) GetObject(ctx context.Context, id *payload.Object_ID) (vec *pay } return nil, status.WrapWithNotFound(fmt.Sprintf("GetObject API meta %s uuid %s Object not found", meta, uuid), err, info.Get()) } + vec.Id = meta return vec, nil } diff --git a/pkg/gateway/meta/handler/grpc/handler_test.go b/pkg/gateway/meta/handler/grpc/handler_test.go new file mode 100644 index 00000000000..359e2731268 --- /dev/null +++ b/pkg/gateway/meta/handler/grpc/handler_test.go @@ -0,0 +1,2195 @@ +// +// 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 grpc server logic +package grpc + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "github.com/vdaas/vald/apis/grpc/payload" + client "github.com/vdaas/vald/internal/client/gateway/vald" + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "github.com/vdaas/vald/pkg/gateway/meta/service" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want vald.ValdServer + } + type test struct { + name string + args args + want want + checkFunc func(want, vald.ValdServer) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got vald.ValdServer) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Exists(t *testing.T) { + type args struct { + ctx context.Context + meta *payload.Object_ID + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + want *payload.Object_ID + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_ID, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_ID, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + meta: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.Exists(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Search(t *testing.T) { + type args struct { + ctx context.Context + req *payload.Search_Request + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.Search(test.args.ctx, test.args.req) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_SearchByID(t *testing.T) { + type args struct { + ctx context.Context + req *payload.Search_IDRequest + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.SearchByID(test.args.ctx, test.args.req) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_search(t *testing.T) { + type args struct { + ctx context.Context + f func(ctx context.Context, vc vald.ValdClient, copts ...grpc.CallOption) (*payload.Search_Response, error) + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + f: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + f: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.search(test.args.ctx, test.args.f) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamSearch(t *testing.T) { + type args struct { + stream vald.Vald_StreamSearchServer + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamSearch(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamSearchByID(t *testing.T) { + type args struct { + stream vald.Vald_StreamSearchByIDServer + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamSearchByID(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Insert(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + wantCe *payload.Object_Location + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Location, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCe *payload.Object_Location, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCe, w.wantCe) { + return errors.Errorf("got = %v, want %v", gotCe, w.wantCe) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + gotCe, err := s.Insert(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, gotCe, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamInsert(t *testing.T) { + type args struct { + stream vald.Vald_StreamInsertServer + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamInsert(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiInsert(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiInsert(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Update(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Location + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Location, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Location, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.Update(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamUpdate(t *testing.T) { + type args struct { + stream vald.Vald_StreamUpdateServer + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamUpdate(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiUpdate(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiUpdate(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Upsert(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + want *payload.Object_Location + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Location, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_Location, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.Upsert(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamUpsert(t *testing.T) { + type args struct { + stream vald.Vald_StreamUpsertServer + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamUpsert(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiUpsert(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + want *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.MultiUpsert(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Remove(t *testing.T) { + type args struct { + ctx context.Context + id *payload.Object_ID + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Location + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Location, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Location, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.Remove(test.args.ctx, test.args.id) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamRemove(t *testing.T) { + type args struct { + stream vald.Vald_StreamRemoveServer + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamRemove(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiRemove(t *testing.T) { + type args struct { + ctx context.Context + ids *payload.Object_IDs + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + ids: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + ids: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiRemove(test.args.ctx, test.args.ids) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_GetObject(t *testing.T) { + type args struct { + ctx context.Context + id *payload.Object_ID + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + wantVec *payload.Object_Vector + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Vector, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotVec *payload.Object_Vector, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotVec, w.wantVec) { + return errors.Errorf("got = %v, want %v", gotVec, w.wantVec) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + gotVec, err := s.GetObject(test.args.ctx, test.args.id) + if err := test.checkFunc(test.want, gotVec, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamGetObject(t *testing.T) { + type args struct { + stream vald.Vald_StreamGetObjectServer + } + type fields struct { + eg errgroup.Group + metadata service.Meta + gateway client.Client + copts []grpc.CallOption + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + metadata: nil, + gateway: nil, + copts: nil, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + metadata: test.fields.metadata, + gateway: test.fields.gateway, + copts: test.fields.copts, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamGetObject(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/meta/handler/grpc/option_test.go b/pkg/gateway/meta/handler/grpc/option_test.go new file mode 100644 index 00000000000..d94646f79b4 --- /dev/null +++ b/pkg/gateway/meta/handler/grpc/option_test.go @@ -0,0 +1,483 @@ +// +// 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 grpc server logic +package grpc + +import ( + "testing" + + "github.com/vdaas/vald/internal/client/gateway/vald" + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/pkg/gateway/meta/service" + "go.uber.org/goleak" +) + +func TestWithClient(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + g vald.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + g: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + g: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithClient(test.args.g) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithClient(test.args.g) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMeta(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + m service.Meta + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + m: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + m: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMeta(test.args.m) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMeta(test.args.m) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithErrGroup(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + eg errgroup.Group + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithErrGroup(test.args.eg) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithErrGroup(test.args.eg) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithStreamConcurrency(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + c int + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + c: 0, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + c: 0, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithStreamConcurrency(test.args.c) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithStreamConcurrency(test.args.c) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/meta/handler/rest/handler_test.go b/pkg/gateway/meta/handler/rest/handler_test.go new file mode 100644 index 00000000000..b0a7e7cebb5 --- /dev/null +++ b/pkg/gateway/meta/handler/rest/handler_test.go @@ -0,0 +1,1099 @@ +// +// 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 rest provides rest api logic +package rest + +import ( + "net/http" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want Handler + } + type test struct { + name string + args args + want want + checkFunc func(want, Handler) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got Handler) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Index(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + want int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + got, err := h.Index(test.args.w, test.args.r) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Search(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Search(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_SearchByID(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.SearchByID(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Insert(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Insert(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiInsert(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiInsert(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Update(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Update(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiUpdate(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiUpdate(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Remove(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Remove(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiRemove(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiRemove(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_GetObject(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.GetObject(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Exists(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Exists(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/meta/handler/rest/option_test.go b/pkg/gateway/meta/handler/rest/option_test.go new file mode 100644 index 00000000000..d45859d8dbd --- /dev/null +++ b/pkg/gateway/meta/handler/rest/option_test.go @@ -0,0 +1,139 @@ +// +// 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 rest provides rest api logic +package rest + +import ( + "testing" + + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "go.uber.org/goleak" +) + +func TestWithVald(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + v vald.ValdServer + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + v: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + v: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithVald(test.args.v) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithVald(test.args.v) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/meta/router/option_test.go b/pkg/gateway/meta/router/option_test.go new file mode 100644 index 00000000000..486b7d0e430 --- /dev/null +++ b/pkg/gateway/meta/router/option_test.go @@ -0,0 +1,253 @@ +// +// 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 router provides implementation of Go API for routing http Handler wrapped by rest.Func +package router + +import ( + "testing" + + "github.com/vdaas/vald/pkg/gateway/meta/handler/rest" + "go.uber.org/goleak" +) + +func TestWithHandler(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + h rest.Handler + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + h: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + h: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithHandler(test.args.h) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithHandler(test.args.h) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithTimeout(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + timeout string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + timeout: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + timeout: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithTimeout(test.args.timeout) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithTimeout(test.args.timeout) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/meta/router/router_test.go b/pkg/gateway/meta/router/router_test.go new file mode 100644 index 00000000000..62ea7131477 --- /dev/null +++ b/pkg/gateway/meta/router/router_test.go @@ -0,0 +1,97 @@ +// +// 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 router provides implementation of Go API for routing http Handler wrapped by rest.Func +package router + +import ( + "net/http" + "reflect" + "testing" + + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want http.Handler + } + type test struct { + name string + args args + want want + checkFunc func(want, http.Handler) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got http.Handler) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/meta/service/meta_test.go b/pkg/gateway/meta/service/meta_test.go new file mode 100644 index 00000000000..f666f1c9f97 --- /dev/null +++ b/pkg/gateway/meta/service/meta_test.go @@ -0,0 +1,1428 @@ +// +// 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 service provides meta service +package service + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/internal/cache" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestNewMeta(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + wantMi Meta + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Meta, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotMi Meta, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotMi, w.wantMi) { + return errors.Errorf("got = %v, want %v", gotMi, w.wantMi) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 + } + + gotMi, err := NewMeta(test.args.opts...) + if err := test.checkFunc(test.want, gotMi, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_Exists(t *testing.T) { + type args struct { + ctx context.Context + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want bool + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, bool, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got bool, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.Exists(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetMeta(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + wantV string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotV string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotV, w.wantV) { + return errors.Errorf("got = %v, want %v", gotV, w.wantV) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + gotV, err := m.GetMeta(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotV, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetMetas(t *testing.T) { + type args struct { + ctx context.Context + uuids []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.GetMetas(test.args.ctx, test.args.uuids...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetUUID(t *testing.T) { + type args struct { + ctx context.Context + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + wantK string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotK string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotK, w.wantK) { + return errors.Errorf("got = %v, want %v", gotK, w.wantK) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + gotK, err := m.GetUUID(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, gotK, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetUUIDs(t *testing.T) { + type args struct { + ctx context.Context + metas []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.GetUUIDs(test.args.ctx, test.args.metas...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_SetUUIDandMeta(t *testing.T) { + type args struct { + ctx context.Context + uuid string + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + err := m.SetUUIDandMeta(test.args.ctx, test.args.uuid, test.args.meta) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_SetUUIDandMetas(t *testing.T) { + type args struct { + ctx context.Context + kvs map[string]string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + kvs: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + kvs: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + err := m.SetUUIDandMetas(test.args.ctx, test.args.kvs) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteMeta(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + wantV string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotV string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotV, w.wantV) { + return errors.Errorf("got = %v, want %v", gotV, w.wantV) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + gotV, err := m.DeleteMeta(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotV, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteMetas(t *testing.T) { + type args struct { + ctx context.Context + uuids []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.DeleteMetas(test.args.ctx, test.args.uuids...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteUUID(t *testing.T) { + type args struct { + ctx context.Context + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.DeleteUUID(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteUUIDs(t *testing.T) { + type args struct { + ctx context.Context + metas []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.DeleteUUIDs(test.args.ctx, test.args.metas...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/meta/service/option_test.go b/pkg/gateway/meta/service/option_test.go new file mode 100644 index 00000000000..9c022ce4983 --- /dev/null +++ b/pkg/gateway/meta/service/option_test.go @@ -0,0 +1,827 @@ +// +// 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 service +package service + +import ( + "testing" + + "github.com/vdaas/vald/internal/cache" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestWithMetaAddr(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + addr string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaAddr(test.args.addr) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaAddr(test.args.addr) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaHostPort(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + host string + port int + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + host: "", + port: 0, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + host: "", + port: 0, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaHostPort(test.args.host, test.args.port) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaHostPort(test.args.host, test.args.port) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaClient(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + client grpc.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaClient(test.args.client) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaClient(test.args.client) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCacheEnabled(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + flg bool + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + flg: false, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + flg: false, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCacheEnabled(test.args.flg) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCacheEnabled(test.args.flg) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCache(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + c cache.Cache + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + c: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + c: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCache(test.args.c) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCache(test.args.c) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCacheExpireDuration(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + dur string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCacheExpireDuration(test.args.dur) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCacheExpireDuration(test.args.dur) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCacheExpiredCheckDuration(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + dur string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCacheExpiredCheckDuration(test.args.dur) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCacheExpiredCheckDuration(test.args.dur) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/meta/usecase/vald_test.go b/pkg/gateway/meta/usecase/vald_test.go new file mode 100644 index 00000000000..953ae8800b8 --- /dev/null +++ b/pkg/gateway/meta/usecase/vald_test.go @@ -0,0 +1,611 @@ +// +// 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 usecase + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/observability" + "github.com/vdaas/vald/internal/runner" + "github.com/vdaas/vald/internal/servers/starter" + "github.com/vdaas/vald/pkg/gateway/meta/config" + "github.com/vdaas/vald/pkg/gateway/meta/service" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + cfg *config.Data + } + type want struct { + wantR runner.Runner + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, runner.Runner, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotR runner.Runner, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotR, w.wantR) { + return errors.Errorf("got = %v, want %v", gotR, w.wantR) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + cfg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + cfg: 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 + } + + gotR, err := New(test.args.cfg) + if err := test.checkFunc(test.want, gotR, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PreStart(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + metadata service.Meta + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + metadata: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + metadata: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + metadata: test.fields.metadata, + } + + err := r.PreStart(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + metadata service.Meta + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + metadata: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + metadata: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + metadata: test.fields.metadata, + } + + got, err := r.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PreStop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + metadata service.Meta + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + metadata: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + metadata: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + metadata: test.fields.metadata, + } + + err := r.PreStop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_Stop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + metadata service.Meta + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + metadata: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + metadata: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + metadata: test.fields.metadata, + } + + err := r.Stop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PostStop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + metadata service.Meta + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + metadata: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + metadata: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + metadata: test.fields.metadata, + } + + err := r.PostStop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/vald/config/config_test.go b/pkg/gateway/vald/config/config_test.go new file mode 100644 index 00000000000..d9ccf63cfe9 --- /dev/null +++ b/pkg/gateway/vald/config/config_test.go @@ -0,0 +1,100 @@ +// +// 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 setting stores all server application settings +package config + +import ( + "reflect" + "testing" + + "go.uber.org/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(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCfg *Data, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCfg, w.wantCfg) { + return errors.Errorf("got = %v, want %v", gotCfg, w.wantCfg) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + path: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + path: "", + }, + 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 + } + + gotCfg, err := NewConfig(test.args.path) + if err := test.checkFunc(test.want, gotCfg, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/vald/handler/grpc/checklist_test.go b/pkg/gateway/vald/handler/grpc/checklist_test.go new file mode 100644 index 00000000000..0fb9c171933 --- /dev/null +++ b/pkg/gateway/vald/handler/grpc/checklist_test.go @@ -0,0 +1,608 @@ +// +// 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 + +import ( + "reflect" + "sync" + "sync/atomic" + "testing" + "unsafe" + + "go.uber.org/goleak" +) + +func Test_checkList_Exists(t *testing.T) { + type args struct { + key string + } + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + want bool + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got bool) 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 { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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 + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + got := m.Exists(test.args.key) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_checkList_Check(t *testing.T) { + type args struct { + key string + } + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + key: "", + }, + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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 + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.Check(test.args.key) + if err := test.checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_entryCheckList_tryStore(t *testing.T) { + type args struct { + i *struct{} + } + type fields struct { + p unsafe.Pointer + } + type want struct { + want bool + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got bool) 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 { + i: struct{}{}, + }, + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + i: struct{}{}, + }, + fields: fields { + p: 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 + } + e := &entryCheckList{ + p: test.fields.p, + } + + got := e.tryStore(test.args.i) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_entryCheckList_unexpungeLocked(t *testing.T) { + type fields struct { + p unsafe.Pointer + } + type want struct { + wantWasExpunged bool + } + type test struct { + name string + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want, gotWasExpunged bool) error { + if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { + return errors.Errorf("got = %v, want %v", gotWasExpunged, w.wantWasExpunged) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + p: 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + e := &entryCheckList{ + p: test.fields.p, + } + + gotWasExpunged := e.unexpungeLocked() + if err := test.checkFunc(test.want, gotWasExpunged); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_checkList_missLocked(t *testing.T) { + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + } + type test struct { + name string + fields fields + want want + checkFunc func(want) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.missLocked() + if err := test.checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_checkList_dirtyLocked(t *testing.T) { + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryCheckList + misses int + } + type want struct { + } + type test struct { + name string + fields fields + want want + checkFunc func(want) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + mu: sync.Mutex{}, + read: nil, + dirty: nil, + misses: 0, + }, + 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + m := &checkList{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.dirtyLocked() + if err := test.checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_entryCheckList_tryExpungeLocked(t *testing.T) { + type fields struct { + p unsafe.Pointer + } + type want struct { + wantIsExpunged bool + } + type test struct { + name string + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want, gotIsExpunged bool) error { + if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { + return errors.Errorf("got = %v, want %v", gotIsExpunged, w.wantIsExpunged) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + p: 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() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + e := &entryCheckList{ + p: test.fields.p, + } + + gotIsExpunged := e.tryExpungeLocked() + if err := test.checkFunc(test.want, gotIsExpunged); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/vald/handler/grpc/handler.go b/pkg/gateway/vald/handler/grpc/handler.go index 6c97fc40607..b7b3832d400 100644 --- a/pkg/gateway/vald/handler/grpc/handler.go +++ b/pkg/gateway/vald/handler/grpc/handler.go @@ -27,7 +27,6 @@ import ( "time" "github.com/kpango/fuid" - agent "github.com/vdaas/vald/apis/grpc/agent/core" "github.com/vdaas/vald/apis/grpc/gateway/vald" "github.com/vdaas/vald/apis/grpc/payload" "github.com/vdaas/vald/internal/errgroup" @@ -91,8 +90,8 @@ func (s *server) Search(ctx context.Context, req *payload.Search_Request) (res * return nil, errors.ErrInvalidDimensionSize(len(req.Vector), 0) } return s.search(ctx, req.GetConfig(), - func(ctx context.Context, ac agent.AgentClient, copts ...grpc.CallOption) (*payload.Search_Response, error) { - return ac.Search(ctx, req, copts...) + func(ctx context.Context, vc vald.ValdClient, copts ...grpc.CallOption) (*payload.Search_Response, error) { + return vc.Search(ctx, req, copts...) }) } @@ -115,13 +114,13 @@ func (s *server) SearchByID(ctx context.Context, req *payload.Search_IDRequest) return nil, status.WrapWithNotFound(fmt.Sprintf("SearchByID API meta %s's uuid not found", metaID), err, req, info.Get()) } return s.search(ctx, req.GetConfig(), - func(ctx context.Context, ac agent.AgentClient, copts ...grpc.CallOption) (*payload.Search_Response, error) { - return ac.SearchByID(ctx, req, copts...) + func(ctx context.Context, vc vald.ValdClient, copts ...grpc.CallOption) (*payload.Search_Response, error) { + return vc.SearchByID(ctx, req, copts...) }) } func (s *server) search(ctx context.Context, cfg *payload.Search_Config, - f func(ctx context.Context, ac agent.AgentClient, copts ...grpc.CallOption) (*payload.Search_Response, error)) ( + f func(ctx context.Context, vc vald.ValdClient, copts ...grpc.CallOption) (*payload.Search_Response, error)) ( res *payload.Search_Response, err error) { ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.search") defer func() { @@ -150,8 +149,8 @@ func (s *server) search(ctx context.Context, cfg *payload.Search_Config, // cl := new(checkList) visited := make(map[string]bool, len(res.Results)) mu := sync.RWMutex{} - return s.gateway.BroadCast(ectx, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error { - r, err := f(ctx, ac, copts...) + return s.gateway.BroadCast(ectx, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error { + r, err := f(ctx, vc, copts...) if err != nil { log.Debug(err) return nil @@ -327,8 +326,8 @@ func (s *server) Insert(ctx context.Context, vec *payload.Object_Vector) (ce *pa vec.Id = uuid mu := new(sync.Mutex) targets := make([]string, 0, s.replica) - err = s.gateway.DoMulti(ctx, s.replica, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) (err error) { - _, err = ac.Insert(ctx, vec, copts...) + err = s.gateway.DoMulti(ctx, s.replica, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) (err error) { + _, err = vc.Insert(ctx, vec, copts...) if err != nil { if err == errors.ErrRPCCallFailed(target, context.Canceled) { return nil @@ -350,9 +349,8 @@ func (s *server) Insert(ctx context.Context, vec *payload.Object_Vector) (ce *pa return nil, status.WrapWithInternal(fmt.Sprintf("Insert API failed to Execute DoMulti error = %s", err.Error()), err, info.Get()) } if s.backup != nil { - vecs := &payload.Object_Location{ + vecs := &payload.Backup_MetaVector{ Uuid: uuid, - Meta: meta, Ips: targets, } if vec != nil { @@ -432,8 +430,8 @@ func (s *server) MultiInsert(ctx context.Context, vecs *payload.Object_Vectors) mu := new(sync.Mutex) targets := make([]string, 0, s.replica) - gerr := s.gateway.DoMulti(ctx, s.replica, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) (err error) { - _, err = ac.MultiInsert(ctx, vecs, copts...) + gerr := s.gateway.DoMulti(ctx, s.replica, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) (err error) { + _, err = vc.MultiInsert(ctx, vecs, copts...) if err != nil { return err } @@ -451,13 +449,12 @@ func (s *server) MultiInsert(ctx context.Context, vecs *payload.Object_Vectors) } if s.backup != nil { - mvecs := new(payload.Object_Locations) - mvecs.Vectors = make([]*payload.Object_Location, 0, len(vecs.GetVectors())) + mvecs := new(payload.Backup_MetaVectors) + mvecs.Vectors = make([]*payload.Backup_MetaVector, 0, len(vecs.GetVectors())) for _, vec := range vecs.GetVectors() { uuid := vec.GetId() - mvecs.Vectors = append(mvecs.Vectors, &payload.Object_Location{ + mvecs.Vectors = append(mvecs.Vectors, &payload.Backup_MetaVector{ Uuid: uuid, - Meta: metaMap[uuid], Vector: vec.GetVector(), Ips: targets, }) @@ -500,11 +497,11 @@ func (s *server) Update(ctx context.Context, vec *payload.Object_Vector) (res *p for _, loc := range locs { lmap[loc] = struct{}{} } - err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error { + err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error { target = strings.SplitN(target, ":", 2)[0] _, ok := lmap[target] if ok { - _, err = ac.Update(ctx, vec, copts...) + _, err = vc.Update(ctx, vec, copts...) if err != nil { return err } @@ -517,13 +514,11 @@ func (s *server) Update(ctx context.Context, vec *payload.Object_Vector) (res *p } return nil, status.WrapWithInternal(fmt.Sprintf("Update API failed request %#v", vec), err, info.Get()) } - mvec := &payload.Object_Location{ + err = s.backup.Register(ctx, &payload.Backup_MetaVector{ Uuid: uuid, - Meta: meta, Vector: vec.GetVector(), Ips: locs, - } - err = s.backup.Register(ctx, mvec) + }) if err != nil { if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) @@ -710,10 +705,10 @@ func (s *server) Remove(ctx context.Context, id *payload.Object_ID) (*payload.Ob for _, loc := range locs { lmap[loc] = struct{}{} } - err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error { + err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error { _, ok := lmap[target] if ok { - _, err = ac.Remove(ctx, &payload.Object_ID{ + _, err = vc.Remove(ctx, &payload.Object_ID{ Id: uuid, }, copts...) if err != nil { @@ -759,7 +754,7 @@ func (s *server) StreamRemove(stream vald.Vald_StreamRemoveServer) error { }) } -func (s *server) MultiRemove(ctx context.Context, ids *payload.Object_IDs) (res *payload.Object_Location, err error) { +func (s *server) MultiRemove(ctx context.Context, ids *payload.Object_IDs) (res *payload.Object_Locations, err error) { ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.MultiRemove") defer func() { if span != nil { @@ -783,10 +778,10 @@ func (s *server) MultiRemove(ctx context.Context, ids *payload.Object_IDs) (res lmap[loc] = append(lmap[loc], uuid) } } - err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error { + err = s.gateway.BroadCast(ctx, func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error { uuids, ok := lmap[target] if ok { - _, err := ac.MultiRemove(ctx, &payload.Object_IDs{ + _, err := vc.MultiRemove(ctx, &payload.Object_IDs{ Ids: uuids, }, copts...) if err != nil { @@ -815,10 +810,10 @@ func (s *server) MultiRemove(ctx context.Context, ids *payload.Object_IDs) (res } return nil, status.WrapWithInternal(fmt.Sprintf("MultiRemove API failed to Remove backup uuids %v ", uuids), err, info.Get()) } - return new(payload.Object_Location), nil + return new(payload.Object_Locations), nil } -func (s *server) GetObject(ctx context.Context, id *payload.Object_ID) (vec *payload.Object_Location, err error) { +func (s *server) GetObject(ctx context.Context, id *payload.Object_ID) (vec *payload.Object_Vector, err error) { ctx, span := trace.StartSpan(ctx, "vald/gateway-vald.GetObject") defer func() { if span != nil { @@ -833,13 +828,17 @@ func (s *server) GetObject(ctx context.Context, id *payload.Object_ID) (vec *pay } return nil, status.WrapWithNotFound(fmt.Sprintf("GetObject API meta %s's uuid not found", meta), err, info.Get()) } - vec, err = s.backup.GetObject(ctx, uuid) + mvec, err := s.backup.GetObject(ctx, uuid) if err != nil { if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } return nil, status.WrapWithNotFound(fmt.Sprintf("GetObject API meta %s uuid %s Object not found", meta, uuid), err, info.Get()) } + vec = &payload.Object_Vector{ + Id: mvec.GetUuid(), + Vector: mvec.GetVector(), + } return vec, nil } diff --git a/pkg/gateway/vald/handler/grpc/handler_test.go b/pkg/gateway/vald/handler/grpc/handler_test.go new file mode 100644 index 00000000000..82dd4df6509 --- /dev/null +++ b/pkg/gateway/vald/handler/grpc/handler_test.go @@ -0,0 +1,2438 @@ +// +// 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 grpc server logic +package grpc + +import ( + "context" + "reflect" + "testing" + "time" + + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "github.com/vdaas/vald/apis/grpc/payload" + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "github.com/vdaas/vald/pkg/gateway/vald/service" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want vald.ValdServer + } + type test struct { + name string + args args + want want + checkFunc func(want, vald.ValdServer) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got vald.ValdServer) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Exists(t *testing.T) { + type args struct { + ctx context.Context + meta *payload.Object_ID + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_ID + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_ID, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_ID, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + meta: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.Exists(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Search(t *testing.T) { + type args struct { + ctx context.Context + req *payload.Search_Request + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.Search(test.args.ctx, test.args.req) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_SearchByID(t *testing.T) { + type args struct { + ctx context.Context + req *payload.Search_IDRequest + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + req: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.SearchByID(test.args.ctx, test.args.req) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_search(t *testing.T) { + type args struct { + ctx context.Context + cfg *payload.Search_Config + f func(ctx context.Context, vc vald.ValdClient, copts ...grpc.CallOption) (*payload.Search_Response, error) + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + cfg: nil, + f: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + cfg: nil, + f: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.search(test.args.ctx, test.args.cfg, test.args.f) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamSearch(t *testing.T) { + type args struct { + stream vald.Vald_StreamSearchServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamSearch(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamSearchByID(t *testing.T) { + type args struct { + stream vald.Vald_StreamSearchByIDServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamSearchByID(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Insert(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantCe *payload.Object_Location + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Location, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCe *payload.Object_Location, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCe, w.wantCe) { + return errors.Errorf("got = %v, want %v", gotCe, w.wantCe) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotCe, err := s.Insert(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, gotCe, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamInsert(t *testing.T) { + type args struct { + stream vald.Vald_StreamInsertServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamInsert(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiInsert(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiInsert(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Update(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Location + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Location, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Location, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.Update(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamUpdate(t *testing.T) { + type args struct { + stream vald.Vald_StreamUpdateServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamUpdate(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiUpdate(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiUpdate(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Upsert(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Object_Vector + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_Location + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Location, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_Location, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.Upsert(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamUpsert(t *testing.T) { + type args struct { + stream vald.Vald_StreamUpsertServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamUpsert(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiUpsert(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Object_Vectors + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.MultiUpsert(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_Remove(t *testing.T) { + type args struct { + ctx context.Context + id *payload.Object_ID + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + want *payload.Object_Location + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Location, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Object_Location, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + got, err := s.Remove(test.args.ctx, test.args.id) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamRemove(t *testing.T) { + type args struct { + stream vald.Vald_StreamRemoveServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamRemove(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_MultiRemove(t *testing.T) { + type args struct { + ctx context.Context + ids *payload.Object_IDs + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantRes *payload.Object_Locations + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Locations, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got = %v, want %v", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + ids: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + ids: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotRes, err := s.MultiRemove(test.args.ctx, test.args.ids) + if err := test.checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_GetObject(t *testing.T) { + type args struct { + ctx context.Context + id *payload.Object_ID + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + wantVec *payload.Object_Vector + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Object_Vector, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotVec *payload.Object_Vector, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotVec, w.wantVec) { + return errors.Errorf("got = %v, want %v", gotVec, w.wantVec) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + id: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + gotVec, err := s.GetObject(test.args.ctx, test.args.id) + if err := test.checkFunc(test.want, gotVec, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_StreamGetObject(t *testing.T) { + type args struct { + stream vald.Vald_StreamGetObjectServer + } + type fields struct { + eg errgroup.Group + gateway service.Gateway + metadata service.Meta + backup service.Backup + timeout time.Duration + filter service.Filter + replica int + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + stream: nil, + }, + fields: fields { + eg: nil, + gateway: nil, + metadata: nil, + backup: nil, + timeout: nil, + filter: nil, + replica: 0, + streamConcurrency: 0, + }, + 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 + } + s := &server{ + eg: test.fields.eg, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + timeout: test.fields.timeout, + filter: test.fields.filter, + replica: test.fields.replica, + streamConcurrency: test.fields.streamConcurrency, + } + + err := s.StreamGetObject(test.args.stream) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/vald/handler/grpc/option_test.go b/pkg/gateway/vald/handler/grpc/option_test.go new file mode 100644 index 00000000000..b453352dc1a --- /dev/null +++ b/pkg/gateway/vald/handler/grpc/option_test.go @@ -0,0 +1,938 @@ +// +// 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 grpc server logic +package grpc + +import ( + "testing" + + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/pkg/gateway/vald/service" + "go.uber.org/goleak" +) + +func TestWithGateway(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + g service.Gateway + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + g: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + g: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithGateway(test.args.g) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithGateway(test.args.g) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMeta(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + m service.Meta + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + m: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + m: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMeta(test.args.m) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMeta(test.args.m) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithBackup(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + b service.Backup + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + b: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + b: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithBackup(test.args.b) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithBackup(test.args.b) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithFilters(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + filter service.Filter + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + filter: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + filter: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithFilters(test.args.filter) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithFilters(test.args.filter) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithErrGroup(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + eg errgroup.Group + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithErrGroup(test.args.eg) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithErrGroup(test.args.eg) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithTimeout(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + dur string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithTimeout(test.args.dur) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithTimeout(test.args.dur) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithReplicationCount(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + rep int + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + rep: 0, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + rep: 0, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithReplicationCount(test.args.rep) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithReplicationCount(test.args.rep) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithStreamConcurrency(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + c int + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + c: 0, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + c: 0, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithStreamConcurrency(test.args.c) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithStreamConcurrency(test.args.c) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/vald/handler/rest/handler_test.go b/pkg/gateway/vald/handler/rest/handler_test.go new file mode 100644 index 00000000000..b0a7e7cebb5 --- /dev/null +++ b/pkg/gateway/vald/handler/rest/handler_test.go @@ -0,0 +1,1099 @@ +// +// 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 rest provides rest api logic +package rest + +import ( + "net/http" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want Handler + } + type test struct { + name string + args args + want want + checkFunc func(want, Handler) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got Handler) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Index(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + want int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + got, err := h.Index(test.args.w, test.args.r) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Search(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Search(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_SearchByID(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.SearchByID(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Insert(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Insert(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiInsert(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiInsert(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Update(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Update(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiUpdate(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiUpdate(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Remove(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Remove(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_MultiRemove(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.MultiRemove(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_GetObject(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.GetObject(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Exists(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + vald vald.ValdServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got = %v, want %v", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + vald: 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 + } + h := &handler{ + vald: test.fields.vald, + } + + gotCode, err := h.Exists(test.args.w, test.args.r) + if err := test.checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/vald/handler/rest/option_test.go b/pkg/gateway/vald/handler/rest/option_test.go new file mode 100644 index 00000000000..d45859d8dbd --- /dev/null +++ b/pkg/gateway/vald/handler/rest/option_test.go @@ -0,0 +1,139 @@ +// +// 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 rest provides rest api logic +package rest + +import ( + "testing" + + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "go.uber.org/goleak" +) + +func TestWithVald(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + v vald.ValdServer + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + v: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + v: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithVald(test.args.v) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithVald(test.args.v) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/vald/router/option_test.go b/pkg/gateway/vald/router/option_test.go new file mode 100644 index 00000000000..51d8860afba --- /dev/null +++ b/pkg/gateway/vald/router/option_test.go @@ -0,0 +1,253 @@ +// +// 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 router provides implementation of Go API for routing http Handler wrapped by rest.Func +package router + +import ( + "testing" + + "github.com/vdaas/vald/pkg/gateway/vald/handler/rest" + "go.uber.org/goleak" +) + +func TestWithHandler(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + h rest.Handler + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + h: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + h: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithHandler(test.args.h) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithHandler(test.args.h) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithTimeout(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + timeout string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + timeout: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + timeout: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithTimeout(test.args.timeout) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithTimeout(test.args.timeout) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/vald/router/router_test.go b/pkg/gateway/vald/router/router_test.go new file mode 100644 index 00000000000..62ea7131477 --- /dev/null +++ b/pkg/gateway/vald/router/router_test.go @@ -0,0 +1,97 @@ +// +// 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 router provides implementation of Go API for routing http Handler wrapped by rest.Func +package router + +import ( + "net/http" + "reflect" + "testing" + + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want http.Handler + } + type test struct { + name string + args args + want want + checkFunc func(want, http.Handler) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got http.Handler) 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 { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 := New(test.args.opts...) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/vald/service/backup.go b/pkg/gateway/vald/service/backup.go index 68a4b259f4f..bc50e649047 100644 --- a/pkg/gateway/vald/service/backup.go +++ b/pkg/gateway/vald/service/backup.go @@ -28,10 +28,10 @@ import ( type Backup interface { Start(ctx context.Context) (<-chan error, error) - GetObject(ctx context.Context, uuid string) (*payload.Object_Locations, error) + GetObject(ctx context.Context, uuid string) (*payload.Backup_MetaVector, error) GetLocation(ctx context.Context, uuid string) ([]string, error) - Register(ctx context.Context, vec *payload.Object_Locations) error - RegisterMultiple(ctx context.Context, vecs *payload.Object_Locationss) error + Register(ctx context.Context, vec *payload.Backup_MetaVector) error + RegisterMultiple(ctx context.Context, vecs *payload.Backup_MetaVectors) error Remove(ctx context.Context, uuid string) error RemoveMultiple(ctx context.Context, uuids ...string) error } @@ -56,7 +56,7 @@ func (b *backup) Start(ctx context.Context) (<-chan error, error) { return b.client.StartConnectionMonitor(ctx) } -func (b *backup) GetObject(ctx context.Context, uuid string) (vec *payload.Object_Locations, err error) { +func (b *backup) GetObject(ctx context.Context, uuid string) (vec *payload.Backup_MetaVector, err error) { _, err = b.client.Do(ctx, b.addr, func(ctx context.Context, conn *grpc.ClientConn, copts ...grpc.CallOption) (i interface{}, err error) { vec, err = compressor.NewBackupClient(conn).GetVector(ctx, &payload.Backup_GetVector_Request{ @@ -85,7 +85,7 @@ func (b *backup) GetLocation(ctx context.Context, uuid string) (ipList []string, return } -func (b *backup) Register(ctx context.Context, vec *payload.Object_Locations) (err error) { +func (b *backup) Register(ctx context.Context, vec *payload.Backup_MetaVector) (err error) { _, err = b.client.Do(ctx, b.addr, func(ctx context.Context, conn *grpc.ClientConn, copts ...grpc.CallOption) (i interface{}, err error) { _, err = compressor.NewBackupClient(conn).Register(ctx, vec, copts...) @@ -97,7 +97,7 @@ func (b *backup) Register(ctx context.Context, vec *payload.Object_Locations) (e return } -func (b *backup) RegisterMultiple(ctx context.Context, vecs *payload.Object_Locationss) (err error) { +func (b *backup) RegisterMultiple(ctx context.Context, vecs *payload.Backup_MetaVectors) (err error) { _, err = b.client.Do(ctx, b.addr, func(ctx context.Context, conn *grpc.ClientConn, copts ...grpc.CallOption) (i interface{}, err error) { _, err = compressor.NewBackupClient(conn).RegisterMulti(ctx, vecs, copts...) diff --git a/pkg/gateway/vald/service/backup_option_test.go b/pkg/gateway/vald/service/backup_option_test.go new file mode 100644 index 00000000000..27be1d2b098 --- /dev/null +++ b/pkg/gateway/vald/service/backup_option_test.go @@ -0,0 +1,253 @@ +// +// 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 service +package service + +import ( + "testing" + + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestWithBackupAddr(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + addr string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithBackupAddr(test.args.addr) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithBackupAddr(test.args.addr) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithBackupClient(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + client grpc.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithBackupClient(test.args.client) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithBackupClient(test.args.client) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/vald/service/backup_test.go b/pkg/gateway/vald/service/backup_test.go new file mode 100644 index 00000000000..8021ffc8b15 --- /dev/null +++ b/pkg/gateway/vald/service/backup_test.go @@ -0,0 +1,749 @@ +// +// 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 service + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/payload" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestNewBackup(t *testing.T) { + type args struct { + opts []BackupOption + } + type want struct { + wantBu Backup + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Backup, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotBu Backup, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotBu, w.wantBu) { + return errors.Errorf("got = %v, want %v", gotBu, w.wantBu) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 + } + + gotBu, err := NewBackup(test.args.opts...) + if err := test.checkFunc(test.want, gotBu, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + got, err := b.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_GetObject(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + wantVec *payload.Backup_MetaVector + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Backup_MetaVector, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotVec *payload.Backup_MetaVector, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotVec, w.wantVec) { + return errors.Errorf("got = %v, want %v", gotVec, w.wantVec) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + gotVec, err := b.GetObject(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotVec, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_GetLocation(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + wantIpList []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotIpList []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotIpList, w.wantIpList) { + return errors.Errorf("got = %v, want %v", gotIpList, w.wantIpList) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + gotIpList, err := b.GetLocation(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotIpList, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_Register(t *testing.T) { + type args struct { + ctx context.Context + vec *payload.Backup_MetaVector + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vec: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.Register(test.args.ctx, test.args.vec) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_RegisterMultiple(t *testing.T) { + type args struct { + ctx context.Context + vecs *payload.Backup_MetaVectors + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + vecs: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.RegisterMultiple(test.args.ctx, test.args.vecs) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_Remove(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.Remove(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_backup_RemoveMultiple(t *testing.T) { + type args struct { + ctx context.Context + uuids []string + } + type fields struct { + addr string + client grpc.Client + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: 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 + } + b := &backup{ + addr: test.fields.addr, + client: test.fields.client, + } + + err := b.RemoveMultiple(test.args.ctx, test.args.uuids...) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/vald/service/filter_option_test.go b/pkg/gateway/vald/service/filter_option_test.go new file mode 100644 index 00000000000..7d941b6e8ce --- /dev/null +++ b/pkg/gateway/vald/service/filter_option_test.go @@ -0,0 +1,139 @@ +// +// 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 service +package service + +import ( + "testing" + + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestWithFilterClient(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + client grpc.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithFilterClient(test.args.client) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithFilterClient(test.args.client) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/vald/service/filter_test.go b/pkg/gateway/vald/service/filter_test.go new file mode 100644 index 00000000000..defabd62e3b --- /dev/null +++ b/pkg/gateway/vald/service/filter_test.go @@ -0,0 +1,282 @@ +// +// 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 service + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/payload" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestNewFilter(t *testing.T) { + type args struct { + opts []FilterOption + } + type want struct { + wantEf Filter + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Filter, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotEf Filter, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotEf, w.wantEf) { + return errors.Errorf("got = %v, want %v", gotEf, w.wantEf) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 + } + + gotEf, err := NewFilter(test.args.opts...) + if err := test.checkFunc(test.want, gotEf, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_filter_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + client grpc.Client + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + client: 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 + } + f := &filter{ + client: test.fields.client, + } + + got, err := f.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_filter_FilterSearch(t *testing.T) { + type args struct { + ctx context.Context + res *payload.Search_Response + } + type fields struct { + client grpc.Client + } + type want struct { + want *payload.Search_Response + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got *payload.Search_Response, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + res: nil, + }, + fields: fields { + client: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + res: nil, + }, + fields: fields { + client: 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 + } + f := &filter{ + client: test.fields.client, + } + + got, err := f.FilterSearch(test.args.ctx, test.args.res) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/vald/service/gateway.go b/pkg/gateway/vald/service/gateway.go index 06469551ad2..6585ce4e4f7 100644 --- a/pkg/gateway/vald/service/gateway.go +++ b/pkg/gateway/vald/service/gateway.go @@ -22,7 +22,7 @@ import ( "reflect" "sync/atomic" - agent "github.com/vdaas/vald/apis/grpc/agent/core" + "github.com/vdaas/vald/apis/grpc/gateway/vald" "github.com/vdaas/vald/internal/client/discoverer" "github.com/vdaas/vald/internal/errgroup" "github.com/vdaas/vald/internal/errors" @@ -34,11 +34,11 @@ type Gateway interface { Start(ctx context.Context) (<-chan error, error) GetAgentCount(ctx context.Context) int Do(ctx context.Context, - f func(ctx context.Context, tgt string, ac agent.AgentClient, copts ...grpc.CallOption) error) error + f func(ctx context.Context, tgt string, vc vald.ValdClient, copts ...grpc.CallOption) error) error DoMulti(ctx context.Context, num int, - f func(ctx context.Context, tgt string, ac agent.AgentClient, copts ...grpc.CallOption) error) error + f func(ctx context.Context, tgt string, vc vald.ValdClient, copts ...grpc.CallOption) error) error BroadCast(ctx context.Context, - f func(ctx context.Context, tgt string, ac agent.AgentClient, copts ...grpc.CallOption) error) error + f func(ctx context.Context, tgt string, vc vald.ValdClient, copts ...grpc.CallOption) error) error } type gateway struct { @@ -61,14 +61,14 @@ func (g *gateway) Start(ctx context.Context) (<-chan error, error) { } func (g *gateway) BroadCast(ctx context.Context, - f func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error) (err error) { + f func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error) (err error) { return g.client.GetClient().RangeConcurrent(ctx, -1, func(ctx context.Context, addr string, conn *grpc.ClientConn, copts ...grpc.CallOption) (err error) { select { case <-ctx.Done(): return nil default: - err = f(ctx, addr, agent.NewAgentClient(conn), copts...) + err = f(ctx, addr, vald.NewValdClient(conn), copts...) if err != nil { log.Debug(addr, err) return err @@ -79,17 +79,17 @@ func (g *gateway) BroadCast(ctx context.Context, } func (g *gateway) Do(ctx context.Context, - f func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error) (err error) { + f func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error) (err error) { addr := g.client.GetAddrs(ctx)[0] _, err = g.client.GetClient().Do(ctx, addr, func(ctx context.Context, conn *grpc.ClientConn, copts ...grpc.CallOption) (interface{}, error) { - return nil, f(ctx, addr, agent.NewAgentClient(conn), copts...) + return nil, f(ctx, addr, vald.NewValdClient(conn), copts...) }) return err } func (g *gateway) DoMulti(ctx context.Context, num int, - f func(ctx context.Context, target string, ac agent.AgentClient, copts ...grpc.CallOption) error) (err error) { + f func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error) (err error) { var cur uint32 = 0 limit := uint32(num) addrs := g.client.GetAddrs(ctx) @@ -99,7 +99,7 @@ func (g *gateway) DoMulti(ctx context.Context, num int, conn *grpc.ClientConn, copts ...grpc.CallOption) (err error) { if atomic.LoadUint32(&cur) < limit { - err = f(ictx, addr, agent.NewAgentClient(conn), copts...) + err = f(ictx, addr, vald.NewValdClient(conn), copts...) if err != nil { log.Debug(addr, err) return err diff --git a/pkg/gateway/vald/service/gateway_option_test.go b/pkg/gateway/vald/service/gateway_option_test.go new file mode 100644 index 00000000000..6ac318982a7 --- /dev/null +++ b/pkg/gateway/vald/service/gateway_option_test.go @@ -0,0 +1,254 @@ +// +// 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 service +package service + +import ( + "testing" + + "github.com/vdaas/vald/internal/client/discoverer" + "github.com/vdaas/vald/internal/errgroup" + "go.uber.org/goleak" +) + +func TestWithDiscoverer(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + c discoverer.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + c: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + c: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithDiscoverer(test.args.c) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithDiscoverer(test.args.c) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithErrGroup(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + eg errgroup.Group + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + eg: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithErrGroup(test.args.eg) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithErrGroup(test.args.eg) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/vald/service/gateway_test.go b/pkg/gateway/vald/service/gateway_test.go new file mode 100644 index 00000000000..730e991bf23 --- /dev/null +++ b/pkg/gateway/vald/service/gateway_test.go @@ -0,0 +1,562 @@ +// +// 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 service +package service + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/gateway/vald" + "github.com/vdaas/vald/internal/client/discoverer" + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestNewGateway(t *testing.T) { + type args struct { + opts []GWOption + } + type want struct { + wantGw Gateway + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Gateway, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotGw Gateway, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotGw, w.wantGw) { + return errors.Errorf("got = %v, want %v", gotGw, w.wantGw) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 + } + + gotGw, err := NewGateway(test.args.opts...) + if err := test.checkFunc(test.want, gotGw, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + got, err := g.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_BroadCast(t *testing.T) { + type args struct { + ctx context.Context + f func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + f: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + f: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + err := g.BroadCast(test.args.ctx, test.args.f) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_Do(t *testing.T) { + type args struct { + ctx context.Context + f func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + f: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + f: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + err := g.Do(test.args.ctx, test.args.f) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_DoMulti(t *testing.T) { + type args struct { + ctx context.Context + num int + f func(ctx context.Context, target string, vc vald.ValdClient, copts ...grpc.CallOption) error + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + num: 0, + f: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + num: 0, + f: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + err := g.DoMulti(test.args.ctx, test.args.num, test.args.f) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_gateway_GetAgentCount(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + client discoverer.Client + eg errgroup.Group + } + type want struct { + want int + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got int) 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 { + ctx: nil, + }, + fields: fields { + client: nil, + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + client: nil, + eg: 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 + } + g := &gateway{ + client: test.fields.client, + eg: test.fields.eg, + } + + got := g.GetAgentCount(test.args.ctx) + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/vald/service/meta_option_test.go b/pkg/gateway/vald/service/meta_option_test.go new file mode 100644 index 00000000000..9c022ce4983 --- /dev/null +++ b/pkg/gateway/vald/service/meta_option_test.go @@ -0,0 +1,827 @@ +// +// 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 service +package service + +import ( + "testing" + + "github.com/vdaas/vald/internal/cache" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestWithMetaAddr(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + addr string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + addr: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaAddr(test.args.addr) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaAddr(test.args.addr) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaHostPort(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + host string + port int + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + host: "", + port: 0, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + host: "", + port: 0, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaHostPort(test.args.host, test.args.port) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaHostPort(test.args.host, test.args.port) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaClient(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + client grpc.Client + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + client: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaClient(test.args.client) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaClient(test.args.client) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCacheEnabled(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + flg bool + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + flg: false, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + flg: false, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCacheEnabled(test.args.flg) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCacheEnabled(test.args.flg) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCache(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + c cache.Cache + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + c: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + c: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCache(test.args.c) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCache(test.args.c) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCacheExpireDuration(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + dur string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCacheExpireDuration(test.args.dur) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCacheExpireDuration(test.args.dur) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithMetaCacheExpiredCheckDuration(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + dur string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + 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) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithMetaCacheExpiredCheckDuration(test.args.dur) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithMetaCacheExpiredCheckDuration(test.args.dur) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/pkg/gateway/vald/service/meta_test.go b/pkg/gateway/vald/service/meta_test.go new file mode 100644 index 00000000000..2f6c63542ed --- /dev/null +++ b/pkg/gateway/vald/service/meta_test.go @@ -0,0 +1,1428 @@ +// +// 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 service provides meta service +package service + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/internal/cache" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc" + "go.uber.org/goleak" +) + +func TestNewMeta(t *testing.T) { + type args struct { + opts []MetaOption + } + type want struct { + wantMi Meta + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Meta, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotMi Meta, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotMi, w.wantMi) { + return errors.Errorf("got = %v, want %v", gotMi, w.wantMi) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: 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 + } + + gotMi, err := NewMeta(test.args.opts...) + if err := test.checkFunc(test.want, gotMi, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_Exists(t *testing.T) { + type args struct { + ctx context.Context + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want bool + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, bool, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got bool, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.Exists(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetMeta(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + wantV string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotV string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotV, w.wantV) { + return errors.Errorf("got = %v, want %v", gotV, w.wantV) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + gotV, err := m.GetMeta(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotV, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetMetas(t *testing.T) { + type args struct { + ctx context.Context + uuids []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.GetMetas(test.args.ctx, test.args.uuids...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetUUID(t *testing.T) { + type args struct { + ctx context.Context + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + wantK string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotK string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotK, w.wantK) { + return errors.Errorf("got = %v, want %v", gotK, w.wantK) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + gotK, err := m.GetUUID(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, gotK, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_GetUUIDs(t *testing.T) { + type args struct { + ctx context.Context + metas []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.GetUUIDs(test.args.ctx, test.args.metas...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_SetUUIDandMeta(t *testing.T) { + type args struct { + ctx context.Context + uuid string + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + err := m.SetUUIDandMeta(test.args.ctx, test.args.uuid, test.args.meta) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_SetUUIDandMetas(t *testing.T) { + type args struct { + ctx context.Context + kvs map[string]string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + kvs: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + kvs: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + err := m.SetUUIDandMetas(test.args.ctx, test.args.kvs) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteMeta(t *testing.T) { + type args struct { + ctx context.Context + uuid string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + wantV string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotV string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotV, w.wantV) { + return errors.Errorf("got = %v, want %v", gotV, w.wantV) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuid: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + gotV, err := m.DeleteMeta(test.args.ctx, test.args.uuid) + if err := test.checkFunc(test.want, gotV, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteMetas(t *testing.T) { + type args struct { + ctx context.Context + uuids []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + uuids: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.DeleteMetas(test.args.ctx, test.args.uuids...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteUUID(t *testing.T) { + type args struct { + ctx context.Context + meta string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + meta: "", + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.DeleteUUID(test.args.ctx, test.args.meta) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_meta_DeleteUUIDs(t *testing.T) { + type args struct { + ctx context.Context + metas []string + } + type fields struct { + addr string + client grpc.Client + cache cache.Cache + enableCache bool + expireCheckDuration string + expireDuration string + } + type want struct { + want []string + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, []string, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got []string, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + metas: nil, + }, + fields: fields { + addr: "", + client: nil, + cache: nil, + enableCache: false, + expireCheckDuration: "", + expireDuration: "", + }, + 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 + } + m := &meta{ + addr: test.fields.addr, + client: test.fields.client, + cache: test.fields.cache, + enableCache: test.fields.enableCache, + expireCheckDuration: test.fields.expireCheckDuration, + expireDuration: test.fields.expireDuration, + } + + got, err := m.DeleteUUIDs(test.args.ctx, test.args.metas...) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/gateway/vald/usecase/vald_test.go b/pkg/gateway/vald/usecase/vald_test.go new file mode 100644 index 00000000000..abdb9b17cd2 --- /dev/null +++ b/pkg/gateway/vald/usecase/vald_test.go @@ -0,0 +1,671 @@ +// +// 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 usecase + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/observability" + "github.com/vdaas/vald/internal/runner" + "github.com/vdaas/vald/internal/servers/starter" + "github.com/vdaas/vald/pkg/gateway/vald/config" + "github.com/vdaas/vald/pkg/gateway/vald/service" + "go.uber.org/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + cfg *config.Data + } + type want struct { + wantR runner.Runner + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, runner.Runner, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, gotR runner.Runner, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(gotR, w.wantR) { + return errors.Errorf("got = %v, want %v", gotR, w.wantR) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + cfg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + cfg: 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 + } + + gotR, err := New(test.args.cfg) + if err := test.checkFunc(test.want, gotR, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PreStart(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + err := r.PreStart(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + 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 { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + got, err := r.Start(test.args.ctx) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PreStop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + err := r.PreStop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_Stop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + err := r.Stop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PostStop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + filter service.Filter + gateway service.Gateway + metadata service.Meta + backup service.Backup + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + filter: nil, + gateway: nil, + metadata: nil, + backup: 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 + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + filter: test.fields.filter, + gateway: test.fields.gateway, + metadata: test.fields.metadata, + backup: test.fields.backup, + } + + err := r.PostStop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +}