From 181fa82a04b7f2067cf6c7cca7eac124ea555376 Mon Sep 17 00:00:00 2001 From: vankichi Date: Tue, 22 Nov 2022 10:21:19 +0900 Subject: [PATCH 1/5] :recycle: Fix deepsource: VET-V0008 lock erroneously passed by value pkg/discoverer Signed-off-by: vankichi --- pkg/discoverer/k8s/service/discover_test.go | 138 ++++-- pkg/discoverer/k8s/service/nodemap_test.go | 399 ++++++++++++------ .../k8s/service/nodemetricsmap_test.go | 373 +++++++++++----- .../k8s/service/podmetricsmap_test.go | 373 +++++++++++----- pkg/discoverer/k8s/service/podsmap_test.go | 373 +++++++++++----- 5 files changed, 1159 insertions(+), 497 deletions(-) diff --git a/pkg/discoverer/k8s/service/discover_test.go b/pkg/discoverer/k8s/service/discover_test.go index 27681ede49..466d07f674 100644 --- a/pkg/discoverer/k8s/service/discover_test.go +++ b/pkg/discoverer/k8s/service/discover_test.go @@ -34,7 +34,6 @@ import ( ) func TestNew(t *testing.T) { - t.Parallel() type args struct { selector *config.Selectors opts []Option @@ -48,8 +47,8 @@ func TestNew(t *testing.T) { args args want want checkFunc func(want, Discoverer, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotDsc Discoverer, err error) error { if !errors.Is(err, w.err) { @@ -66,10 +65,17 @@ func TestNew(t *testing.T) { { name: "test_case_1", args: args { + selector: nil, opts: nil, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -79,10 +85,17 @@ func TestNew(t *testing.T) { return test { name: "test_case_2", args: args { + selector: nil, opts: nil, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -94,10 +107,10 @@ func TestNew(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -108,21 +121,21 @@ func TestNew(t *testing.T) { if err := checkFunc(test.want, gotDsc, err); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_discoverer_Start(t *testing.T) { - t.Parallel() type args struct { ctx context.Context } type fields struct { maxPods int - nodes nodeMap - nodeMetrics nodeMetricsMap - pods podsMap - podMetrics podMetricsMap + nodes func() nodeMap + nodeMetrics func() nodeMetricsMap + pods func() podsMap + podMetrics func() podMetricsMap podsByNode atomic.Value podsByNamespace atomic.Value podsByName atomic.Value @@ -144,8 +157,8 @@ func Test_discoverer_Start(t *testing.T) { fields fields want want checkFunc func(want, <-chan error, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got <-chan error, err error) error { if !errors.Is(err, w.err) { @@ -183,6 +196,12 @@ func Test_discoverer_Start(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -213,6 +232,12 @@ func Test_discoverer_Start(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -224,10 +249,10 @@ func Test_discoverer_Start(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -235,10 +260,10 @@ func Test_discoverer_Start(t *testing.T) { } d := &discoverer{ maxPods: test.fields.maxPods, - nodes: test.fields.nodes, - nodeMetrics: test.fields.nodeMetrics, - pods: test.fields.pods, - podMetrics: test.fields.podMetrics, + nodes: test.fields.nodes(), + nodeMetrics: test.fields.nodeMetrics(), + pods: test.fields.pods(), + podMetrics: test.fields.podMetrics(), podsByNode: test.fields.podsByNode, podsByNamespace: test.fields.podsByNamespace, podsByName: test.fields.podsByName, @@ -255,21 +280,21 @@ func Test_discoverer_Start(t *testing.T) { if err := checkFunc(test.want, got, err); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_discoverer_GetPods(t *testing.T) { - t.Parallel() type args struct { req *payload.Discoverer_Request } type fields struct { maxPods int - nodes nodeMap - nodeMetrics nodeMetricsMap - pods podsMap - podMetrics podMetricsMap + nodes func() nodeMap + nodeMetrics func() nodeMetricsMap + pods func() podsMap + podMetrics func() podMetricsMap podsByNode atomic.Value podsByNamespace atomic.Value podsByName atomic.Value @@ -291,8 +316,8 @@ func Test_discoverer_GetPods(t *testing.T) { fields fields want want checkFunc func(want, *payload.Info_Pods, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotPods *payload.Info_Pods, err error) error { if !errors.Is(err, w.err) { @@ -330,6 +355,12 @@ func Test_discoverer_GetPods(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -360,6 +391,12 @@ func Test_discoverer_GetPods(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -371,10 +408,10 @@ func Test_discoverer_GetPods(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -382,10 +419,10 @@ func Test_discoverer_GetPods(t *testing.T) { } d := &discoverer{ maxPods: test.fields.maxPods, - nodes: test.fields.nodes, - nodeMetrics: test.fields.nodeMetrics, - pods: test.fields.pods, - podMetrics: test.fields.podMetrics, + nodes: test.fields.nodes(), + nodeMetrics: test.fields.nodeMetrics(), + pods: test.fields.pods(), + podMetrics: test.fields.podMetrics(), podsByNode: test.fields.podsByNode, podsByNamespace: test.fields.podsByNamespace, podsByName: test.fields.podsByName, @@ -402,21 +439,21 @@ func Test_discoverer_GetPods(t *testing.T) { if err := checkFunc(test.want, gotPods, err); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_discoverer_GetNodes(t *testing.T) { - t.Parallel() type args struct { req *payload.Discoverer_Request } type fields struct { maxPods int - nodes nodeMap - nodeMetrics nodeMetricsMap - pods podsMap - podMetrics podMetricsMap + nodes func() nodeMap + nodeMetrics func() nodeMetricsMap + pods func() podsMap + podMetrics func() podMetricsMap podsByNode atomic.Value podsByNamespace atomic.Value podsByName atomic.Value @@ -438,8 +475,8 @@ func Test_discoverer_GetNodes(t *testing.T) { fields fields want want checkFunc func(want, *payload.Info_Nodes, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotNodes *payload.Info_Nodes, err error) error { if !errors.Is(err, w.err) { @@ -477,6 +514,12 @@ func Test_discoverer_GetNodes(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -507,6 +550,12 @@ func Test_discoverer_GetNodes(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -518,10 +567,10 @@ func Test_discoverer_GetNodes(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -529,10 +578,10 @@ func Test_discoverer_GetNodes(t *testing.T) { } d := &discoverer{ maxPods: test.fields.maxPods, - nodes: test.fields.nodes, - nodeMetrics: test.fields.nodeMetrics, - pods: test.fields.pods, - podMetrics: test.fields.podMetrics, + nodes: test.fields.nodes(), + nodeMetrics: test.fields.nodeMetrics(), + pods: test.fields.pods(), + podMetrics: test.fields.podMetrics(), podsByNode: test.fields.podsByNode, podsByNamespace: test.fields.podsByNamespace, podsByName: test.fields.podsByName, @@ -549,6 +598,7 @@ func Test_discoverer_GetNodes(t *testing.T) { if err := checkFunc(test.want, gotNodes, err); err != nil { tt.Errorf("error = %v", err) } + }) } } diff --git a/pkg/discoverer/k8s/service/nodemap_test.go b/pkg/discoverer/k8s/service/nodemap_test.go index 5f77c38212..3b2f969a01 100644 --- a/pkg/discoverer/k8s/service/nodemap_test.go +++ b/pkg/discoverer/k8s/service/nodemap_test.go @@ -18,18 +18,16 @@ package service import ( "reflect" - "sync" "sync/atomic" "testing" "unsafe" - "github.com/vdaas/vald/internal/errors" + "github.com/pkg/errors" "github.com/vdaas/vald/internal/k8s/node" "github.com/vdaas/vald/internal/test/goleak" ) func Test_newEntryNodeMap(t *testing.T) { - t.Parallel() type args struct { i *node.Node } @@ -41,8 +39,8 @@ func Test_newEntryNodeMap(t *testing.T) { args args want want checkFunc func(want, *entryNodeMap) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got *entryNodeMap) error { if !reflect.DeepEqual(got, w.want) { @@ -60,6 +58,12 @@ func Test_newEntryNodeMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -73,6 +77,12 @@ func Test_newEntryNodeMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -84,10 +94,10 @@ func Test_newEntryNodeMap(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -98,17 +108,16 @@ func Test_newEntryNodeMap(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_nodeMap_Load(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int @@ -123,8 +132,8 @@ func Test_nodeMap_Load(t *testing.T) { fields fields want want checkFunc func(want, *node.Node, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotValue *node.Node, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -144,13 +153,18 @@ func Test_nodeMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -163,13 +177,18 @@ func Test_nodeMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -181,17 +200,16 @@ func Test_nodeMap_Load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -201,12 +219,12 @@ func Test_nodeMap_Load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryNodeMap_load(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -219,8 +237,8 @@ func Test_entryNodeMap_load(t *testing.T) { fields fields want want checkFunc func(want, *node.Node, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotValue *node.Node, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -241,6 +259,12 @@ func Test_entryNodeMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -254,6 +278,12 @@ func Test_entryNodeMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -265,10 +295,10 @@ func Test_entryNodeMap_load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -282,31 +312,31 @@ func Test_entryNodeMap_load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_nodeMap_Store(t *testing.T) { - t.Parallel() type args struct { key string value *node.Node } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -321,13 +351,18 @@ func Test_nodeMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -341,13 +376,18 @@ func Test_nodeMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -359,17 +399,16 @@ func Test_nodeMap_Store(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -384,7 +423,6 @@ func Test_nodeMap_Store(t *testing.T) { } func Test_entryNodeMap_tryStore(t *testing.T) { - t.Parallel() type args struct { i **node.Node } @@ -400,8 +438,8 @@ func Test_entryNodeMap_tryStore(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got bool) error { if !reflect.DeepEqual(got, w.want) { @@ -422,6 +460,12 @@ func Test_entryNodeMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -438,6 +482,12 @@ func Test_entryNodeMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -449,10 +499,10 @@ func Test_entryNodeMap_tryStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -466,12 +516,12 @@ func Test_entryNodeMap_tryStore(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryNodeMap_unexpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -483,8 +533,8 @@ func Test_entryNodeMap_unexpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotWasExpunged bool) error { if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { @@ -502,6 +552,12 @@ func Test_entryNodeMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -515,6 +571,12 @@ func Test_entryNodeMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -526,10 +588,10 @@ func Test_entryNodeMap_unexpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -543,27 +605,28 @@ func Test_entryNodeMap_unexpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotWasExpunged); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryNodeMap_storeLocked(t *testing.T) { - t.Parallel() type args struct { i **node.Node } type fields struct { p unsafe.Pointer } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -581,6 +644,12 @@ func Test_entryNodeMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -597,6 +666,12 @@ func Test_entryNodeMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -608,10 +683,10 @@ func Test_entryNodeMap_storeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -630,13 +705,11 @@ func Test_entryNodeMap_storeLocked(t *testing.T) { } func Test_nodeMap_LoadOrStore(t *testing.T) { - t.Parallel() type args struct { key string value *node.Node } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int @@ -651,8 +724,8 @@ func Test_nodeMap_LoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, *node.Node, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual *node.Node, gotLoaded bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -673,13 +746,18 @@ func Test_nodeMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -693,13 +771,18 @@ func Test_nodeMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -711,17 +794,16 @@ func Test_nodeMap_LoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -731,12 +813,12 @@ func Test_nodeMap_LoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryNodeMap_tryLoadOrStore(t *testing.T) { - t.Parallel() type args struct { i *node.Node } @@ -754,8 +836,8 @@ func Test_entryNodeMap_tryLoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, *node.Node, bool, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual *node.Node, gotLoaded bool, gotOk bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -782,6 +864,12 @@ func Test_entryNodeMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -798,6 +886,12 @@ func Test_entryNodeMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -809,10 +903,10 @@ func Test_entryNodeMap_tryLoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -826,17 +920,16 @@ func Test_entryNodeMap_tryLoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded, gotOk); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_nodeMap_LoadAndDelete(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int @@ -851,8 +944,8 @@ func Test_nodeMap_LoadAndDelete(t *testing.T) { fields fields want want checkFunc func(want, *node.Node, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotValue *node.Node, gotLoaded bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -872,13 +965,18 @@ func Test_nodeMap_LoadAndDelete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -891,13 +989,18 @@ func Test_nodeMap_LoadAndDelete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -909,17 +1012,16 @@ func Test_nodeMap_LoadAndDelete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -929,30 +1031,30 @@ func Test_nodeMap_LoadAndDelete(t *testing.T) { if err := checkFunc(test.want, gotValue, gotLoaded); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_nodeMap_Delete(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -966,13 +1068,18 @@ func Test_nodeMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -985,13 +1092,18 @@ func Test_nodeMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1003,17 +1115,16 @@ func Test_nodeMap_Delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1028,7 +1139,6 @@ func Test_nodeMap_Delete(t *testing.T) { } func Test_entryNodeMap_delete(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -1041,8 +1151,8 @@ func Test_entryNodeMap_delete(t *testing.T) { fields fields want want checkFunc func(want, *node.Node, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotValue *node.Node, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -1063,6 +1173,12 @@ func Test_entryNodeMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1076,6 +1192,12 @@ func Test_entryNodeMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1087,10 +1209,10 @@ func Test_entryNodeMap_delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1104,30 +1226,30 @@ func Test_entryNodeMap_delete(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_nodeMap_Range(t *testing.T) { - t.Parallel() type args struct { f func(key string, value *node.Node) bool } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -1141,13 +1263,18 @@ func Test_nodeMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1160,13 +1287,18 @@ func Test_nodeMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1178,17 +1310,16 @@ func Test_nodeMap_Range(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1203,21 +1334,20 @@ func Test_nodeMap_Range(t *testing.T) { } func Test_nodeMap_missLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int } - type want struct{} + type want struct { + } type test struct { name string fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1228,13 +1358,18 @@ func Test_nodeMap_missLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1244,13 +1379,18 @@ func Test_nodeMap_missLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1262,17 +1402,16 @@ func Test_nodeMap_missLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1287,21 +1426,20 @@ func Test_nodeMap_missLocked(t *testing.T) { } func Test_nodeMap_dirtyLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int } - type want struct{} + type want struct { + } type test struct { name string fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1312,13 +1450,18 @@ func Test_nodeMap_dirtyLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1328,13 +1471,18 @@ func Test_nodeMap_dirtyLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1346,17 +1494,16 @@ func Test_nodeMap_dirtyLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1371,7 +1518,6 @@ func Test_nodeMap_dirtyLocked(t *testing.T) { } func Test_entryNodeMap_tryExpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -1383,8 +1529,8 @@ func Test_entryNodeMap_tryExpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotIsExpunged bool) error { if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { @@ -1402,6 +1548,12 @@ func Test_entryNodeMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1415,6 +1567,12 @@ func Test_entryNodeMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1426,10 +1584,10 @@ func Test_entryNodeMap_tryExpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1443,6 +1601,7 @@ func Test_entryNodeMap_tryExpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotIsExpunged); err != nil { tt.Errorf("error = %v", err) } + }) } } diff --git a/pkg/discoverer/k8s/service/nodemetricsmap_test.go b/pkg/discoverer/k8s/service/nodemetricsmap_test.go index 846b41cd94..72f8e50d3f 100644 --- a/pkg/discoverer/k8s/service/nodemetricsmap_test.go +++ b/pkg/discoverer/k8s/service/nodemetricsmap_test.go @@ -18,18 +18,16 @@ package service import ( "reflect" - "sync" "sync/atomic" "testing" "unsafe" - "github.com/vdaas/vald/internal/errors" + "github.com/pkg/errors" mnode "github.com/vdaas/vald/internal/k8s/metrics/node" "github.com/vdaas/vald/internal/test/goleak" ) func Test_newEntryNodeMetricsMap(t *testing.T) { - t.Parallel() type args struct { i mnode.Node } @@ -41,8 +39,8 @@ func Test_newEntryNodeMetricsMap(t *testing.T) { args args want want checkFunc func(want, *entryNodeMetricsMap) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got *entryNodeMetricsMap) error { if !reflect.DeepEqual(got, w.want) { @@ -60,6 +58,12 @@ func Test_newEntryNodeMetricsMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -73,6 +77,12 @@ func Test_newEntryNodeMetricsMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -84,10 +94,10 @@ func Test_newEntryNodeMetricsMap(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -98,17 +108,16 @@ func Test_newEntryNodeMetricsMap(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_nodeMetricsMap_Load(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMetricsMap misses int @@ -123,8 +132,8 @@ func Test_nodeMetricsMap_Load(t *testing.T) { fields fields want want checkFunc func(want, mnode.Node, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotValue mnode.Node, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -144,13 +153,18 @@ func Test_nodeMetricsMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -163,13 +177,18 @@ func Test_nodeMetricsMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -181,17 +200,16 @@ func Test_nodeMetricsMap_Load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -201,12 +219,12 @@ func Test_nodeMetricsMap_Load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryNodeMetricsMap_load(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -219,8 +237,8 @@ func Test_entryNodeMetricsMap_load(t *testing.T) { fields fields want want checkFunc func(want, mnode.Node, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotValue mnode.Node, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -241,6 +259,12 @@ func Test_entryNodeMetricsMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -254,6 +278,12 @@ func Test_entryNodeMetricsMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -265,10 +295,10 @@ func Test_entryNodeMetricsMap_load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -282,31 +312,31 @@ func Test_entryNodeMetricsMap_load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_nodeMetricsMap_Store(t *testing.T) { - t.Parallel() type args struct { key string value mnode.Node } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMetricsMap misses int } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -321,13 +351,18 @@ func Test_nodeMetricsMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -341,13 +376,18 @@ func Test_nodeMetricsMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -359,17 +399,16 @@ func Test_nodeMetricsMap_Store(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -384,7 +423,6 @@ func Test_nodeMetricsMap_Store(t *testing.T) { } func Test_entryNodeMetricsMap_tryStore(t *testing.T) { - t.Parallel() type args struct { i *mnode.Node } @@ -400,8 +438,8 @@ func Test_entryNodeMetricsMap_tryStore(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got bool) error { if !reflect.DeepEqual(got, w.want) { @@ -422,6 +460,12 @@ func Test_entryNodeMetricsMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -438,6 +482,12 @@ func Test_entryNodeMetricsMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -449,10 +499,10 @@ func Test_entryNodeMetricsMap_tryStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -466,12 +516,12 @@ func Test_entryNodeMetricsMap_tryStore(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryNodeMetricsMap_unexpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -483,8 +533,8 @@ func Test_entryNodeMetricsMap_unexpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotWasExpunged bool) error { if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { @@ -502,6 +552,12 @@ func Test_entryNodeMetricsMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -515,6 +571,12 @@ func Test_entryNodeMetricsMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -526,10 +588,10 @@ func Test_entryNodeMetricsMap_unexpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -543,27 +605,28 @@ func Test_entryNodeMetricsMap_unexpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotWasExpunged); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryNodeMetricsMap_storeLocked(t *testing.T) { - t.Parallel() type args struct { i *mnode.Node } type fields struct { p unsafe.Pointer } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -581,6 +644,12 @@ func Test_entryNodeMetricsMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -597,6 +666,12 @@ func Test_entryNodeMetricsMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -608,10 +683,10 @@ func Test_entryNodeMetricsMap_storeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -630,13 +705,11 @@ func Test_entryNodeMetricsMap_storeLocked(t *testing.T) { } func Test_nodeMetricsMap_LoadOrStore(t *testing.T) { - t.Parallel() type args struct { key string value mnode.Node } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMetricsMap misses int @@ -651,8 +724,8 @@ func Test_nodeMetricsMap_LoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, mnode.Node, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual mnode.Node, gotLoaded bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -673,13 +746,18 @@ func Test_nodeMetricsMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -693,13 +771,18 @@ func Test_nodeMetricsMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -711,17 +794,16 @@ func Test_nodeMetricsMap_LoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -731,12 +813,12 @@ func Test_nodeMetricsMap_LoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryNodeMetricsMap_tryLoadOrStore(t *testing.T) { - t.Parallel() type args struct { i mnode.Node } @@ -754,8 +836,8 @@ func Test_entryNodeMetricsMap_tryLoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, mnode.Node, bool, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual mnode.Node, gotLoaded bool, gotOk bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -782,6 +864,12 @@ func Test_entryNodeMetricsMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -798,6 +886,12 @@ func Test_entryNodeMetricsMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -809,10 +903,10 @@ func Test_entryNodeMetricsMap_tryLoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -826,30 +920,30 @@ func Test_entryNodeMetricsMap_tryLoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded, gotOk); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_nodeMetricsMap_Delete(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMetricsMap misses int } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -863,13 +957,18 @@ func Test_nodeMetricsMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -882,13 +981,18 @@ func Test_nodeMetricsMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -900,17 +1004,16 @@ func Test_nodeMetricsMap_Delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -925,7 +1028,6 @@ func Test_nodeMetricsMap_Delete(t *testing.T) { } func Test_entryNodeMetricsMap_delete(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -937,8 +1039,8 @@ func Test_entryNodeMetricsMap_delete(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotHadValue bool) error { if !reflect.DeepEqual(gotHadValue, w.wantHadValue) { @@ -956,6 +1058,12 @@ func Test_entryNodeMetricsMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -969,6 +1077,12 @@ func Test_entryNodeMetricsMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -980,10 +1094,10 @@ func Test_entryNodeMetricsMap_delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -997,30 +1111,30 @@ func Test_entryNodeMetricsMap_delete(t *testing.T) { if err := checkFunc(test.want, gotHadValue); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_nodeMetricsMap_Range(t *testing.T) { - t.Parallel() type args struct { f func(key string, value mnode.Node) bool } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMetricsMap misses int } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -1034,13 +1148,18 @@ func Test_nodeMetricsMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1053,13 +1172,18 @@ func Test_nodeMetricsMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1071,17 +1195,16 @@ func Test_nodeMetricsMap_Range(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1096,21 +1219,20 @@ func Test_nodeMetricsMap_Range(t *testing.T) { } func Test_nodeMetricsMap_missLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMetricsMap misses int } - type want struct{} + type want struct { + } type test struct { name string fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1121,13 +1243,18 @@ func Test_nodeMetricsMap_missLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1137,13 +1264,18 @@ func Test_nodeMetricsMap_missLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1155,17 +1287,16 @@ func Test_nodeMetricsMap_missLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1180,21 +1311,20 @@ func Test_nodeMetricsMap_missLocked(t *testing.T) { } func Test_nodeMetricsMap_dirtyLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMetricsMap misses int } - type want struct{} + type want struct { + } type test struct { name string fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1205,13 +1335,18 @@ func Test_nodeMetricsMap_dirtyLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1221,13 +1356,18 @@ func Test_nodeMetricsMap_dirtyLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1239,17 +1379,16 @@ func Test_nodeMetricsMap_dirtyLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1264,7 +1403,6 @@ func Test_nodeMetricsMap_dirtyLocked(t *testing.T) { } func Test_entryNodeMetricsMap_tryExpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -1276,8 +1414,8 @@ func Test_entryNodeMetricsMap_tryExpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotIsExpunged bool) error { if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { @@ -1295,6 +1433,12 @@ func Test_entryNodeMetricsMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1308,6 +1452,12 @@ func Test_entryNodeMetricsMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1319,10 +1469,10 @@ func Test_entryNodeMetricsMap_tryExpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1336,6 +1486,7 @@ func Test_entryNodeMetricsMap_tryExpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotIsExpunged); err != nil { tt.Errorf("error = %v", err) } + }) } } diff --git a/pkg/discoverer/k8s/service/podmetricsmap_test.go b/pkg/discoverer/k8s/service/podmetricsmap_test.go index 7c6ca96d43..34a6802b78 100644 --- a/pkg/discoverer/k8s/service/podmetricsmap_test.go +++ b/pkg/discoverer/k8s/service/podmetricsmap_test.go @@ -18,18 +18,16 @@ package service import ( "reflect" - "sync" "sync/atomic" "testing" "unsafe" - "github.com/vdaas/vald/internal/errors" + "github.com/pkg/errors" mpod "github.com/vdaas/vald/internal/k8s/metrics/pod" "github.com/vdaas/vald/internal/test/goleak" ) func Test_newEntryPodMetricsMap(t *testing.T) { - t.Parallel() type args struct { i mpod.Pod } @@ -41,8 +39,8 @@ func Test_newEntryPodMetricsMap(t *testing.T) { args args want want checkFunc func(want, *entryPodMetricsMap) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got *entryPodMetricsMap) error { if !reflect.DeepEqual(got, w.want) { @@ -60,6 +58,12 @@ func Test_newEntryPodMetricsMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -73,6 +77,12 @@ func Test_newEntryPodMetricsMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -84,10 +94,10 @@ func Test_newEntryPodMetricsMap(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -98,17 +108,16 @@ func Test_newEntryPodMetricsMap(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_podMetricsMap_Load(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodMetricsMap misses int @@ -123,8 +132,8 @@ func Test_podMetricsMap_Load(t *testing.T) { fields fields want want checkFunc func(want, mpod.Pod, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotValue mpod.Pod, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -144,13 +153,18 @@ func Test_podMetricsMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -163,13 +177,18 @@ func Test_podMetricsMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -181,17 +200,16 @@ func Test_podMetricsMap_Load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -201,12 +219,12 @@ func Test_podMetricsMap_Load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryPodMetricsMap_load(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -219,8 +237,8 @@ func Test_entryPodMetricsMap_load(t *testing.T) { fields fields want want checkFunc func(want, mpod.Pod, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotValue mpod.Pod, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -241,6 +259,12 @@ func Test_entryPodMetricsMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -254,6 +278,12 @@ func Test_entryPodMetricsMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -265,10 +295,10 @@ func Test_entryPodMetricsMap_load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -282,31 +312,31 @@ func Test_entryPodMetricsMap_load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_podMetricsMap_Store(t *testing.T) { - t.Parallel() type args struct { key string value mpod.Pod } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodMetricsMap misses int } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -321,13 +351,18 @@ func Test_podMetricsMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -341,13 +376,18 @@ func Test_podMetricsMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -359,17 +399,16 @@ func Test_podMetricsMap_Store(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -384,7 +423,6 @@ func Test_podMetricsMap_Store(t *testing.T) { } func Test_entryPodMetricsMap_tryStore(t *testing.T) { - t.Parallel() type args struct { i *mpod.Pod } @@ -400,8 +438,8 @@ func Test_entryPodMetricsMap_tryStore(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got bool) error { if !reflect.DeepEqual(got, w.want) { @@ -422,6 +460,12 @@ func Test_entryPodMetricsMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -438,6 +482,12 @@ func Test_entryPodMetricsMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -449,10 +499,10 @@ func Test_entryPodMetricsMap_tryStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -466,12 +516,12 @@ func Test_entryPodMetricsMap_tryStore(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryPodMetricsMap_unexpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -483,8 +533,8 @@ func Test_entryPodMetricsMap_unexpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotWasExpunged bool) error { if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { @@ -502,6 +552,12 @@ func Test_entryPodMetricsMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -515,6 +571,12 @@ func Test_entryPodMetricsMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -526,10 +588,10 @@ func Test_entryPodMetricsMap_unexpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -543,27 +605,28 @@ func Test_entryPodMetricsMap_unexpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotWasExpunged); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryPodMetricsMap_storeLocked(t *testing.T) { - t.Parallel() type args struct { i *mpod.Pod } type fields struct { p unsafe.Pointer } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -581,6 +644,12 @@ func Test_entryPodMetricsMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -597,6 +666,12 @@ func Test_entryPodMetricsMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -608,10 +683,10 @@ func Test_entryPodMetricsMap_storeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -630,13 +705,11 @@ func Test_entryPodMetricsMap_storeLocked(t *testing.T) { } func Test_podMetricsMap_LoadOrStore(t *testing.T) { - t.Parallel() type args struct { key string value mpod.Pod } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodMetricsMap misses int @@ -651,8 +724,8 @@ func Test_podMetricsMap_LoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, mpod.Pod, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual mpod.Pod, gotLoaded bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -673,13 +746,18 @@ func Test_podMetricsMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -693,13 +771,18 @@ func Test_podMetricsMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -711,17 +794,16 @@ func Test_podMetricsMap_LoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -731,12 +813,12 @@ func Test_podMetricsMap_LoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryPodMetricsMap_tryLoadOrStore(t *testing.T) { - t.Parallel() type args struct { i mpod.Pod } @@ -754,8 +836,8 @@ func Test_entryPodMetricsMap_tryLoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, mpod.Pod, bool, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual mpod.Pod, gotLoaded bool, gotOk bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -782,6 +864,12 @@ func Test_entryPodMetricsMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -798,6 +886,12 @@ func Test_entryPodMetricsMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -809,10 +903,10 @@ func Test_entryPodMetricsMap_tryLoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -826,30 +920,30 @@ func Test_entryPodMetricsMap_tryLoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded, gotOk); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_podMetricsMap_Delete(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodMetricsMap misses int } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -863,13 +957,18 @@ func Test_podMetricsMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -882,13 +981,18 @@ func Test_podMetricsMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -900,17 +1004,16 @@ func Test_podMetricsMap_Delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -925,7 +1028,6 @@ func Test_podMetricsMap_Delete(t *testing.T) { } func Test_entryPodMetricsMap_delete(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -937,8 +1039,8 @@ func Test_entryPodMetricsMap_delete(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotHadValue bool) error { if !reflect.DeepEqual(gotHadValue, w.wantHadValue) { @@ -956,6 +1058,12 @@ func Test_entryPodMetricsMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -969,6 +1077,12 @@ func Test_entryPodMetricsMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -980,10 +1094,10 @@ func Test_entryPodMetricsMap_delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -997,30 +1111,30 @@ func Test_entryPodMetricsMap_delete(t *testing.T) { if err := checkFunc(test.want, gotHadValue); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_podMetricsMap_Range(t *testing.T) { - t.Parallel() type args struct { f func(key string, value mpod.Pod) bool } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodMetricsMap misses int } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -1034,13 +1148,18 @@ func Test_podMetricsMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1053,13 +1172,18 @@ func Test_podMetricsMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1071,17 +1195,16 @@ func Test_podMetricsMap_Range(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1096,21 +1219,20 @@ func Test_podMetricsMap_Range(t *testing.T) { } func Test_podMetricsMap_missLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodMetricsMap misses int } - type want struct{} + type want struct { + } type test struct { name string fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1121,13 +1243,18 @@ func Test_podMetricsMap_missLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1137,13 +1264,18 @@ func Test_podMetricsMap_missLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1155,17 +1287,16 @@ func Test_podMetricsMap_missLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1180,21 +1311,20 @@ func Test_podMetricsMap_missLocked(t *testing.T) { } func Test_podMetricsMap_dirtyLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodMetricsMap misses int } - type want struct{} + type want struct { + } type test struct { name string fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1205,13 +1335,18 @@ func Test_podMetricsMap_dirtyLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1221,13 +1356,18 @@ func Test_podMetricsMap_dirtyLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1239,17 +1379,16 @@ func Test_podMetricsMap_dirtyLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1264,7 +1403,6 @@ func Test_podMetricsMap_dirtyLocked(t *testing.T) { } func Test_entryPodMetricsMap_tryExpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -1276,8 +1414,8 @@ func Test_entryPodMetricsMap_tryExpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotIsExpunged bool) error { if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { @@ -1295,6 +1433,12 @@ func Test_entryPodMetricsMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1308,6 +1452,12 @@ func Test_entryPodMetricsMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1319,10 +1469,10 @@ func Test_entryPodMetricsMap_tryExpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1336,6 +1486,7 @@ func Test_entryPodMetricsMap_tryExpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotIsExpunged); err != nil { tt.Errorf("error = %v", err) } + }) } } diff --git a/pkg/discoverer/k8s/service/podsmap_test.go b/pkg/discoverer/k8s/service/podsmap_test.go index b2bbd29359..4861df58ea 100644 --- a/pkg/discoverer/k8s/service/podsmap_test.go +++ b/pkg/discoverer/k8s/service/podsmap_test.go @@ -18,18 +18,16 @@ package service import ( "reflect" - "sync" "sync/atomic" "testing" "unsafe" - "github.com/vdaas/vald/internal/errors" + "github.com/pkg/errors" "github.com/vdaas/vald/internal/k8s/pod" "github.com/vdaas/vald/internal/test/goleak" ) func Test_newEntryPodsMap(t *testing.T) { - t.Parallel() type args struct { i []pod.Pod } @@ -41,8 +39,8 @@ func Test_newEntryPodsMap(t *testing.T) { args args want want checkFunc func(want, *entryPodsMap) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got *entryPodsMap) error { if !reflect.DeepEqual(got, w.want) { @@ -60,6 +58,12 @@ func Test_newEntryPodsMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -73,6 +77,12 @@ func Test_newEntryPodsMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -84,10 +94,10 @@ func Test_newEntryPodsMap(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -98,17 +108,16 @@ func Test_newEntryPodsMap(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_podsMap_Load(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodsMap misses int @@ -123,8 +132,8 @@ func Test_podsMap_Load(t *testing.T) { fields fields want want checkFunc func(want, []pod.Pod, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotValue []pod.Pod, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -144,13 +153,18 @@ func Test_podsMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -163,13 +177,18 @@ func Test_podsMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -181,17 +200,16 @@ func Test_podsMap_Load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -201,12 +219,12 @@ func Test_podsMap_Load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryPodsMap_load(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -219,8 +237,8 @@ func Test_entryPodsMap_load(t *testing.T) { fields fields want want checkFunc func(want, []pod.Pod, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotValue []pod.Pod, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -241,6 +259,12 @@ func Test_entryPodsMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -254,6 +278,12 @@ func Test_entryPodsMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -265,10 +295,10 @@ func Test_entryPodsMap_load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -282,31 +312,31 @@ func Test_entryPodsMap_load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_podsMap_Store(t *testing.T) { - t.Parallel() type args struct { key string value []pod.Pod } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodsMap misses int } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -321,13 +351,18 @@ func Test_podsMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -341,13 +376,18 @@ func Test_podsMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -359,17 +399,16 @@ func Test_podsMap_Store(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -384,7 +423,6 @@ func Test_podsMap_Store(t *testing.T) { } func Test_entryPodsMap_tryStore(t *testing.T) { - t.Parallel() type args struct { i *[]pod.Pod } @@ -400,8 +438,8 @@ func Test_entryPodsMap_tryStore(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got bool) error { if !reflect.DeepEqual(got, w.want) { @@ -422,6 +460,12 @@ func Test_entryPodsMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -438,6 +482,12 @@ func Test_entryPodsMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -449,10 +499,10 @@ func Test_entryPodsMap_tryStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -466,12 +516,12 @@ func Test_entryPodsMap_tryStore(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryPodsMap_unexpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -483,8 +533,8 @@ func Test_entryPodsMap_unexpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotWasExpunged bool) error { if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { @@ -502,6 +552,12 @@ func Test_entryPodsMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -515,6 +571,12 @@ func Test_entryPodsMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -526,10 +588,10 @@ func Test_entryPodsMap_unexpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -543,27 +605,28 @@ func Test_entryPodsMap_unexpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotWasExpunged); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryPodsMap_storeLocked(t *testing.T) { - t.Parallel() type args struct { i *[]pod.Pod } type fields struct { p unsafe.Pointer } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -581,6 +644,12 @@ func Test_entryPodsMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -597,6 +666,12 @@ func Test_entryPodsMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -608,10 +683,10 @@ func Test_entryPodsMap_storeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -630,13 +705,11 @@ func Test_entryPodsMap_storeLocked(t *testing.T) { } func Test_podsMap_LoadOrStore(t *testing.T) { - t.Parallel() type args struct { key string value []pod.Pod } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodsMap misses int @@ -651,8 +724,8 @@ func Test_podsMap_LoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, []pod.Pod, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual []pod.Pod, gotLoaded bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -673,13 +746,18 @@ func Test_podsMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -693,13 +771,18 @@ func Test_podsMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -711,17 +794,16 @@ func Test_podsMap_LoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -731,12 +813,12 @@ func Test_podsMap_LoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_entryPodsMap_tryLoadOrStore(t *testing.T) { - t.Parallel() type args struct { i []pod.Pod } @@ -754,8 +836,8 @@ func Test_entryPodsMap_tryLoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, []pod.Pod, bool, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual []pod.Pod, gotLoaded bool, gotOk bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -782,6 +864,12 @@ func Test_entryPodsMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -798,6 +886,12 @@ func Test_entryPodsMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -809,10 +903,10 @@ func Test_entryPodsMap_tryLoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -826,30 +920,30 @@ func Test_entryPodsMap_tryLoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded, gotOk); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_podsMap_Delete(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodsMap misses int } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -863,13 +957,18 @@ func Test_podsMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -882,13 +981,18 @@ func Test_podsMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -900,17 +1004,16 @@ func Test_podsMap_Delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -925,7 +1028,6 @@ func Test_podsMap_Delete(t *testing.T) { } func Test_entryPodsMap_delete(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -937,8 +1039,8 @@ func Test_entryPodsMap_delete(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotHadValue bool) error { if !reflect.DeepEqual(gotHadValue, w.wantHadValue) { @@ -956,6 +1058,12 @@ func Test_entryPodsMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -969,6 +1077,12 @@ func Test_entryPodsMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -980,10 +1094,10 @@ func Test_entryPodsMap_delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -997,30 +1111,30 @@ func Test_entryPodsMap_delete(t *testing.T) { if err := checkFunc(test.want, gotHadValue); err != nil { tt.Errorf("error = %v", err) } + }) } } func Test_podsMap_Range(t *testing.T) { - t.Parallel() type args struct { f func(key string, value []pod.Pod) bool } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodsMap misses int } - type want struct{} + type want struct { + } type test struct { name string args args fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -1034,13 +1148,18 @@ func Test_podsMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1053,13 +1172,18 @@ func Test_podsMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1071,17 +1195,16 @@ func Test_podsMap_Range(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1096,21 +1219,20 @@ func Test_podsMap_Range(t *testing.T) { } func Test_podsMap_missLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodsMap misses int } - type want struct{} + type want struct { + } type test struct { name string fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1121,13 +1243,18 @@ func Test_podsMap_missLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1137,13 +1264,18 @@ func Test_podsMap_missLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1155,17 +1287,16 @@ func Test_podsMap_missLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1180,21 +1311,20 @@ func Test_podsMap_missLocked(t *testing.T) { } func Test_podsMap_dirtyLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodsMap misses int } - type want struct{} + type want struct { + } type test struct { name string fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1205,13 +1335,18 @@ func Test_podsMap_dirtyLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1221,13 +1356,18 @@ func Test_podsMap_dirtyLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1239,17 +1379,16 @@ func Test_podsMap_dirtyLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1264,7 +1403,6 @@ func Test_podsMap_dirtyLocked(t *testing.T) { } func Test_entryPodsMap_tryExpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -1276,8 +1414,8 @@ func Test_entryPodsMap_tryExpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotIsExpunged bool) error { if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { @@ -1295,6 +1433,12 @@ func Test_entryPodsMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1308,6 +1452,12 @@ func Test_entryPodsMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1319,10 +1469,10 @@ func Test_entryPodsMap_tryExpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1336,6 +1486,7 @@ func Test_entryPodsMap_tryExpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotIsExpunged); err != nil { tt.Errorf("error = %v", err) } + }) } } From c360071dab3c212e7015b0550405ad231480db19 Mon Sep 17 00:00:00 2001 From: vankichi Date: Tue, 22 Nov 2022 10:28:32 +0900 Subject: [PATCH 2/5] :recycle: Fix import package Signed-off-by: vankichi --- pkg/discoverer/k8s/service/nodemap_test.go | 2 +- pkg/discoverer/k8s/service/nodemetricsmap_test.go | 2 +- pkg/discoverer/k8s/service/podmetricsmap_test.go | 2 +- pkg/discoverer/k8s/service/podsmap_test.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/discoverer/k8s/service/nodemap_test.go b/pkg/discoverer/k8s/service/nodemap_test.go index 3b2f969a01..4061e2a543 100644 --- a/pkg/discoverer/k8s/service/nodemap_test.go +++ b/pkg/discoverer/k8s/service/nodemap_test.go @@ -22,7 +22,7 @@ import ( "testing" "unsafe" - "github.com/pkg/errors" + "github.com/vdaas/vald/internal/errors" "github.com/vdaas/vald/internal/k8s/node" "github.com/vdaas/vald/internal/test/goleak" ) diff --git a/pkg/discoverer/k8s/service/nodemetricsmap_test.go b/pkg/discoverer/k8s/service/nodemetricsmap_test.go index 72f8e50d3f..ef46202d6d 100644 --- a/pkg/discoverer/k8s/service/nodemetricsmap_test.go +++ b/pkg/discoverer/k8s/service/nodemetricsmap_test.go @@ -22,7 +22,7 @@ import ( "testing" "unsafe" - "github.com/pkg/errors" + "github.com/vdaas/vald/internal/errors" mnode "github.com/vdaas/vald/internal/k8s/metrics/node" "github.com/vdaas/vald/internal/test/goleak" ) diff --git a/pkg/discoverer/k8s/service/podmetricsmap_test.go b/pkg/discoverer/k8s/service/podmetricsmap_test.go index 34a6802b78..051afb45e7 100644 --- a/pkg/discoverer/k8s/service/podmetricsmap_test.go +++ b/pkg/discoverer/k8s/service/podmetricsmap_test.go @@ -22,7 +22,7 @@ import ( "testing" "unsafe" - "github.com/pkg/errors" + "github.com/vdaas/vald/internal/errors" mpod "github.com/vdaas/vald/internal/k8s/metrics/pod" "github.com/vdaas/vald/internal/test/goleak" ) diff --git a/pkg/discoverer/k8s/service/podsmap_test.go b/pkg/discoverer/k8s/service/podsmap_test.go index 4861df58ea..d86d43ad55 100644 --- a/pkg/discoverer/k8s/service/podsmap_test.go +++ b/pkg/discoverer/k8s/service/podsmap_test.go @@ -22,7 +22,7 @@ import ( "testing" "unsafe" - "github.com/pkg/errors" + "github.com/vdaas/vald/internal/errors" "github.com/vdaas/vald/internal/k8s/pod" "github.com/vdaas/vald/internal/test/goleak" ) From 51a6b8734b86f13430df1b65beda60a469b88392 Mon Sep 17 00:00:00 2001 From: vankichi Date: Tue, 22 Nov 2022 11:06:45 +0900 Subject: [PATCH 3/5] :recycle: Fix lint Signed-off-by: vankichi --- pkg/discoverer/k8s/service/discover_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/discoverer/k8s/service/discover_test.go b/pkg/discoverer/k8s/service/discover_test.go index 466d07f674..344b55a1a7 100644 --- a/pkg/discoverer/k8s/service/discover_test.go +++ b/pkg/discoverer/k8s/service/discover_test.go @@ -121,7 +121,6 @@ func TestNew(t *testing.T) { if err := checkFunc(test.want, gotDsc, err); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -280,7 +279,6 @@ func Test_discoverer_Start(t *testing.T) { if err := checkFunc(test.want, got, err); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -439,7 +437,6 @@ func Test_discoverer_GetPods(t *testing.T) { if err := checkFunc(test.want, gotPods, err); err != nil { tt.Errorf("error = %v", err) } - }) } } From 24c2c6a047f1e2d07c23fd3d92a9342a83549769 Mon Sep 17 00:00:00 2001 From: vankichi Date: Tue, 22 Nov 2022 11:40:40 +0900 Subject: [PATCH 4/5] :recycle: Fix discoverer_test.go Signed-off-by: vankichi --- pkg/discoverer/k8s/service/discover_test.go | 196 +++++++++++++++----- 1 file changed, 146 insertions(+), 50 deletions(-) diff --git a/pkg/discoverer/k8s/service/discover_test.go b/pkg/discoverer/k8s/service/discover_test.go index 344b55a1a7..553a456543 100644 --- a/pkg/discoverer/k8s/service/discover_test.go +++ b/pkg/discoverer/k8s/service/discover_test.go @@ -130,11 +130,27 @@ func Test_discoverer_Start(t *testing.T) { ctx context.Context } type fields struct { - maxPods int - nodes func() nodeMap - nodeMetrics func() nodeMetricsMap - pods func() podsMap - podMetrics func() podMetricsMap + maxPods int + nodes struct { + read atomic.Value + dirty map[string]*entryNodeMap + misses int + } + nodeMetrics struct { + read atomic.Value + dirty map[string]*entryNodeMetricsMap + misses int + } + pods struct { + read atomic.Value + dirty map[string]*entryPodsMap + misses int + } + podMetrics struct { + read atomic.Value + dirty map[string]*entryPodMetricsMap + misses int + } podsByNode atomic.Value podsByNamespace atomic.Value podsByName atomic.Value @@ -178,10 +194,10 @@ func Test_discoverer_Start(t *testing.T) { }, fields: fields { maxPods: 0, - nodes: nodeMap{}, - nodeMetrics: nodeMetricsMap{}, - pods: podsMap{}, - podMetrics: podMetricsMap{}, + nodes: struct{}, + nodeMetrics: struct{}, + pods: struct{}, + podMetrics: struct{}, podsByNode: nil, podsByNamespace: nil, podsByName: nil, @@ -214,10 +230,10 @@ func Test_discoverer_Start(t *testing.T) { }, fields: fields { maxPods: 0, - nodes: nodeMap{}, - nodeMetrics: nodeMetricsMap{}, - pods: podsMap{}, - podMetrics: podMetricsMap{}, + nodes: struct{}, + nodeMetrics: struct{}, + pods: struct{}, + podMetrics: struct{}, podsByNode: nil, podsByNamespace: nil, podsByName: nil, @@ -258,11 +274,27 @@ func Test_discoverer_Start(t *testing.T) { checkFunc = defaultCheckFunc } d := &discoverer{ - maxPods: test.fields.maxPods, - nodes: test.fields.nodes(), - nodeMetrics: test.fields.nodeMetrics(), - pods: test.fields.pods(), - podMetrics: test.fields.podMetrics(), + maxPods: test.fields.maxPods, + nodes: nodeMap{ + read: test.fields.nodes.read, + dirty: test.fields.nodes.dirty, + misses: test.fields.nodes.misses, + }, + nodeMetrics: nodeMetricsMap{ + read: test.fields.nodeMetrics.read, + dirty: test.fields.nodeMetrics.dirty, + misses: test.fields.nodeMetrics.misses, + }, + pods: podsMap{ + read: test.fields.pods.read, + dirty: test.fields.pods.dirty, + misses: test.fields.pods.misses, + }, + podMetrics: podMetricsMap{ + read: test.fields.podMetrics.read, + dirty: test.fields.podMetrics.dirty, + misses: test.fields.podMetrics.misses, + }, podsByNode: test.fields.podsByNode, podsByNamespace: test.fields.podsByNamespace, podsByName: test.fields.podsByName, @@ -289,10 +321,26 @@ func Test_discoverer_GetPods(t *testing.T) { } type fields struct { maxPods int - nodes func() nodeMap - nodeMetrics func() nodeMetricsMap - pods func() podsMap - podMetrics func() podMetricsMap + nodes struct { + read atomic.Value + dirty map[string]*entryNodeMap + misses int + } + nodeMetrics struct { + read atomic.Value + dirty map[string]*entryNodeMetricsMap + misses int + } + pods struct { + read atomic.Value + dirty map[string]*entryPodsMap + misses int + } + podMetrics struct { + read atomic.Value + dirty map[string]*entryPodMetricsMap + misses int + } podsByNode atomic.Value podsByNamespace atomic.Value podsByName atomic.Value @@ -336,10 +384,10 @@ func Test_discoverer_GetPods(t *testing.T) { }, fields: fields { maxPods: 0, - nodes: nodeMap{}, - nodeMetrics: nodeMetricsMap{}, - pods: podsMap{}, - podMetrics: podMetricsMap{}, + nodes: struct{}, + nodeMetrics: struct{}, + pods: struct{}, + podMetrics: struct{}, podsByNode: nil, podsByNamespace: nil, podsByName: nil, @@ -372,10 +420,10 @@ func Test_discoverer_GetPods(t *testing.T) { }, fields: fields { maxPods: 0, - nodes: nodeMap{}, - nodeMetrics: nodeMetricsMap{}, - pods: podsMap{}, - podMetrics: podMetricsMap{}, + nodes: struct{}, + nodeMetrics: struct{}, + pods: struct{}, + podMetrics: struct{}, podsByNode: nil, podsByNamespace: nil, podsByName: nil, @@ -417,10 +465,26 @@ func Test_discoverer_GetPods(t *testing.T) { } d := &discoverer{ maxPods: test.fields.maxPods, - nodes: test.fields.nodes(), - nodeMetrics: test.fields.nodeMetrics(), - pods: test.fields.pods(), - podMetrics: test.fields.podMetrics(), + nodes: nodeMap{ + read: test.fields.nodes.read, + dirty: test.fields.nodes.dirty, + misses: test.fields.nodes.misses, + }, + nodeMetrics: nodeMetricsMap{ + read: test.fields.nodeMetrics.read, + dirty: test.fields.nodeMetrics.dirty, + misses: test.fields.nodeMetrics.misses, + }, + pods: podsMap{ + read: test.fields.pods.read, + dirty: test.fields.pods.dirty, + misses: test.fields.pods.misses, + }, + podMetrics: podMetricsMap{ + read: test.fields.podMetrics.read, + dirty: test.fields.podMetrics.dirty, + misses: test.fields.podMetrics.misses, + }, podsByNode: test.fields.podsByNode, podsByNamespace: test.fields.podsByNamespace, podsByName: test.fields.podsByName, @@ -447,10 +511,26 @@ func Test_discoverer_GetNodes(t *testing.T) { } type fields struct { maxPods int - nodes func() nodeMap - nodeMetrics func() nodeMetricsMap - pods func() podsMap - podMetrics func() podMetricsMap + nodes struct { + read atomic.Value + dirty map[string]*entryNodeMap + misses int + } + nodeMetrics struct { + read atomic.Value + dirty map[string]*entryNodeMetricsMap + misses int + } + pods struct { + read atomic.Value + dirty map[string]*entryPodsMap + misses int + } + podMetrics struct { + read atomic.Value + dirty map[string]*entryPodMetricsMap + misses int + } podsByNode atomic.Value podsByNamespace atomic.Value podsByName atomic.Value @@ -494,10 +574,10 @@ func Test_discoverer_GetNodes(t *testing.T) { }, fields: fields { maxPods: 0, - nodes: nodeMap{}, - nodeMetrics: nodeMetricsMap{}, - pods: podsMap{}, - podMetrics: podMetricsMap{}, + nodes: struct{}, + nodeMetrics: struct{}, + pods: struct{}, + podMetrics: struct{}, podsByNode: nil, podsByNamespace: nil, podsByName: nil, @@ -530,10 +610,10 @@ func Test_discoverer_GetNodes(t *testing.T) { }, fields: fields { maxPods: 0, - nodes: nodeMap{}, - nodeMetrics: nodeMetricsMap{}, - pods: podsMap{}, - podMetrics: podMetricsMap{}, + nodes: struct{}, + nodeMetrics: struct{}, + pods: struct{}, + podMetrics: struct{}, podsByNode: nil, podsByNamespace: nil, podsByName: nil, @@ -575,10 +655,26 @@ func Test_discoverer_GetNodes(t *testing.T) { } d := &discoverer{ maxPods: test.fields.maxPods, - nodes: test.fields.nodes(), - nodeMetrics: test.fields.nodeMetrics(), - pods: test.fields.pods(), - podMetrics: test.fields.podMetrics(), + nodes: nodeMap{ + read: test.fields.nodes.read, + dirty: test.fields.nodes.dirty, + misses: test.fields.nodes.misses, + }, + nodeMetrics: nodeMetricsMap{ + read: test.fields.nodeMetrics.read, + dirty: test.fields.nodeMetrics.dirty, + misses: test.fields.nodeMetrics.misses, + }, + pods: podsMap{ + read: test.fields.pods.read, + dirty: test.fields.pods.dirty, + misses: test.fields.pods.misses, + }, + podMetrics: podMetricsMap{ + read: test.fields.podMetrics.read, + dirty: test.fields.podMetrics.dirty, + misses: test.fields.podMetrics.misses, + }, podsByNode: test.fields.podsByNode, podsByNamespace: test.fields.podsByNamespace, podsByName: test.fields.podsByName, From f4e45345223158612c8aca9adad1378558804da9 Mon Sep 17 00:00:00 2001 From: vankichi Date: Tue, 22 Nov 2022 11:46:04 +0900 Subject: [PATCH 5/5] :recycle: Fix format Signed-off-by: vankichi --- pkg/discoverer/k8s/service/discover_test.go | 15 +++++----- pkg/discoverer/k8s/service/nodemap_test.go | 28 ++++--------------- .../k8s/service/nodemetricsmap_test.go | 27 ++++-------------- .../k8s/service/podmetricsmap_test.go | 27 ++++-------------- pkg/discoverer/k8s/service/podsmap_test.go | 27 ++++-------------- 5 files changed, 31 insertions(+), 93 deletions(-) diff --git a/pkg/discoverer/k8s/service/discover_test.go b/pkg/discoverer/k8s/service/discover_test.go index 553a456543..6e3cfb8ad5 100644 --- a/pkg/discoverer/k8s/service/discover_test.go +++ b/pkg/discoverer/k8s/service/discover_test.go @@ -131,7 +131,7 @@ func Test_discoverer_Start(t *testing.T) { } type fields struct { maxPods int - nodes struct { + nodes struct { read atomic.Value dirty map[string]*entryNodeMap misses int @@ -320,8 +320,8 @@ func Test_discoverer_GetPods(t *testing.T) { req *payload.Discoverer_Request } type fields struct { - maxPods int - nodes struct { + maxPods int + nodes struct { read atomic.Value dirty map[string]*entryNodeMap misses int @@ -464,7 +464,7 @@ func Test_discoverer_GetPods(t *testing.T) { checkFunc = defaultCheckFunc } d := &discoverer{ - maxPods: test.fields.maxPods, + maxPods: test.fields.maxPods, nodes: nodeMap{ read: test.fields.nodes.read, dirty: test.fields.nodes.dirty, @@ -510,8 +510,8 @@ func Test_discoverer_GetNodes(t *testing.T) { req *payload.Discoverer_Request } type fields struct { - maxPods int - nodes struct { + maxPods int + nodes struct { read atomic.Value dirty map[string]*entryNodeMap misses int @@ -654,7 +654,7 @@ func Test_discoverer_GetNodes(t *testing.T) { checkFunc = defaultCheckFunc } d := &discoverer{ - maxPods: test.fields.maxPods, + maxPods: test.fields.maxPods, nodes: nodeMap{ read: test.fields.nodes.read, dirty: test.fields.nodes.dirty, @@ -691,7 +691,6 @@ func Test_discoverer_GetNodes(t *testing.T) { if err := checkFunc(test.want, gotNodes, err); err != nil { tt.Errorf("error = %v", err) } - }) } } diff --git a/pkg/discoverer/k8s/service/nodemap_test.go b/pkg/discoverer/k8s/service/nodemap_test.go index 4061e2a543..73065093f3 100644 --- a/pkg/discoverer/k8s/service/nodemap_test.go +++ b/pkg/discoverer/k8s/service/nodemap_test.go @@ -108,7 +108,6 @@ func Test_newEntryNodeMap(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -219,7 +218,6 @@ func Test_nodeMap_Load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -312,7 +310,6 @@ func Test_entryNodeMap_load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -327,8 +324,7 @@ func Test_nodeMap_Store(t *testing.T) { dirty map[string]*entryNodeMap misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -516,7 +512,6 @@ func Test_entryNodeMap_tryStore(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -605,7 +600,6 @@ func Test_entryNodeMap_unexpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotWasExpunged); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -617,8 +611,7 @@ func Test_entryNodeMap_storeLocked(t *testing.T) { type fields struct { p unsafe.Pointer } - type want struct { - } + type want struct{} type test struct { name string args args @@ -813,7 +806,6 @@ func Test_nodeMap_LoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -920,7 +912,6 @@ func Test_entryNodeMap_tryLoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -1031,7 +1022,6 @@ func Test_nodeMap_LoadAndDelete(t *testing.T) { if err := checkFunc(test.want, gotValue, gotLoaded); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -1045,8 +1035,7 @@ func Test_nodeMap_Delete(t *testing.T) { dirty map[string]*entryNodeMap misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -1226,7 +1215,6 @@ func Test_entryNodeMap_delete(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -1240,8 +1228,7 @@ func Test_nodeMap_Range(t *testing.T) { dirty map[string]*entryNodeMap misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -1339,8 +1326,7 @@ func Test_nodeMap_missLocked(t *testing.T) { dirty map[string]*entryNodeMap misses int } - type want struct { - } + type want struct{} type test struct { name string fields fields @@ -1431,8 +1417,7 @@ func Test_nodeMap_dirtyLocked(t *testing.T) { dirty map[string]*entryNodeMap misses int } - type want struct { - } + type want struct{} type test struct { name string fields fields @@ -1601,7 +1586,6 @@ func Test_entryNodeMap_tryExpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotIsExpunged); err != nil { tt.Errorf("error = %v", err) } - }) } } diff --git a/pkg/discoverer/k8s/service/nodemetricsmap_test.go b/pkg/discoverer/k8s/service/nodemetricsmap_test.go index ef46202d6d..23e4427b9d 100644 --- a/pkg/discoverer/k8s/service/nodemetricsmap_test.go +++ b/pkg/discoverer/k8s/service/nodemetricsmap_test.go @@ -108,7 +108,6 @@ func Test_newEntryNodeMetricsMap(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -219,7 +218,6 @@ func Test_nodeMetricsMap_Load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -312,7 +310,6 @@ func Test_entryNodeMetricsMap_load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -327,8 +324,7 @@ func Test_nodeMetricsMap_Store(t *testing.T) { dirty map[string]*entryNodeMetricsMap misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -516,7 +512,6 @@ func Test_entryNodeMetricsMap_tryStore(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -605,7 +600,6 @@ func Test_entryNodeMetricsMap_unexpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotWasExpunged); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -617,8 +611,7 @@ func Test_entryNodeMetricsMap_storeLocked(t *testing.T) { type fields struct { p unsafe.Pointer } - type want struct { - } + type want struct{} type test struct { name string args args @@ -813,7 +806,6 @@ func Test_nodeMetricsMap_LoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -920,7 +912,6 @@ func Test_entryNodeMetricsMap_tryLoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -934,8 +925,7 @@ func Test_nodeMetricsMap_Delete(t *testing.T) { dirty map[string]*entryNodeMetricsMap misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -1111,7 +1101,6 @@ func Test_entryNodeMetricsMap_delete(t *testing.T) { if err := checkFunc(test.want, gotHadValue); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -1125,8 +1114,7 @@ func Test_nodeMetricsMap_Range(t *testing.T) { dirty map[string]*entryNodeMetricsMap misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -1224,8 +1212,7 @@ func Test_nodeMetricsMap_missLocked(t *testing.T) { dirty map[string]*entryNodeMetricsMap misses int } - type want struct { - } + type want struct{} type test struct { name string fields fields @@ -1316,8 +1303,7 @@ func Test_nodeMetricsMap_dirtyLocked(t *testing.T) { dirty map[string]*entryNodeMetricsMap misses int } - type want struct { - } + type want struct{} type test struct { name string fields fields @@ -1486,7 +1472,6 @@ func Test_entryNodeMetricsMap_tryExpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotIsExpunged); err != nil { tt.Errorf("error = %v", err) } - }) } } diff --git a/pkg/discoverer/k8s/service/podmetricsmap_test.go b/pkg/discoverer/k8s/service/podmetricsmap_test.go index 051afb45e7..3b3c95859d 100644 --- a/pkg/discoverer/k8s/service/podmetricsmap_test.go +++ b/pkg/discoverer/k8s/service/podmetricsmap_test.go @@ -108,7 +108,6 @@ func Test_newEntryPodMetricsMap(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -219,7 +218,6 @@ func Test_podMetricsMap_Load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -312,7 +310,6 @@ func Test_entryPodMetricsMap_load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -327,8 +324,7 @@ func Test_podMetricsMap_Store(t *testing.T) { dirty map[string]*entryPodMetricsMap misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -516,7 +512,6 @@ func Test_entryPodMetricsMap_tryStore(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -605,7 +600,6 @@ func Test_entryPodMetricsMap_unexpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotWasExpunged); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -617,8 +611,7 @@ func Test_entryPodMetricsMap_storeLocked(t *testing.T) { type fields struct { p unsafe.Pointer } - type want struct { - } + type want struct{} type test struct { name string args args @@ -813,7 +806,6 @@ func Test_podMetricsMap_LoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -920,7 +912,6 @@ func Test_entryPodMetricsMap_tryLoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -934,8 +925,7 @@ func Test_podMetricsMap_Delete(t *testing.T) { dirty map[string]*entryPodMetricsMap misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -1111,7 +1101,6 @@ func Test_entryPodMetricsMap_delete(t *testing.T) { if err := checkFunc(test.want, gotHadValue); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -1125,8 +1114,7 @@ func Test_podMetricsMap_Range(t *testing.T) { dirty map[string]*entryPodMetricsMap misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -1224,8 +1212,7 @@ func Test_podMetricsMap_missLocked(t *testing.T) { dirty map[string]*entryPodMetricsMap misses int } - type want struct { - } + type want struct{} type test struct { name string fields fields @@ -1316,8 +1303,7 @@ func Test_podMetricsMap_dirtyLocked(t *testing.T) { dirty map[string]*entryPodMetricsMap misses int } - type want struct { - } + type want struct{} type test struct { name string fields fields @@ -1486,7 +1472,6 @@ func Test_entryPodMetricsMap_tryExpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotIsExpunged); err != nil { tt.Errorf("error = %v", err) } - }) } } diff --git a/pkg/discoverer/k8s/service/podsmap_test.go b/pkg/discoverer/k8s/service/podsmap_test.go index d86d43ad55..c04a24155d 100644 --- a/pkg/discoverer/k8s/service/podsmap_test.go +++ b/pkg/discoverer/k8s/service/podsmap_test.go @@ -108,7 +108,6 @@ func Test_newEntryPodsMap(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -219,7 +218,6 @@ func Test_podsMap_Load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -312,7 +310,6 @@ func Test_entryPodsMap_load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -327,8 +324,7 @@ func Test_podsMap_Store(t *testing.T) { dirty map[string]*entryPodsMap misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -516,7 +512,6 @@ func Test_entryPodsMap_tryStore(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -605,7 +600,6 @@ func Test_entryPodsMap_unexpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotWasExpunged); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -617,8 +611,7 @@ func Test_entryPodsMap_storeLocked(t *testing.T) { type fields struct { p unsafe.Pointer } - type want struct { - } + type want struct{} type test struct { name string args args @@ -813,7 +806,6 @@ func Test_podsMap_LoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -920,7 +912,6 @@ func Test_entryPodsMap_tryLoadOrStore(t *testing.T) { if err := checkFunc(test.want, gotActual, gotLoaded, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -934,8 +925,7 @@ func Test_podsMap_Delete(t *testing.T) { dirty map[string]*entryPodsMap misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -1111,7 +1101,6 @@ func Test_entryPodsMap_delete(t *testing.T) { if err := checkFunc(test.want, gotHadValue); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -1125,8 +1114,7 @@ func Test_podsMap_Range(t *testing.T) { dirty map[string]*entryPodsMap misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -1224,8 +1212,7 @@ func Test_podsMap_missLocked(t *testing.T) { dirty map[string]*entryPodsMap misses int } - type want struct { - } + type want struct{} type test struct { name string fields fields @@ -1316,8 +1303,7 @@ func Test_podsMap_dirtyLocked(t *testing.T) { dirty map[string]*entryPodsMap misses int } - type want struct { - } + type want struct{} type test struct { name string fields fields @@ -1486,7 +1472,6 @@ func Test_entryPodsMap_tryExpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotIsExpunged); err != nil { tt.Errorf("error = %v", err) } - }) } }