diff --git a/cmd/index/job/correction/main_test.go b/cmd/index/job/correction/main_test.go new file mode 100644 index 0000000000..29d6625da1 --- /dev/null +++ b/cmd/index/job/correction/main_test.go @@ -0,0 +1,87 @@ +// Copyright (C) 2019-2023 vdaas.org vald team +// +// 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 correction + +// NOT IMPLEMENTED BELOW +// +// func Test_main(t *testing.T) { +// type want struct { +// } +// type test struct { +// name string +// want want +// checkFunc func(want) error +// beforeFunc func(*testing.T) +// afterFunc func(*testing.T) +// } +// defaultCheckFunc := func(w want) error { +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T,) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T,) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T,) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T,) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// +// main() +// if err := checkFunc(test.want); err != nil { +// tt.Errorf("error = %v", err) +// } +// }) +// } +// } diff --git a/cmd/index/job/creation/main_test.go b/cmd/index/job/creation/main_test.go new file mode 100644 index 0000000000..1609af5fe3 --- /dev/null +++ b/cmd/index/job/creation/main_test.go @@ -0,0 +1,87 @@ +// Copyright (C) 2019-2023 vdaas.org vald team +// +// 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 creation + +// NOT IMPLEMENTED BELOW +// +// func Test_main(t *testing.T) { +// type want struct { +// } +// type test struct { +// name string +// want want +// checkFunc func(want) error +// beforeFunc func(*testing.T) +// afterFunc func(*testing.T) +// } +// defaultCheckFunc := func(w want) error { +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T,) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T,) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T,) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T,) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// +// main() +// if err := checkFunc(test.want); err != nil { +// tt.Errorf("error = %v", err) +// } +// }) +// } +// } diff --git a/cmd/index/job/readreplica/rotate/main_test.go b/cmd/index/job/readreplica/rotate/main_test.go new file mode 100644 index 0000000000..37015f5d76 --- /dev/null +++ b/cmd/index/job/readreplica/rotate/main_test.go @@ -0,0 +1,87 @@ +// Copyright (C) 2019-2023 vdaas.org vald team +// +// 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 rotate + +// NOT IMPLEMENTED BELOW +// +// func Test_main(t *testing.T) { +// type want struct { +// } +// type test struct { +// name string +// want want +// checkFunc func(want) error +// beforeFunc func(*testing.T) +// afterFunc func(*testing.T) +// } +// defaultCheckFunc := func(w want) error { +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T,) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T,) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T,) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T,) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// +// main() +// if err := checkFunc(test.want); err != nil { +// tt.Errorf("error = %v", err) +// } +// }) +// } +// } diff --git a/cmd/index/job/save/main_test.go b/cmd/index/job/save/main_test.go new file mode 100644 index 0000000000..556461f15e --- /dev/null +++ b/cmd/index/job/save/main_test.go @@ -0,0 +1,87 @@ +// Copyright (C) 2019-2023 vdaas.org vald team +// +// 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 save + +// NOT IMPLEMENTED BELOW +// +// func Test_main(t *testing.T) { +// type want struct { +// } +// type test struct { +// name string +// want want +// checkFunc func(want) error +// beforeFunc func(*testing.T) +// afterFunc func(*testing.T) +// } +// defaultCheckFunc := func(w want) error { +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T,) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T,) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T,) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T,) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// +// main() +// if err := checkFunc(test.want); err != nil { +// tt.Errorf("error = %v", err) +// } +// }) +// } +// } diff --git a/cmd/tools/cli/benchmark/core/main_test.go b/cmd/tools/cli/benchmark/core/main_test.go index 8d8297becb..ef86d3b0a6 100644 --- a/cmd/tools/cli/benchmark/core/main_test.go +++ b/cmd/tools/cli/benchmark/core/main_test.go @@ -88,8 +88,14 @@ package main // // func Test_run(t *testing.T) { // type args struct { -// dur time.Duration -// output func(header string) +// ctx context.Context +// load bool +// path string +// dim int +// vectors [][]float32 +// ids []uint +// dur time.Duration +// output func(header string) // } // type want struct { // } @@ -110,6 +116,12 @@ package main // { // name: "test_case_1", // args: args { +// ctx:nil, +// load:false, +// path:"", +// dim:0, +// vectors:nil, +// ids:nil, // dur:nil, // output:nil, // }, @@ -130,6 +142,12 @@ package main // return test { // name: "test_case_2", // args: args { +// ctx:nil, +// load:false, +// path:"", +// dim:0, +// vectors:nil, +// ids:nil, // dur:nil, // output:nil, // }, @@ -162,7 +180,100 @@ package main // checkFunc = defaultCheckFunc // } // -// run(test.args.dur, test.args.output) +// run(test.args.ctx, test.args.load, test.args.path, test.args.dim, test.args.vectors, test.args.ids, test.args.dur, test.args.output) +// if err := checkFunc(test.want); err != nil { +// tt.Errorf("error = %v", err) +// } +// }) +// } +// } +// +// func Test_sleep(t *testing.T) { +// type args struct { +// ctx context.Context +// duration time.Duration +// limit time.Duration +// fn func() +// efn func() +// } +// type want struct { +// } +// type test struct { +// name string +// args args +// want want +// checkFunc func(want) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want) error { +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// ctx:nil, +// duration:nil, +// limit:nil, +// fn:nil, +// efn:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// ctx:nil, +// duration:nil, +// limit:nil, +// fn:nil, +// efn:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// +// sleep(test.args.ctx, test.args.duration, test.args.limit, test.args.fn, test.args.efn) // if err := checkFunc(test.want); err != nil { // tt.Errorf("error = %v", err) // } diff --git a/internal/client/v1/client/agent/core/client_test.go b/internal/client/v1/client/agent/core/client_test.go index 22fbde67df..2782ae2fc1 100644 --- a/internal/client/v1/client/agent/core/client_test.go +++ b/internal/client/v1/client/agent/core/client_test.go @@ -675,6 +675,123 @@ package core // } // } // +// func Test_agentClient_GetTimestamp(t *testing.T) { +// type args struct { +// ctx context.Context +// req *client.ObjectGetTimestampRequest +// in2 []grpc.CallOption +// } +// type fields struct { +// Client vald.Client +// addrs []string +// c grpc.Client +// } +// type want struct { +// wantRes *client.ObjectTimestamp +// err error +// } +// type test struct { +// name string +// args args +// fields fields +// want want +// checkFunc func(want, *client.ObjectTimestamp, error) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, gotRes *client.ObjectTimestamp, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// if !reflect.DeepEqual(gotRes, w.wantRes) { +// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotRes, w.wantRes) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// ctx:nil, +// req:nil, +// in2:nil, +// }, +// fields: fields { +// Client:nil, +// addrs:nil, +// c:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// ctx:nil, +// req:nil, +// in2:nil, +// }, +// fields: fields { +// Client:nil, +// addrs:nil, +// c:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// c := &agentClient{ +// Client: test.fields.Client, +// addrs: test.fields.addrs, +// c: test.fields.c, +// } +// +// gotRes, err := c.GetTimestamp(test.args.ctx, test.args.req, test.args.in2...) +// if err := checkFunc(test.want, gotRes, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } +// // func Test_singleAgentClient_CreateIndex(t *testing.T) { // type args struct { // ctx context.Context @@ -1126,3 +1243,116 @@ package core // }) // } // } +// +// func Test_singleAgentClient_GetTimestamp(t *testing.T) { +// type args struct { +// ctx context.Context +// req *client.ObjectGetTimestampRequest +// opts []grpc.CallOption +// } +// type fields struct { +// Client vald.Client +// ac agent.AgentClient +// } +// type want struct { +// wantRes *client.ObjectTimestamp +// err error +// } +// type test struct { +// name string +// args args +// fields fields +// want want +// checkFunc func(want, *client.ObjectTimestamp, error) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, gotRes *client.ObjectTimestamp, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// if !reflect.DeepEqual(gotRes, w.wantRes) { +// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotRes, w.wantRes) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// ctx:nil, +// req:nil, +// opts:nil, +// }, +// fields: fields { +// Client:nil, +// ac:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// ctx:nil, +// req:nil, +// opts:nil, +// }, +// fields: fields { +// Client:nil, +// ac:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// c := &singleAgentClient{ +// Client: test.fields.Client, +// ac: test.fields.ac, +// } +// +// gotRes, err := c.GetTimestamp(test.args.ctx, test.args.req, test.args.opts...) +// if err := checkFunc(test.want, gotRes, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } diff --git a/internal/config/corrector_test.go b/internal/config/corrector_test.go index a0725a19d7..27751abb0f 100644 --- a/internal/config/corrector_test.go +++ b/internal/config/corrector_test.go @@ -17,15 +17,15 @@ package config // // func TestCorrector_Bind(t *testing.T) { // type fields struct { -// AgentPort int -// AgentName string -// AgentNamespace string -// AgentDNS string -// NodeName string -// StreamListConcurrency int -// KvsAsyncWriteConcurrency int -// IndexReplica int -// Discoverer *DiscovererClient +// AgentPort int +// AgentName string +// AgentNamespace string +// AgentDNS string +// NodeName string +// StreamListConcurrency int +// KvsAsyncWriteConcurrency int +// IndexReplica int +// Discoverer *DiscovererClient // } // type want struct { // want *Corrector @@ -116,15 +116,15 @@ package config // checkFunc = defaultCheckFunc // } // c := &Corrector{ -// AgentPort: test.fields.AgentPort, -// AgentName: test.fields.AgentName, -// AgentNamespace: test.fields.AgentNamespace, -// AgentDNS: test.fields.AgentDNS, -// NodeName: test.fields.NodeName, -// StreamListConcurrency: test.fields.StreamListConcurrency, -// KvsAsyncWriteConcurrency: test.fields.KvsAsyncWriteConcurrency, -// IndexReplica: test.fields.IndexReplica, -// Discoverer: test.fields.Discoverer, +// AgentPort: test.fields.AgentPort, +// AgentName: test.fields.AgentName, +// AgentNamespace: test.fields.AgentNamespace, +// AgentDNS: test.fields.AgentDNS, +// NodeName: test.fields.NodeName, +// StreamListConcurrency: test.fields.StreamListConcurrency, +// KvsAsyncWriteConcurrency: test.fields.KvsAsyncWriteConcurrency, +// IndexReplica: test.fields.IndexReplica, +// Discoverer: test.fields.Discoverer, // } // // got := c.Bind() diff --git a/internal/config/readreplica_rotate_test.go b/internal/config/readreplica_rotate_test.go index 586eff9162..cdf0458f12 100644 --- a/internal/config/readreplica_rotate_test.go +++ b/internal/config/readreplica_rotate_test.go @@ -15,7 +15,7 @@ package config // NOT IMPLEMENTED BELOW // -// func TestReadreplicaRotate_Bind(t *testing.T) { +// func TestReadReplicaRotate_Bind(t *testing.T) { // type fields struct { // AgentNamespace string // ReadReplicaLabelKey string @@ -23,17 +23,17 @@ package config // VolumeName string // } // type want struct { -// want *ReadreplicaRotate +// want *ReadReplicaRotate // } // type test struct { // name string // fields fields // want want -// checkFunc func(want, *ReadreplicaRotate) error +// checkFunc func(want, *ReadReplicaRotate) error // beforeFunc func(*testing.T) // afterFunc func(*testing.T) // } -// defaultCheckFunc := func(w want, got *ReadreplicaRotate) error { +// defaultCheckFunc := func(w want, got *ReadReplicaRotate) error { // if !reflect.DeepEqual(got, w.want) { // return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) // } @@ -100,7 +100,7 @@ package config // if test.checkFunc == nil { // checkFunc = defaultCheckFunc // } -// r := &ReadreplicaRotate{ +// r := &ReadReplicaRotate{ // AgentNamespace: test.fields.AgentNamespace, // ReadReplicaLabelKey: test.fields.ReadReplicaLabelKey, // ReadReplicaID: test.fields.ReadReplicaID, diff --git a/internal/k8s/client/client_test.go b/internal/k8s/client/client_test.go new file mode 100644 index 0000000000..1feec7b39f --- /dev/null +++ b/internal/k8s/client/client_test.go @@ -0,0 +1,911 @@ +// Copyright (C) 2019-2023 vdaas.org vald team +// +// 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 client + +// NOT IMPLEMENTED BELOW +// +// func TestNew(t *testing.T) { +// type args struct { +// opts []Option +// } +// type want struct { +// want Client +// err error +// } +// type test struct { +// name string +// args args +// want want +// checkFunc func(want, Client, error) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, got Client, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// if !reflect.DeepEqual(got, w.want) { +// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// opts:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// opts:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// +// got, err := New(test.args.opts...) +// if err := checkFunc(test.want, got, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } +// +// func Test_client_Get(t *testing.T) { +// type args struct { +// ctx context.Context +// name string +// namespace string +// obj cli.Object +// opts []cli.GetOption +// } +// type fields struct { +// scheme *runtime.Scheme +// reader cli.Reader +// withWatch cli.WithWatch +// } +// type want struct { +// err error +// } +// type test struct { +// name string +// args args +// fields fields +// want want +// checkFunc func(want, error) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// ctx:nil, +// name:"", +// namespace:"", +// obj:nil, +// opts:nil, +// }, +// fields: fields { +// scheme:nil, +// reader:nil, +// withWatch:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// ctx:nil, +// name:"", +// namespace:"", +// obj:nil, +// opts:nil, +// }, +// fields: fields { +// scheme:nil, +// reader:nil, +// withWatch:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// c := &client{ +// scheme: test.fields.scheme, +// reader: test.fields.reader, +// withWatch: test.fields.withWatch, +// } +// +// err := c.Get(test.args.ctx, test.args.name, test.args.namespace, test.args.obj, test.args.opts...) +// if err := checkFunc(test.want, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } +// +// func Test_client_List(t *testing.T) { +// type args struct { +// ctx context.Context +// list cli.ObjectList +// opts []cli.ListOption +// } +// type fields struct { +// scheme *runtime.Scheme +// reader cli.Reader +// withWatch cli.WithWatch +// } +// type want struct { +// err error +// } +// type test struct { +// name string +// args args +// fields fields +// want want +// checkFunc func(want, error) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// ctx:nil, +// list:nil, +// opts:nil, +// }, +// fields: fields { +// scheme:nil, +// reader:nil, +// withWatch:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// ctx:nil, +// list:nil, +// opts:nil, +// }, +// fields: fields { +// scheme:nil, +// reader:nil, +// withWatch:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// c := &client{ +// scheme: test.fields.scheme, +// reader: test.fields.reader, +// withWatch: test.fields.withWatch, +// } +// +// err := c.List(test.args.ctx, test.args.list, test.args.opts...) +// if err := checkFunc(test.want, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } +// +// func Test_client_Create(t *testing.T) { +// type args struct { +// ctx context.Context +// obj Object +// opts []CreateOption +// } +// type fields struct { +// scheme *runtime.Scheme +// reader cli.Reader +// withWatch cli.WithWatch +// } +// type want struct { +// err error +// } +// type test struct { +// name string +// args args +// fields fields +// want want +// checkFunc func(want, error) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// ctx:nil, +// obj:nil, +// opts:nil, +// }, +// fields: fields { +// scheme:nil, +// reader:nil, +// withWatch:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// ctx:nil, +// obj:nil, +// opts:nil, +// }, +// fields: fields { +// scheme:nil, +// reader:nil, +// withWatch:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// c := &client{ +// scheme: test.fields.scheme, +// reader: test.fields.reader, +// withWatch: test.fields.withWatch, +// } +// +// err := c.Create(test.args.ctx, test.args.obj, test.args.opts...) +// if err := checkFunc(test.want, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } +// +// func Test_client_Delete(t *testing.T) { +// type args struct { +// ctx context.Context +// obj Object +// opts []cli.DeleteOption +// } +// type fields struct { +// scheme *runtime.Scheme +// reader cli.Reader +// withWatch cli.WithWatch +// } +// type want struct { +// err error +// } +// type test struct { +// name string +// args args +// fields fields +// want want +// checkFunc func(want, error) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// ctx:nil, +// obj:nil, +// opts:nil, +// }, +// fields: fields { +// scheme:nil, +// reader:nil, +// withWatch:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// ctx:nil, +// obj:nil, +// opts:nil, +// }, +// fields: fields { +// scheme:nil, +// reader:nil, +// withWatch:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// c := &client{ +// scheme: test.fields.scheme, +// reader: test.fields.reader, +// withWatch: test.fields.withWatch, +// } +// +// err := c.Delete(test.args.ctx, test.args.obj, test.args.opts...) +// if err := checkFunc(test.want, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } +// +// func Test_client_Update(t *testing.T) { +// type args struct { +// ctx context.Context +// obj Object +// opts []cli.UpdateOption +// } +// type fields struct { +// scheme *runtime.Scheme +// reader cli.Reader +// withWatch cli.WithWatch +// } +// type want struct { +// err error +// } +// type test struct { +// name string +// args args +// fields fields +// want want +// checkFunc func(want, error) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// ctx:nil, +// obj:nil, +// opts:nil, +// }, +// fields: fields { +// scheme:nil, +// reader:nil, +// withWatch:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// ctx:nil, +// obj:nil, +// opts:nil, +// }, +// fields: fields { +// scheme:nil, +// reader:nil, +// withWatch:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// c := &client{ +// scheme: test.fields.scheme, +// reader: test.fields.reader, +// withWatch: test.fields.withWatch, +// } +// +// err := c.Update(test.args.ctx, test.args.obj, test.args.opts...) +// if err := checkFunc(test.want, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } +// +// func Test_client_Watch(t *testing.T) { +// type args struct { +// ctx context.Context +// obj cli.ObjectList +// opts []ListOption +// } +// type fields struct { +// scheme *runtime.Scheme +// reader cli.Reader +// withWatch cli.WithWatch +// } +// type want struct { +// want watch.Interface +// err error +// } +// type test struct { +// name string +// args args +// fields fields +// want want +// checkFunc func(want, watch.Interface, error) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, got watch.Interface, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// if !reflect.DeepEqual(got, w.want) { +// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// ctx:nil, +// obj:nil, +// opts:nil, +// }, +// fields: fields { +// scheme:nil, +// reader:nil, +// withWatch:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// ctx:nil, +// obj:nil, +// opts:nil, +// }, +// fields: fields { +// scheme:nil, +// reader:nil, +// withWatch:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// c := &client{ +// scheme: test.fields.scheme, +// reader: test.fields.reader, +// withWatch: test.fields.withWatch, +// } +// +// got, err := c.Watch(test.args.ctx, test.args.obj, test.args.opts...) +// if err := checkFunc(test.want, got, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } +// +// func Test_client_LabelSelector(t *testing.T) { +// type args struct { +// key string +// op selection.Operator +// vals []string +// } +// type fields struct { +// scheme *runtime.Scheme +// reader cli.Reader +// withWatch cli.WithWatch +// } +// type want struct { +// want labels.Selector +// err error +// } +// type test struct { +// name string +// args args +// fields fields +// want want +// checkFunc func(want, labels.Selector, error) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, got labels.Selector, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// if !reflect.DeepEqual(got, w.want) { +// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// key:"", +// op:nil, +// vals:nil, +// }, +// fields: fields { +// scheme:nil, +// reader:nil, +// withWatch:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// key:"", +// op:nil, +// vals:nil, +// }, +// fields: fields { +// scheme:nil, +// reader:nil, +// withWatch:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// c := &client{ +// scheme: test.fields.scheme, +// reader: test.fields.reader, +// withWatch: test.fields.withWatch, +// } +// +// got, err := c.LabelSelector(test.args.key, test.args.op, test.args.vals) +// if err := checkFunc(test.want, got, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } diff --git a/internal/k8s/client/option_test.go b/internal/k8s/client/option_test.go new file mode 100644 index 0000000000..bd009daa9c --- /dev/null +++ b/internal/k8s/client/option_test.go @@ -0,0 +1,102 @@ +// Copyright (C) 2019-2023 vdaas.org vald team +// +// 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 client + +// NOT IMPLEMENTED BELOW +// +// func TestWithSchemeBuilder(t *testing.T) { +// type args struct { +// sb scheme.Builder +// } +// type want struct { +// want Option +// } +// type test struct { +// name string +// args args +// want want +// checkFunc func(want, Option) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, got Option) error { +// if !reflect.DeepEqual(got, w.want) { +// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// sb:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// sb:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// +// got := WithSchemeBuilder(test.args.sb) +// if err := checkFunc(test.want, got); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } diff --git a/internal/net/grpc/client_test.go b/internal/net/grpc/client_test.go index a118cc29de..d6a54e384d 100644 --- a/internal/net/grpc/client_test.go +++ b/internal/net/grpc/client_test.go @@ -113,7 +113,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -167,7 +167,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -210,7 +210,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -301,7 +301,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -352,7 +352,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -396,7 +396,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -488,7 +488,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -540,7 +540,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -585,7 +585,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -677,7 +677,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -729,7 +729,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -774,7 +774,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -867,7 +867,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -920,7 +920,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -966,7 +966,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -1057,7 +1057,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -1112,7 +1112,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -1156,7 +1156,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -1248,7 +1248,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -1304,7 +1304,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -1349,7 +1349,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -1443,7 +1443,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -1501,7 +1501,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -1548,7 +1548,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -1635,7 +1635,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -1681,7 +1681,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -1721,7 +1721,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -1808,7 +1808,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -1854,7 +1854,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -1894,7 +1894,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -1981,7 +1981,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -2027,7 +2027,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -2067,7 +2067,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -2159,7 +2159,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -2215,7 +2215,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -2260,7 +2260,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -2351,7 +2351,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -2402,7 +2402,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -2446,7 +2446,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -2537,7 +2537,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -2588,7 +2588,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -2632,7 +2632,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -2719,7 +2719,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -2765,7 +2765,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -2805,7 +2805,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -2895,7 +2895,7 @@ package grpc // addrs map[string]struct{} // poolSize uint64 // clientCount uint64 -// conns grpcConns +// conns sync.Map[string, pool.Conn] // hcDur time.Duration // prDur time.Duration // dialer net.Dialer @@ -2945,7 +2945,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -2988,7 +2988,7 @@ package grpc // addrs:nil, // poolSize:0, // clientCount:0, -// conns:grpcConns{}, +// conns:nil, // hcDur:nil, // prDur:nil, // dialer:nil, @@ -3069,3 +3069,186 @@ package grpc // }) // } // } +// +// func Test_gRPCClient_rangeConns(t *testing.T) { +// type args struct { +// fn func(addr string, p pool.Conn) bool +// } +// type fields struct { +// addrs map[string]struct{} +// poolSize uint64 +// clientCount uint64 +// conns sync.Map[string, pool.Conn] +// hcDur time.Duration +// prDur time.Duration +// dialer net.Dialer +// enablePoolRebalance bool +// resolveDNS bool +// dopts []DialOption +// copts []CallOption +// roccd string +// eg errgroup.Group +// bo backoff.Backoff +// cb circuitbreaker.CircuitBreaker +// gbo gbackoff.Config +// mcd time.Duration +// group singleflight.Group[pool.Conn] +// crl sync.Map[string, bool] +// ech <-chan error +// monitorRunning atomic.Bool +// stopMonitor context.CancelFunc +// } +// type want struct { +// err error +// } +// type test struct { +// name string +// args args +// fields fields +// want want +// checkFunc func(want, error) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// fn:nil, +// }, +// fields: fields { +// addrs:nil, +// poolSize:0, +// clientCount:0, +// conns:nil, +// hcDur:nil, +// prDur:nil, +// dialer:nil, +// enablePoolRebalance:false, +// resolveDNS:false, +// dopts:nil, +// copts:nil, +// roccd:"", +// eg:nil, +// bo:nil, +// cb:nil, +// gbo:nil, +// mcd:nil, +// group:nil, +// crl:nil, +// ech:nil, +// monitorRunning:nil, +// stopMonitor:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// fn:nil, +// }, +// fields: fields { +// addrs:nil, +// poolSize:0, +// clientCount:0, +// conns:nil, +// hcDur:nil, +// prDur:nil, +// dialer:nil, +// enablePoolRebalance:false, +// resolveDNS:false, +// dopts:nil, +// copts:nil, +// roccd:"", +// eg:nil, +// bo:nil, +// cb:nil, +// gbo:nil, +// mcd:nil, +// group:nil, +// crl:nil, +// ech:nil, +// monitorRunning:nil, +// stopMonitor:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// g := &gRPCClient{ +// addrs: test.fields.addrs, +// poolSize: test.fields.poolSize, +// clientCount: test.fields.clientCount, +// conns: test.fields.conns, +// hcDur: test.fields.hcDur, +// prDur: test.fields.prDur, +// dialer: test.fields.dialer, +// enablePoolRebalance: test.fields.enablePoolRebalance, +// resolveDNS: test.fields.resolveDNS, +// dopts: test.fields.dopts, +// copts: test.fields.copts, +// roccd: test.fields.roccd, +// eg: test.fields.eg, +// bo: test.fields.bo, +// cb: test.fields.cb, +// gbo: test.fields.gbo, +// mcd: test.fields.mcd, +// group: test.fields.group, +// crl: test.fields.crl, +// ech: test.fields.ech, +// monitorRunning: test.fields.monitorRunning, +// stopMonitor: test.fields.stopMonitor, +// } +// +// err := g.rangeConns(test.args.fn) +// if err := checkFunc(test.want, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } diff --git a/internal/net/grpc/proto/proto_test.go b/internal/net/grpc/proto/proto_test.go index 5a8bb5a863..22d756572e 100644 --- a/internal/net/grpc/proto/proto_test.go +++ b/internal/net/grpc/proto/proto_test.go @@ -339,3 +339,89 @@ func TestToMessageV1(t *testing.T) { } // NOT IMPLEMENTED BELOW +// +// func TestToMessageV2(t *testing.T) { +// type args struct { +// m MessageV1 +// } +// type want struct { +// want Message +// } +// type test struct { +// name string +// args args +// want want +// checkFunc func(want, Message) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, got Message) error { +// if !reflect.DeepEqual(got, w.want) { +// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// m:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// m:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// +// got := ToMessageV2(test.args.m) +// if err := checkFunc(test.want, got); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } diff --git a/internal/net/grpc/stream_test.go b/internal/net/grpc/stream_test.go index c65aebd935..27438cbdde 100644 --- a/internal/net/grpc/stream_test.go +++ b/internal/net/grpc/stream_test.go @@ -295,92 +295,3 @@ func TestBidirectionalStream(t *testing.T) { // }) // } // } -// -// func Test_removeDuplicates(t *testing.T) { -// type args struct { -// x S -// less func(left, right E) int -// } -// type want struct { -// want S -// } -// type test struct { -// name string -// args args -// want want -// checkFunc func(want, S) error -// beforeFunc func(*testing.T, args) -// afterFunc func(*testing.T, args) -// } -// defaultCheckFunc := func(w want, got S) error { -// if !reflect.DeepEqual(got, w.want) { -// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) -// } -// return nil -// } -// tests := []test{ -// // TODO test cases -// /* -// { -// name: "test_case_1", -// args: args { -// x:nil, -// less:nil, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// }, -// */ -// -// // TODO test cases -// /* -// func() test { -// return test { -// name: "test_case_2", -// args: args { -// x:nil, -// less:nil, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// } -// }(), -// */ -// } -// -// for _, tc := range tests { -// test := tc -// t.Run(test.name, func(tt *testing.T) { -// tt.Parallel() -// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) -// if test.beforeFunc != nil { -// test.beforeFunc(tt, test.args) -// } -// if test.afterFunc != nil { -// defer test.afterFunc(tt, test.args) -// } -// checkFunc := test.checkFunc -// if test.checkFunc == nil { -// checkFunc = defaultCheckFunc -// } -// -// got := removeDuplicates(test.args.x, test.args.less) -// if err := checkFunc(test.want, got); err != nil { -// tt.Errorf("error = %v", err) -// } -// -// }) -// } -// } diff --git a/internal/observability/metrics/index/job/correction/correction_test.go b/internal/observability/metrics/index/job/correction/correction_test.go new file mode 100644 index 0000000000..1b41d0b73c --- /dev/null +++ b/internal/observability/metrics/index/job/correction/correction_test.go @@ -0,0 +1,294 @@ +// Copyright (C) 2019-2023 vdaas.org vald team +// +// 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 correction + +// NOT IMPLEMENTED BELOW +// +// func TestNew(t *testing.T) { +// type args struct { +// c service.Corrector +// } +// type want struct { +// want metrics.Metric +// } +// type test struct { +// name string +// args args +// want want +// checkFunc func(want, metrics.Metric) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, got metrics.Metric) error { +// if !reflect.DeepEqual(got, w.want) { +// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// c:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// c:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// +// got := New(test.args.c) +// if err := checkFunc(test.want, got); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } +// +// func Test_correctionMetrics_View(t *testing.T) { +// type fields struct { +// correction service.Corrector +// } +// type want struct { +// want []*metrics.View +// err error +// } +// type test struct { +// name string +// fields fields +// want want +// checkFunc func(want, []*metrics.View, error) error +// beforeFunc func(*testing.T) +// afterFunc func(*testing.T) +// } +// defaultCheckFunc := func(w want, got []*metrics.View, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// if !reflect.DeepEqual(got, w.want) { +// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// fields: fields { +// correction:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T,) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T,) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// fields: fields { +// correction:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T,) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T,) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// c := &correctionMetrics{ +// correction: test.fields.correction, +// } +// +// got, err := c.View() +// if err := checkFunc(test.want, got, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } +// +// func Test_correctionMetrics_Register(t *testing.T) { +// type args struct { +// m metrics.Meter +// } +// type fields struct { +// correction service.Corrector +// } +// type want struct { +// err error +// } +// type test struct { +// name string +// args args +// fields fields +// want want +// checkFunc func(want, error) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// m:nil, +// }, +// fields: fields { +// correction:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// m:nil, +// }, +// fields: fields { +// correction:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// c := &correctionMetrics{ +// correction: test.fields.correction, +// } +// +// err := c.Register(test.args.m) +// if err := checkFunc(test.want, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } diff --git a/pkg/agent/core/ngt/handler/grpc/object_test.go b/pkg/agent/core/ngt/handler/grpc/object_test.go index 6626949efd..233349c3b3 100644 --- a/pkg/agent/core/ngt/handler/grpc/object_test.go +++ b/pkg/agent/core/ngt/handler/grpc/object_test.go @@ -1455,10 +1455,9 @@ func Test_server_GetTimestamp(t *testing.T) { // NOT IMPLEMENTED BELOW // -// func Test_server_StreamListObject(t *testing.T) { +// func Test_server_StreamGetObject(t *testing.T) { // type args struct { -// in0 *payload.Object_List_Request -// stream vald.Object_StreamListObjectServer +// stream vald.Object_StreamGetObjectServer // } // type fields struct { // name string @@ -1493,7 +1492,6 @@ func Test_server_GetTimestamp(t *testing.T) { // { // name: "test_case_1", // args: args { -// in0:nil, // stream:nil, // }, // fields: fields { @@ -1522,7 +1520,6 @@ func Test_server_GetTimestamp(t *testing.T) { // return test { // name: "test_case_2", // args: args { -// in0:nil, // stream:nil, // }, // fields: fields { @@ -1572,7 +1569,7 @@ func Test_server_GetTimestamp(t *testing.T) { // UnimplementedValdServer: test.fields.UnimplementedValdServer, // } // -// err := s.StreamListObject(test.args.in0, test.args.stream) +// err := s.StreamGetObject(test.args.stream) // if err := checkFunc(test.want, err); err != nil { // tt.Errorf("error = %v", err) // } diff --git a/pkg/gateway/lb/handler/grpc/handler_test.go b/pkg/gateway/lb/handler/grpc/handler_test.go index 928adb73e0..bb35ec7136 100644 --- a/pkg/gateway/lb/handler/grpc/handler_test.go +++ b/pkg/gateway/lb/handler/grpc/handler_test.go @@ -3901,3 +3901,137 @@ package grpc // }) // } // } +// +// func Test_server_StreamListObject(t *testing.T) { +// type args struct { +// req *payload.Object_List_Request +// stream vald.Object_StreamListObjectServer +// } +// type fields struct { +// eg errgroup.Group +// gateway service.Gateway +// timeout time.Duration +// replica int +// streamConcurrency int +// multiConcurrency int +// name string +// ip string +// UnimplementedValdServer vald.UnimplementedValdServer +// } +// type want struct { +// err error +// } +// type test struct { +// name string +// args args +// fields fields +// want want +// checkFunc func(want, error) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// req:nil, +// stream:nil, +// }, +// fields: fields { +// eg:nil, +// gateway:nil, +// timeout:nil, +// replica:0, +// streamConcurrency:0, +// multiConcurrency:0, +// name:"", +// ip:"", +// UnimplementedValdServer:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// req:nil, +// stream:nil, +// }, +// fields: fields { +// eg:nil, +// gateway:nil, +// timeout:nil, +// replica:0, +// streamConcurrency:0, +// multiConcurrency:0, +// name:"", +// ip:"", +// UnimplementedValdServer:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// s := &server{ +// eg: test.fields.eg, +// gateway: test.fields.gateway, +// timeout: test.fields.timeout, +// replica: test.fields.replica, +// streamConcurrency: test.fields.streamConcurrency, +// multiConcurrency: test.fields.multiConcurrency, +// name: test.fields.name, +// ip: test.fields.ip, +// UnimplementedValdServer: test.fields.UnimplementedValdServer, +// } +// +// err := s.StreamListObject(test.args.req, test.args.stream) +// if err := checkFunc(test.want, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// } diff --git a/pkg/index/job/correction/service/corrector_test.go b/pkg/index/job/correction/service/corrector_test.go index a249d59f60..eab80e6fab 100644 --- a/pkg/index/job/correction/service/corrector_test.go +++ b/pkg/index/job/correction/service/corrector_test.go @@ -561,7 +561,7 @@ func Test_correct_correctReplica(t *testing.T) { // type fields struct { // discoverer discoverer.Client // agentAddrs []string -// indexInfos sync.Map[string, *payload.Info_Index_Count] +// sortedByIndexCntAddrs []string // uuidsCount uint32 // uncommittedUUIDsCount uint32 // checkedID bbolt.Bbolt @@ -605,7 +605,7 @@ func Test_correct_correctReplica(t *testing.T) { // fields: fields { // discoverer:nil, // agentAddrs:nil, -// indexInfos:nil, +// sortedByIndexCntAddrs:nil, // uuidsCount:0, // uncommittedUUIDsCount:0, // checkedID:nil, @@ -638,7 +638,7 @@ func Test_correct_correctReplica(t *testing.T) { // fields: fields { // discoverer:nil, // agentAddrs:nil, -// indexInfos:nil, +// sortedByIndexCntAddrs:nil, // uuidsCount:0, // uncommittedUUIDsCount:0, // checkedID:nil, @@ -680,7 +680,7 @@ func Test_correct_correctReplica(t *testing.T) { // c := &correct{ // discoverer: test.fields.discoverer, // agentAddrs: test.fields.agentAddrs, -// indexInfos: test.fields.indexInfos, +// sortedByIndexCntAddrs: test.fields.sortedByIndexCntAddrs, // uuidsCount: test.fields.uuidsCount, // uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, // checkedID: test.fields.checkedID, @@ -708,7 +708,7 @@ func Test_correct_correctReplica(t *testing.T) { // type fields struct { // discoverer discoverer.Client // agentAddrs []string -// indexInfos sync.Map[string, *payload.Info_Index_Count] +// sortedByIndexCntAddrs []string // uuidsCount uint32 // uncommittedUUIDsCount uint32 // checkedID bbolt.Bbolt @@ -748,7 +748,7 @@ func Test_correct_correctReplica(t *testing.T) { // fields: fields { // discoverer:nil, // agentAddrs:nil, -// indexInfos:nil, +// sortedByIndexCntAddrs:nil, // uuidsCount:0, // uncommittedUUIDsCount:0, // checkedID:nil, @@ -781,7 +781,7 @@ func Test_correct_correctReplica(t *testing.T) { // fields: fields { // discoverer:nil, // agentAddrs:nil, -// indexInfos:nil, +// sortedByIndexCntAddrs:nil, // uuidsCount:0, // uncommittedUUIDsCount:0, // checkedID:nil, @@ -823,7 +823,7 @@ func Test_correct_correctReplica(t *testing.T) { // c := &correct{ // discoverer: test.fields.discoverer, // agentAddrs: test.fields.agentAddrs, -// indexInfos: test.fields.indexInfos, +// sortedByIndexCntAddrs: test.fields.sortedByIndexCntAddrs, // uuidsCount: test.fields.uuidsCount, // uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, // checkedID: test.fields.checkedID, @@ -851,7 +851,7 @@ func Test_correct_correctReplica(t *testing.T) { // type fields struct { // discoverer discoverer.Client // agentAddrs []string -// indexInfos sync.Map[string, *payload.Info_Index_Count] +// sortedByIndexCntAddrs []string // uuidsCount uint32 // uncommittedUUIDsCount uint32 // checkedID bbolt.Bbolt @@ -891,7 +891,7 @@ func Test_correct_correctReplica(t *testing.T) { // fields: fields { // discoverer:nil, // agentAddrs:nil, -// indexInfos:nil, +// sortedByIndexCntAddrs:nil, // uuidsCount:0, // uncommittedUUIDsCount:0, // checkedID:nil, @@ -924,7 +924,7 @@ func Test_correct_correctReplica(t *testing.T) { // fields: fields { // discoverer:nil, // agentAddrs:nil, -// indexInfos:nil, +// sortedByIndexCntAddrs:nil, // uuidsCount:0, // uncommittedUUIDsCount:0, // checkedID:nil, @@ -966,7 +966,7 @@ func Test_correct_correctReplica(t *testing.T) { // c := &correct{ // discoverer: test.fields.discoverer, // agentAddrs: test.fields.agentAddrs, -// indexInfos: test.fields.indexInfos, +// sortedByIndexCntAddrs: test.fields.sortedByIndexCntAddrs, // uuidsCount: test.fields.uuidsCount, // uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, // checkedID: test.fields.checkedID, @@ -991,7 +991,7 @@ func Test_correct_correctReplica(t *testing.T) { // type fields struct { // discoverer discoverer.Client // agentAddrs []string -// indexInfos sync.Map[string, *payload.Info_Index_Count] +// sortedByIndexCntAddrs []string // uuidsCount uint32 // uncommittedUUIDsCount uint32 // checkedID bbolt.Bbolt @@ -1027,7 +1027,7 @@ func Test_correct_correctReplica(t *testing.T) { // fields: fields { // discoverer:nil, // agentAddrs:nil, -// indexInfos:nil, +// sortedByIndexCntAddrs:nil, // uuidsCount:0, // uncommittedUUIDsCount:0, // checkedID:nil, @@ -1057,7 +1057,7 @@ func Test_correct_correctReplica(t *testing.T) { // fields: fields { // discoverer:nil, // agentAddrs:nil, -// indexInfos:nil, +// sortedByIndexCntAddrs:nil, // uuidsCount:0, // uncommittedUUIDsCount:0, // checkedID:nil, @@ -1099,7 +1099,7 @@ func Test_correct_correctReplica(t *testing.T) { // c := &correct{ // discoverer: test.fields.discoverer, // agentAddrs: test.fields.agentAddrs, -// indexInfos: test.fields.indexInfos, +// sortedByIndexCntAddrs: test.fields.sortedByIndexCntAddrs, // uuidsCount: test.fields.uuidsCount, // uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, // checkedID: test.fields.checkedID, @@ -1124,7 +1124,7 @@ func Test_correct_correctReplica(t *testing.T) { // type fields struct { // discoverer discoverer.Client // agentAddrs []string -// indexInfos sync.Map[string, *payload.Info_Index_Count] +// sortedByIndexCntAddrs []string // uuidsCount uint32 // uncommittedUUIDsCount uint32 // checkedID bbolt.Bbolt @@ -1160,7 +1160,7 @@ func Test_correct_correctReplica(t *testing.T) { // fields: fields { // discoverer:nil, // agentAddrs:nil, -// indexInfos:nil, +// sortedByIndexCntAddrs:nil, // uuidsCount:0, // uncommittedUUIDsCount:0, // checkedID:nil, @@ -1190,7 +1190,7 @@ func Test_correct_correctReplica(t *testing.T) { // fields: fields { // discoverer:nil, // agentAddrs:nil, -// indexInfos:nil, +// sortedByIndexCntAddrs:nil, // uuidsCount:0, // uncommittedUUIDsCount:0, // checkedID:nil, @@ -1232,7 +1232,7 @@ func Test_correct_correctReplica(t *testing.T) { // c := &correct{ // discoverer: test.fields.discoverer, // agentAddrs: test.fields.agentAddrs, -// indexInfos: test.fields.indexInfos, +// sortedByIndexCntAddrs: test.fields.sortedByIndexCntAddrs, // uuidsCount: test.fields.uuidsCount, // uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, // checkedID: test.fields.checkedID, @@ -1257,7 +1257,7 @@ func Test_correct_correctReplica(t *testing.T) { // type fields struct { // discoverer discoverer.Client // agentAddrs []string -// indexInfos sync.Map[string, *payload.Info_Index_Count] +// sortedByIndexCntAddrs []string // uuidsCount uint32 // uncommittedUUIDsCount uint32 // checkedID bbolt.Bbolt @@ -1293,7 +1293,7 @@ func Test_correct_correctReplica(t *testing.T) { // fields: fields { // discoverer:nil, // agentAddrs:nil, -// indexInfos:nil, +// sortedByIndexCntAddrs:nil, // uuidsCount:0, // uncommittedUUIDsCount:0, // checkedID:nil, @@ -1323,7 +1323,7 @@ func Test_correct_correctReplica(t *testing.T) { // fields: fields { // discoverer:nil, // agentAddrs:nil, -// indexInfos:nil, +// sortedByIndexCntAddrs:nil, // uuidsCount:0, // uncommittedUUIDsCount:0, // checkedID:nil, @@ -1365,7 +1365,7 @@ func Test_correct_correctReplica(t *testing.T) { // c := &correct{ // discoverer: test.fields.discoverer, // agentAddrs: test.fields.agentAddrs, -// indexInfos: test.fields.indexInfos, +// sortedByIndexCntAddrs: test.fields.sortedByIndexCntAddrs, // uuidsCount: test.fields.uuidsCount, // uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, // checkedID: test.fields.checkedID, diff --git a/pkg/index/job/correction/service/options_test.go b/pkg/index/job/correction/service/options_test.go index ed1a312363..4c6bccc1e7 100644 --- a/pkg/index/job/correction/service/options_test.go +++ b/pkg/index/job/correction/service/options_test.go @@ -273,7 +273,7 @@ package service // } // } // -// func TestWithBboltAsyncWriteConcurrency(t *testing.T) { +// func TestWithKvsAsyncWriteConcurrency(t *testing.T) { // type args struct { // num int // } @@ -350,7 +350,7 @@ package service // checkFunc = defaultCheckFunc // } // -// got := WithBboltAsyncWriteConcurrency(test.args.num) +// got := WithKvsAsyncWriteConcurrency(test.args.num) // if err := checkFunc(test.want, got); err != nil { // tt.Errorf("error = %v", err) // } diff --git a/pkg/index/job/readreplica/rotate/usecase/rotate_test.go b/pkg/index/job/readreplica/rotate/usecase/rotate_test.go new file mode 100644 index 0000000000..1eab852c2d --- /dev/null +++ b/pkg/index/job/readreplica/rotate/usecase/rotate_test.go @@ -0,0 +1,106 @@ +// Copyright (C) 2019-2023 vdaas.org vald team +// +// 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 + +// NOT IMPLEMENTED BELOW +// +// func TestNew(t *testing.T) { +// type args struct { +// cfg *config.Data +// } +// type want struct { +// want runner.Runner +// err error +// } +// type test struct { +// name string +// args args +// want want +// checkFunc func(want, runner.Runner, error) error +// beforeFunc func(*testing.T, args) +// afterFunc func(*testing.T, args) +// } +// defaultCheckFunc := func(w want, got runner.Runner, err error) error { +// if !errors.Is(err, w.err) { +// return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) +// } +// if !reflect.DeepEqual(got, w.want) { +// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) +// } +// return nil +// } +// tests := []test{ +// // TODO test cases +// /* +// { +// name: "test_case_1", +// args: args { +// cfg:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// }, +// */ +// +// // TODO test cases +// /* +// func() test { +// return test { +// name: "test_case_2", +// args: args { +// cfg:nil, +// }, +// want: want{}, +// checkFunc: defaultCheckFunc, +// beforeFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// afterFunc: func(t *testing.T, args args) { +// t.Helper() +// }, +// } +// }(), +// */ +// } +// +// for _, tc := range tests { +// test := tc +// t.Run(test.name, func(tt *testing.T) { +// tt.Parallel() +// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) +// if test.beforeFunc != nil { +// test.beforeFunc(tt, test.args) +// } +// if test.afterFunc != nil { +// defer test.afterFunc(tt, test.args) +// } +// checkFunc := test.checkFunc +// if test.checkFunc == nil { +// checkFunc = defaultCheckFunc +// } +// +// got, err := New(test.args.cfg) +// if err := checkFunc(test.want, got, err); err != nil { +// tt.Errorf("error = %v", err) +// } +// +// }) +// } +// }