diff --git a/README.md b/README.md index 9d1fccbd4b..2b085c4799 100755 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fvdaas%2Fvald.svg?type=small&style=flat-square)](https://app.fossa.com/projects/git%2Bgithub.com%2Fvdaas%2Fvald?ref=badge_small) [![DeepSource](https://static.deepsource.io/deepsource-badge-light-mini.svg)](https://deepsource.io/gh/vdaas/vald/?ref=repository-badge) [![CLA](https://cla-assistant.io/readme/badge/vdaas/vald?&style=flat-square)](https://cla-assistant.io/vdaas/vald) +[![Artifact Hub](https://img.shields.io/badge/chart-ArtifactHub-informational?logo=helm&style=flat-square)](https://artifacthub.io/packages/chart/vald/vald) [![Slack](https://img.shields.io/badge/slack-join-brightgreen?logo=slack&style=flat-square)](https://join.slack.com/t/vald-community/shared_invite/zt-db2ky9o4-R_9p2sVp8xRwztVa8gfnPA) [![Twitter](https://img.shields.io/badge/twitter-follow-blue?logo=twitter&style=flat-square)](https://twitter.com/vdaas_vald) diff --git a/charts/vald-helm-operator/Chart.yaml b/charts/vald-helm-operator/Chart.yaml index cf24b04e01..4e2cad8e01 100644 --- a/charts/vald-helm-operator/Chart.yaml +++ b/charts/vald-helm-operator/Chart.yaml @@ -22,14 +22,26 @@ type: application keywords: - Vald - NGT -home: https://vdaas.org + - vector + - search + - approximate-nearest-neighbor-search + - nearest-neighbor-search + - vector-search-engine + - similarity-search + - image-search + - operator + - Kubernetes + - k8s + - AI + - artificial-intelligence +home: https://vald.vdaas.org icon: https://raw.githubusercontent.com/vdaas/vald/master/assets/image/svg/icon_color.svg sources: - https://github.com/vdaas/vald maintainers: - name: kpango - email: i.can.feel.gravity@gmail.com + email: kpango@vdaas.org - name: rinx - email: rintaro.okamura@gmail.com + email: rinx@vdaas.org - name: kmrmt - email: kou.morimoto@gmail.com + email: ksk@vdaas.org diff --git a/charts/vald-helm-operator/README.md.gotmpl b/charts/vald-helm-operator/README.md.gotmpl index f5777a5afd..41e6e9e691 100644 --- a/charts/vald-helm-operator/README.md.gotmpl +++ b/charts/vald-helm-operator/README.md.gotmpl @@ -5,6 +5,15 @@ This is a Helm chart to install vald-helm-operator. {{ template "chart.versionLine" . }} +Table of Contents +--- + +- [Install](#install) +- [Custom Resources](#custom-resources) + - [ValdRelease](#valdrelease) + - [ValdHelmOperatorRelease](#valdhelmoperatorrelease) +- [Configuration](#configuration) + Install --- diff --git a/charts/vald/Chart.yaml b/charts/vald/Chart.yaml index b7a3854a88..219b2e0ea5 100644 --- a/charts/vald/Chart.yaml +++ b/charts/vald/Chart.yaml @@ -22,14 +22,25 @@ type: application keywords: - Vald - NGT -home: https://vdaas.org + - vector + - search + - approximate-nearest-neighbor-search + - nearest-neighbor-search + - vector-search-engine + - similarity-search + - image-search + - Kubernetes + - k8s + - AI + - artificial-intelligence +home: https://vald.vdaas.org icon: https://raw.githubusercontent.com/vdaas/vald/master/assets/image/svg/icon_color.svg sources: - https://github.com/vdaas/vald maintainers: - name: kpango - email: i.can.feel.gravity@gmail.com + email: kpango@vdaas.org - name: rinx - email: rintaro.okamura@gmail.com + email: rinx@vdaas.org - name: kmrmt - email: kou.morimoto@gmail.com + email: ksk@vdaas.org diff --git a/charts/vald/README.md.gotmpl b/charts/vald/README.md.gotmpl index 5800a71bd5..c79db71f02 100644 --- a/charts/vald/README.md.gotmpl +++ b/charts/vald/README.md.gotmpl @@ -5,6 +5,16 @@ This is a Helm chart to install Vald components. {{ template "chart.versionLine" . }} +Table of Contents +--- + +- [Install](#install) +- [Configuration](#configuration) + - [Overview](#overview) + - [Parameters](#parameters) +- [Miscellaneous](#miscellaneous) + - [Standalone Vald agent NGT deployment](#standalone-vald-agent-ngt-deployment) + Install --- diff --git a/internal/config/observability_test.go b/internal/config/observability_test.go index d109f9cc5e..26ac1d74a3 100644 --- a/internal/config/observability_test.go +++ b/internal/config/observability_test.go @@ -27,11 +27,12 @@ import ( func TestObservability_Bind(t *testing.T) { type fields struct { - Enabled bool - Collector *Collector - Trace *Trace - Prometheus *Prometheus - Jaeger *Jaeger + Enabled bool + Collector *Collector + Trace *Trace + Prometheus *Prometheus + Jaeger *Jaeger + Stackdriver *Stackdriver } type want struct { want *Observability @@ -61,6 +62,7 @@ func TestObservability_Bind(t *testing.T) { Trace: Trace{}, Prometheus: Prometheus{}, Jaeger: Jaeger{}, + Stackdriver: Stackdriver{}, }, want: want{}, checkFunc: defaultCheckFunc, @@ -78,6 +80,7 @@ func TestObservability_Bind(t *testing.T) { Trace: Trace{}, Prometheus: Prometheus{}, Jaeger: Jaeger{}, + Stackdriver: Stackdriver{}, }, want: want{}, checkFunc: defaultCheckFunc, @@ -88,6 +91,7 @@ func TestObservability_Bind(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc() } @@ -98,11 +102,12 @@ func TestObservability_Bind(t *testing.T) { test.checkFunc = defaultCheckFunc } o := &Observability{ - Enabled: test.fields.Enabled, - Collector: test.fields.Collector, - Trace: test.fields.Trace, - Prometheus: test.fields.Prometheus, - Jaeger: test.fields.Jaeger, + Enabled: test.fields.Enabled, + Collector: test.fields.Collector, + Trace: test.fields.Trace, + Prometheus: test.fields.Prometheus, + Jaeger: test.fields.Jaeger, + Stackdriver: test.fields.Stackdriver, } got := o.Bind() @@ -114,9 +119,88 @@ func TestObservability_Bind(t *testing.T) { } } +func TestCollector_Bind(t *testing.T) { + type fields struct { + Duration string + Metrics *Metrics + } + type want struct { + want *Collector + } + type test struct { + name string + fields fields + want want + checkFunc func(want, *Collector) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want, got *Collector) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got = %v, want %v", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + Duration: "", + Metrics: Metrics{}, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + Duration: "", + Metrics: Metrics{}, + }, + want: want{}, + checkFunc: defaultCheckFunc, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + c := &Collector{ + Duration: test.fields.Duration, + Metrics: test.fields.Metrics, + } + + got := c.Bind() + if err := test.checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + func TestStackdriver_Bind(t *testing.T) { type fields struct { ProjectID string + Client *StackdriverClient Exporter *StackdriverExporter Profiler *StackdriverProfiler } @@ -144,6 +228,7 @@ func TestStackdriver_Bind(t *testing.T) { name: "test_case_1", fields: fields { ProjectID: "", + Client: StackdriverClient{}, Exporter: StackdriverExporter{}, Profiler: StackdriverProfiler{}, }, @@ -159,6 +244,7 @@ func TestStackdriver_Bind(t *testing.T) { name: "test_case_2", fields: fields { ProjectID: "", + Client: StackdriverClient{}, Exporter: StackdriverExporter{}, Profiler: StackdriverProfiler{}, }, @@ -183,6 +269,7 @@ func TestStackdriver_Bind(t *testing.T) { } sd := &Stackdriver{ ProjectID: test.fields.ProjectID, + Client: test.fields.Client, Exporter: test.fields.Exporter, Profiler: test.fields.Profiler, } diff --git a/internal/observability/client/google/option_test.go b/internal/observability/client/google/option_test.go new file mode 100644 index 0000000000..f30d322b05 --- /dev/null +++ b/internal/observability/client/google/option_test.go @@ -0,0 +1,1278 @@ +// +// Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt ) +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// Package google provides a google API client options. +package google + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestWithAPIKey(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + apiKey string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + apiKey: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + apiKey: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc(test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithAPIKey(test.args.apiKey) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithAPIKey(test.args.apiKey) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithAudiences(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + audiences []string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + audiences: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + audiences: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc(test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithAudiences(test.args.audiences...) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithAudiences(test.args.audiences...) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithCredentialsFile(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + path string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + path: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + path: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc(test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithCredentialsFile(test.args.path) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithCredentialsFile(test.args.path) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithEndpoint(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + endpoint string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + endpoint: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + endpoint: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc(test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithEndpoint(test.args.endpoint) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithEndpoint(test.args.endpoint) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithQuotaProject(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + qp string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + qp: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + qp: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc(test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithQuotaProject(test.args.qp) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithQuotaProject(test.args.qp) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithRequestReason(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + rr string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + rr: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + rr: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc(test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithRequestReason(test.args.rr) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithRequestReason(test.args.rr) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithScopes(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + scopes []string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + scopes: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + scopes: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc(test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithScopes(test.args.scopes...) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithScopes(test.args.scopes...) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithUserAgent(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + ua string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ua: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ua: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc(test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithUserAgent(test.args.ua) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithUserAgent(test.args.ua) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithCredentialsJSON(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + json string + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + json: "", + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + json: "", + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc(test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithCredentialsJSON(test.args.json) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithCredentialsJSON(test.args.json) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithTelemetry(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + enabled bool + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + enabled: false, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + enabled: false, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc(test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithTelemetry(test.args.enabled) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithTelemetry(test.args.enabled) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithAuthentication(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + enabled bool + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + enabled: false, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + enabled: false, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc(test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + + got := WithAuthentication(test.args.enabled) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithAuthentication(test.args.enabled) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} diff --git a/internal/observability/collector/collector_option_test.go b/internal/observability/collector/collector_option_test.go index 5adcd9658c..c14c09920d 100644 --- a/internal/observability/collector/collector_option_test.go +++ b/internal/observability/collector/collector_option_test.go @@ -22,11 +22,11 @@ import ( "github.com/vdaas/vald/internal/errgroup" "github.com/vdaas/vald/internal/observability/metrics" - "go.uber.org/goleak" ) func TestWithErrGroup(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { eg errgroup.Group @@ -64,7 +64,7 @@ func TestWithErrGroup(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -102,7 +102,7 @@ func TestWithErrGroup(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -123,7 +123,7 @@ func TestWithErrGroup(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -131,7 +131,7 @@ func TestWithErrGroup(t *testing.T) { got := WithErrGroup(test.args.eg) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -140,6 +140,7 @@ func TestWithErrGroup(t *testing.T) { } func TestWithDuration(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { dur string @@ -177,7 +178,7 @@ func TestWithDuration(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -215,7 +216,7 @@ func TestWithDuration(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -236,7 +237,7 @@ func TestWithDuration(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -244,7 +245,7 @@ func TestWithDuration(t *testing.T) { got := WithDuration(test.args.dur) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -253,6 +254,7 @@ func TestWithDuration(t *testing.T) { } func TestWithMetrics(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { metrics []metrics.Metric @@ -290,7 +292,7 @@ func TestWithMetrics(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -328,7 +330,7 @@ func TestWithMetrics(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -349,7 +351,7 @@ func TestWithMetrics(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -357,7 +359,7 @@ func TestWithMetrics(t *testing.T) { got := WithMetrics(test.args.metrics...) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -366,9 +368,11 @@ func TestWithMetrics(t *testing.T) { } func TestWithVersionInfo(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { enabled bool + labels []string } type want struct { obj *T @@ -403,7 +407,7 @@ func TestWithVersionInfo(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -416,6 +420,7 @@ func TestWithVersionInfo(t *testing.T) { name: "test_case_1", args: args { enabled: false, + labels: nil, }, want: want { obj: new(T), @@ -430,6 +435,7 @@ func TestWithVersionInfo(t *testing.T) { name: "test_case_2", args: args { enabled: false, + labels: nil, }, want: want { obj: new(T), @@ -441,7 +447,7 @@ func TestWithVersionInfo(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -455,22 +461,22 @@ func TestWithVersionInfo(t *testing.T) { test.checkFunc = defaultCheckFunc } - got := WithVersionInfo(test.args.enabled) + got := WithVersionInfo(test.args.enabled, test.args.labels...) obj := new(T) if err := test.checkFunc(test.want, obj, got(obj)); err != nil { tt.Errorf("error = %v", err) } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - got := WithVersionInfo(test.args.enabled) + got := WithVersionInfo(test.args.enabled, test.args.labels...) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -479,6 +485,7 @@ func TestWithVersionInfo(t *testing.T) { } func TestWithMemoryMetrics(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { enabled bool @@ -516,7 +523,7 @@ func TestWithMemoryMetrics(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -554,7 +561,7 @@ func TestWithMemoryMetrics(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -575,7 +582,7 @@ func TestWithMemoryMetrics(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -583,7 +590,7 @@ func TestWithMemoryMetrics(t *testing.T) { got := WithMemoryMetrics(test.args.enabled) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -592,6 +599,7 @@ func TestWithMemoryMetrics(t *testing.T) { } func TestWithGoroutineMetrics(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { enabled bool @@ -629,7 +637,7 @@ func TestWithGoroutineMetrics(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -667,7 +675,7 @@ func TestWithGoroutineMetrics(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -688,7 +696,7 @@ func TestWithGoroutineMetrics(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -696,7 +704,7 @@ func TestWithGoroutineMetrics(t *testing.T) { got := WithGoroutineMetrics(test.args.enabled) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -705,6 +713,7 @@ func TestWithGoroutineMetrics(t *testing.T) { } func TestWithCGOMetrics(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { enabled bool @@ -742,7 +751,7 @@ func TestWithCGOMetrics(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -780,7 +789,7 @@ func TestWithCGOMetrics(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -801,7 +810,7 @@ func TestWithCGOMetrics(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -809,7 +818,7 @@ func TestWithCGOMetrics(t *testing.T) { got := WithCGOMetrics(test.args.enabled) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ diff --git a/internal/observability/exporter/jaeger/jaeger_option_test.go b/internal/observability/exporter/jaeger/jaeger_option_test.go index d82c358b30..f17451bc28 100644 --- a/internal/observability/exporter/jaeger/jaeger_option_test.go +++ b/internal/observability/exporter/jaeger/jaeger_option_test.go @@ -24,6 +24,7 @@ import ( ) func TestWithCollectorEndpoint(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { cep string @@ -61,7 +62,7 @@ func TestWithCollectorEndpoint(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -99,7 +100,7 @@ func TestWithCollectorEndpoint(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -120,7 +121,7 @@ func TestWithCollectorEndpoint(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -128,7 +129,7 @@ func TestWithCollectorEndpoint(t *testing.T) { got := WithCollectorEndpoint(test.args.cep) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -137,6 +138,7 @@ func TestWithCollectorEndpoint(t *testing.T) { } func TestWithAgentEndpoint(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { aep string @@ -174,7 +176,7 @@ func TestWithAgentEndpoint(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -212,7 +214,7 @@ func TestWithAgentEndpoint(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -233,7 +235,7 @@ func TestWithAgentEndpoint(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -241,7 +243,7 @@ func TestWithAgentEndpoint(t *testing.T) { got := WithAgentEndpoint(test.args.aep) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -250,6 +252,7 @@ func TestWithAgentEndpoint(t *testing.T) { } func TestWithUsername(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { username string @@ -287,7 +290,7 @@ func TestWithUsername(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -325,7 +328,7 @@ func TestWithUsername(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -346,7 +349,7 @@ func TestWithUsername(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -354,7 +357,7 @@ func TestWithUsername(t *testing.T) { got := WithUsername(test.args.username) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -363,6 +366,7 @@ func TestWithUsername(t *testing.T) { } func TestWithPassword(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { password string @@ -400,7 +404,7 @@ func TestWithPassword(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -438,7 +442,7 @@ func TestWithPassword(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -459,7 +463,7 @@ func TestWithPassword(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -467,7 +471,7 @@ func TestWithPassword(t *testing.T) { got := WithPassword(test.args.password) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -476,6 +480,7 @@ func TestWithPassword(t *testing.T) { } func TestWithServiceName(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { serviceName string @@ -513,7 +518,7 @@ func TestWithServiceName(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -551,7 +556,7 @@ func TestWithServiceName(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -572,7 +577,7 @@ func TestWithServiceName(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -580,7 +585,7 @@ func TestWithServiceName(t *testing.T) { got := WithServiceName(test.args.serviceName) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -589,6 +594,7 @@ func TestWithServiceName(t *testing.T) { } func TestWithBufferMaxCount(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { cnt int @@ -626,7 +632,7 @@ func TestWithBufferMaxCount(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -664,7 +670,7 @@ func TestWithBufferMaxCount(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -685,7 +691,7 @@ func TestWithBufferMaxCount(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -693,7 +699,7 @@ func TestWithBufferMaxCount(t *testing.T) { got := WithBufferMaxCount(test.args.cnt) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -702,6 +708,7 @@ func TestWithBufferMaxCount(t *testing.T) { } func TestWithOnErrorFunc(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { f func(error) @@ -739,7 +746,7 @@ func TestWithOnErrorFunc(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -777,7 +784,7 @@ func TestWithOnErrorFunc(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -798,7 +805,7 @@ func TestWithOnErrorFunc(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -806,7 +813,7 @@ func TestWithOnErrorFunc(t *testing.T) { got := WithOnErrorFunc(test.args.f) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ diff --git a/internal/observability/exporter/jaeger/jaeger_test.go b/internal/observability/exporter/jaeger/jaeger_test.go index edacacd50f..d271000f9b 100644 --- a/internal/observability/exporter/jaeger/jaeger_test.go +++ b/internal/observability/exporter/jaeger/jaeger_test.go @@ -24,7 +24,6 @@ import ( "contrib.go.opencensus.io/exporter/jaeger" "github.com/vdaas/vald/internal/errors" - "go.uber.org/goleak" ) @@ -83,7 +82,7 @@ func TestNew(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -103,7 +102,7 @@ func TestNew(t *testing.T) { } } -func Test_exporter_Start(t *testing.T) { +func Test_exp_Start(t *testing.T) { type args struct { ctx context.Context } @@ -167,7 +166,7 @@ func Test_exporter_Start(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -177,7 +176,7 @@ func Test_exporter_Start(t *testing.T) { if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - e := &exporter{ + e := &exp{ exporter: test.fields.exporter, options: test.fields.options, } @@ -191,7 +190,7 @@ func Test_exporter_Start(t *testing.T) { } } -func Test_exporter_Stop(t *testing.T) { +func Test_exp_Stop(t *testing.T) { type args struct { ctx context.Context } @@ -251,7 +250,7 @@ func Test_exporter_Stop(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -261,7 +260,7 @@ func Test_exporter_Stop(t *testing.T) { if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - e := &exporter{ + e := &exp{ exporter: test.fields.exporter, options: test.fields.options, } diff --git a/internal/observability/exporter/prometheus/prometheus_option_test.go b/internal/observability/exporter/prometheus/prometheus_option_test.go index 1a58d02117..21097a8796 100644 --- a/internal/observability/exporter/prometheus/prometheus_option_test.go +++ b/internal/observability/exporter/prometheus/prometheus_option_test.go @@ -24,6 +24,7 @@ import ( ) func TestWithEndpoint(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { ep string @@ -61,7 +62,7 @@ func TestWithEndpoint(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -99,7 +100,7 @@ func TestWithEndpoint(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -120,7 +121,7 @@ func TestWithEndpoint(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -128,7 +129,7 @@ func TestWithEndpoint(t *testing.T) { got := WithEndpoint(test.args.ep) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -137,6 +138,7 @@ func TestWithEndpoint(t *testing.T) { } func TestWithNamespace(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { ns string @@ -174,7 +176,7 @@ func TestWithNamespace(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -212,7 +214,7 @@ func TestWithNamespace(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -233,7 +235,7 @@ func TestWithNamespace(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -241,7 +243,7 @@ func TestWithNamespace(t *testing.T) { got := WithNamespace(test.args.ns) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -250,6 +252,7 @@ func TestWithNamespace(t *testing.T) { } func TestWithOnErrorFunc(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { f func(error) @@ -287,7 +290,7 @@ func TestWithOnErrorFunc(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -325,7 +328,7 @@ func TestWithOnErrorFunc(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -346,7 +349,7 @@ func TestWithOnErrorFunc(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -354,7 +357,7 @@ func TestWithOnErrorFunc(t *testing.T) { got := WithOnErrorFunc(test.args.f) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ diff --git a/internal/observability/exporter/prometheus/prometheus_test.go b/internal/observability/exporter/prometheus/prometheus_test.go index b489fd9150..598bdbb56e 100644 --- a/internal/observability/exporter/prometheus/prometheus_test.go +++ b/internal/observability/exporter/prometheus/prometheus_test.go @@ -83,7 +83,7 @@ func TestNew(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -103,7 +103,7 @@ func TestNew(t *testing.T) { } } -func Test_exporter_Start(t *testing.T) { +func Test_exp_Start(t *testing.T) { type args struct { ctx context.Context } @@ -167,7 +167,7 @@ func Test_exporter_Start(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -177,7 +177,7 @@ func Test_exporter_Start(t *testing.T) { if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - e := &exporter{ + e := &exp{ exporter: test.fields.exporter, options: test.fields.options, } @@ -191,7 +191,7 @@ func Test_exporter_Start(t *testing.T) { } } -func Test_exporter_Stop(t *testing.T) { +func Test_exp_Stop(t *testing.T) { type args struct { ctx context.Context } @@ -251,7 +251,7 @@ func Test_exporter_Stop(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -261,7 +261,7 @@ func Test_exporter_Stop(t *testing.T) { if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - e := &exporter{ + e := &exp{ exporter: test.fields.exporter, options: test.fields.options, } @@ -274,7 +274,7 @@ func Test_exporter_Stop(t *testing.T) { } } -func Test_exporter_NewHTTPHandler(t *testing.T) { +func Test_exp_NewHTTPHandler(t *testing.T) { type fields struct { exporter *prometheus.Exporter options prometheusOptions @@ -338,7 +338,7 @@ func Test_exporter_NewHTTPHandler(t *testing.T) { if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - e := &exporter{ + e := &exp{ exporter: test.fields.exporter, options: test.fields.options, } diff --git a/internal/observability/exporter/stackdriver/stackdriver_option_test.go b/internal/observability/exporter/stackdriver/stackdriver_option_test.go index f527d2183e..77979eeaa4 100644 --- a/internal/observability/exporter/stackdriver/stackdriver_option_test.go +++ b/internal/observability/exporter/stackdriver/stackdriver_option_test.go @@ -22,9 +22,9 @@ import ( "contrib.go.opencensus.io/exporter/stackdriver" "contrib.go.opencensus.io/exporter/stackdriver/monitoredresource" + "github.com/vdaas/vald/internal/observability/client/google" "github.com/vdaas/vald/internal/observability/metrics" "go.uber.org/goleak" - "google.golang.org/api/option" ) func TestWithMonitoring(t *testing.T) { @@ -601,7 +601,7 @@ func TestWithMonitoringClientOptions(t *testing.T) { // Change interface type to the type of object you are testing type T = interface{} type args struct { - copts []option.ClientOption + copts []google.Option } type want struct { obj *T @@ -715,7 +715,7 @@ func TestWithTraceClientOptions(t *testing.T) { // Change interface type to the type of object you are testing type T = interface{} type args struct { - copts []option.ClientOption + copts []google.Option } type want struct { obj *T diff --git a/internal/observability/exporter/stackdriver/stackdriver_test.go b/internal/observability/exporter/stackdriver/stackdriver_test.go index da47934467..8ee18618a5 100644 --- a/internal/observability/exporter/stackdriver/stackdriver_test.go +++ b/internal/observability/exporter/stackdriver/stackdriver_test.go @@ -102,7 +102,7 @@ func TestNew(t *testing.T) { } } -func Test_exporter_Start(t *testing.T) { +func Test_exp_Start(t *testing.T) { type args struct { ctx context.Context } @@ -182,7 +182,7 @@ func Test_exporter_Start(t *testing.T) { if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - e := &exporter{ + e := &exp{ exporter: test.fields.exporter, monitoringEnabled: test.fields.monitoringEnabled, tracingEnabled: test.fields.tracingEnabled, @@ -198,7 +198,7 @@ func Test_exporter_Start(t *testing.T) { } } -func Test_exporter_Stop(t *testing.T) { +func Test_exp_Stop(t *testing.T) { type args struct { ctx context.Context } @@ -274,7 +274,7 @@ func Test_exporter_Stop(t *testing.T) { if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - e := &exporter{ + e := &exp{ exporter: test.fields.exporter, monitoringEnabled: test.fields.monitoringEnabled, tracingEnabled: test.fields.tracingEnabled, diff --git a/internal/observability/metrics/version/version_test.go b/internal/observability/metrics/version/version_test.go index 6a3e9486f5..c308124c24 100644 --- a/internal/observability/metrics/version/version_test.go +++ b/internal/observability/metrics/version/version_test.go @@ -24,21 +24,24 @@ import ( "github.com/vdaas/vald/internal/errors" "github.com/vdaas/vald/internal/observability/metrics" - "go.uber.org/goleak" ) func TestNew(t *testing.T) { + type args struct { + labels []string + } type want struct { want metrics.Metric err error } type test struct { name string + args args want want checkFunc func(want, metrics.Metric, error) error - beforeFunc func() - afterFunc func() + beforeFunc func(args) + afterFunc func(args) } defaultCheckFunc := func(w want, got metrics.Metric, err error) error { if !errors.Is(err, w.err) { @@ -54,6 +57,9 @@ func TestNew(t *testing.T) { /* { name: "test_case_1", + args: args { + labels: nil, + }, want: want{}, checkFunc: defaultCheckFunc, }, @@ -64,6 +70,9 @@ func TestNew(t *testing.T) { func() test { return test { name: "test_case_2", + args: args { + labels: nil, + }, want: want{}, checkFunc: defaultCheckFunc, } @@ -73,18 +82,18 @@ func TestNew(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - got, err := New() + got, err := New(test.args.labels...) if err := test.checkFunc(test.want, got, err); err != nil { tt.Errorf("error = %v", err) } @@ -94,16 +103,20 @@ func TestNew(t *testing.T) { } func Test_labelKVs(t *testing.T) { + type args struct { + labels []string + } type want struct { want map[metrics.Key]string err error } type test struct { name string + args args want want checkFunc func(want, map[metrics.Key]string, error) error - beforeFunc func() - afterFunc func() + beforeFunc func(args) + afterFunc func(args) } defaultCheckFunc := func(w want, got map[metrics.Key]string, err error) error { if !errors.Is(err, w.err) { @@ -119,6 +132,9 @@ func Test_labelKVs(t *testing.T) { /* { name: "test_case_1", + args: args { + labels: nil, + }, want: want{}, checkFunc: defaultCheckFunc, }, @@ -129,6 +145,9 @@ func Test_labelKVs(t *testing.T) { func() test { return test { name: "test_case_2", + args: args { + labels: nil, + }, want: want{}, checkFunc: defaultCheckFunc, } @@ -138,18 +157,18 @@ func Test_labelKVs(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - got, err := labelKVs() + got, err := labelKVs(test.args.labels...) if err := test.checkFunc(test.want, got, err); err != nil { tt.Errorf("error = %v", err) } @@ -226,7 +245,7 @@ func Test_version_Measurement(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -318,7 +337,7 @@ func Test_version_MeasurementWithTags(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -396,7 +415,7 @@ func Test_version_View(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc() } diff --git a/internal/observability/observability_option_test.go b/internal/observability/observability_option_test.go index 32b875c592..650d34e84b 100644 --- a/internal/observability/observability_option_test.go +++ b/internal/observability/observability_option_test.go @@ -29,6 +29,7 @@ import ( ) func TestWithErrGroup(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { eg errgroup.Group @@ -66,7 +67,7 @@ func TestWithErrGroup(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -104,7 +105,7 @@ func TestWithErrGroup(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -125,7 +126,7 @@ func TestWithErrGroup(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -133,7 +134,7 @@ func TestWithErrGroup(t *testing.T) { got := WithErrGroup(test.args.eg) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -142,6 +143,7 @@ func TestWithErrGroup(t *testing.T) { } func TestWithCollector(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { c collector.Collector @@ -179,7 +181,7 @@ func TestWithCollector(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -217,7 +219,7 @@ func TestWithCollector(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -238,7 +240,7 @@ func TestWithCollector(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -246,7 +248,7 @@ func TestWithCollector(t *testing.T) { got := WithCollector(test.args.c) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -255,6 +257,7 @@ func TestWithCollector(t *testing.T) { } func TestWithTracer(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { t trace.Tracer @@ -292,7 +295,7 @@ func TestWithTracer(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -330,7 +333,7 @@ func TestWithTracer(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -351,7 +354,7 @@ func TestWithTracer(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -359,7 +362,7 @@ func TestWithTracer(t *testing.T) { got := WithTracer(test.args.t) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ diff --git a/internal/observability/observability_test.go b/internal/observability/observability_test.go index 0cbd620f2e..847d17775b 100644 --- a/internal/observability/observability_test.go +++ b/internal/observability/observability_test.go @@ -91,7 +91,7 @@ func TestNewWithConfig(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -166,7 +166,7 @@ func TestNew(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } diff --git a/internal/observability/profiler/stackdriver/stackdriver_option_test.go b/internal/observability/profiler/stackdriver/stackdriver_option_test.go index 3b0ec73509..407352e1b5 100644 --- a/internal/observability/profiler/stackdriver/stackdriver_option_test.go +++ b/internal/observability/profiler/stackdriver/stackdriver_option_test.go @@ -20,8 +20,8 @@ package stackdriver import ( "testing" + "github.com/vdaas/vald/internal/observability/client/google" "go.uber.org/goleak" - "google.golang.org/api/option" ) func TestWithProjectID(t *testing.T) { @@ -1510,7 +1510,7 @@ func TestWithClientOptions(t *testing.T) { // Change interface type to the type of object you are testing type T = interface{} type args struct { - opts []option.ClientOption + copts []google.Option } type want struct { obj *T @@ -1557,7 +1557,7 @@ func TestWithClientOptions(t *testing.T) { { name: "test_case_1", args: args { - opts: nil, + copts: nil, }, want: want { obj: new(T), @@ -1571,7 +1571,7 @@ func TestWithClientOptions(t *testing.T) { return test { name: "test_case_2", args: args { - opts: nil, + copts: nil, }, want: want { obj: new(T), @@ -1597,7 +1597,7 @@ func TestWithClientOptions(t *testing.T) { test.checkFunc = defaultCheckFunc } - got := WithClientOptions(test.args.opts...) + got := WithClientOptions(test.args.copts...) obj := new(T) if err := test.checkFunc(test.want, obj, got(obj)); err != nil { tt.Errorf("error = %v", err) @@ -1609,7 +1609,7 @@ func TestWithClientOptions(t *testing.T) { if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - got := WithClientOptions(test.args.opts...) + got := WithClientOptions(test.args.copts...) obj := new(T) got(obj) if err := test.checkFunc(test.want, obj); err != nil { diff --git a/internal/observability/profiler/stackdriver/stackdriver_test.go b/internal/observability/profiler/stackdriver/stackdriver_test.go index 627a264998..3fbe7f43fd 100644 --- a/internal/observability/profiler/stackdriver/stackdriver_test.go +++ b/internal/observability/profiler/stackdriver/stackdriver_test.go @@ -24,8 +24,8 @@ import ( "cloud.google.com/go/profiler" "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/observability/client/google" "go.uber.org/goleak" - "google.golang.org/api/option" ) func TestNew(t *testing.T) { @@ -109,7 +109,7 @@ func Test_prof_Start(t *testing.T) { } type fields struct { Config *profiler.Config - clientOpts []option.ClientOption + clientOpts []google.Option } type want struct { err error @@ -190,3 +190,86 @@ func Test_prof_Start(t *testing.T) { }) } } + +func Test_prof_Stop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + Config *profiler.Config + clientOpts []google.Option + } + type want struct { + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + Config: nil, + clientOpts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + Config: nil, + clientOpts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc(test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + p := &prof{ + Config: test.fields.Config, + clientOpts: test.fields.clientOpts, + } + + p.Stop(test.args.ctx) + if err := test.checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +}