Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create test template for using gotests #327

Conversation

vankichi
Copy link
Contributor

@vankichi vankichi commented Apr 10, 2020

Signed-off-by: vankichi kyukawa315@gmail.com

Description:

I added make command and testing template for generating missing test files using gotests .
This PR is related to #325

Note:

We will update the below test files using our template.
Missing test files are below (check filled test file will be generated):

files
  • cmd/agent/ngt/main_test.go
  • cmd/cli/vdctl/main_test.go
  • cmd/discoverer/k8s/main_test.go
  • cmd/gateway/vald/main_test.go
  • cmd/manager/backup/cassandra/main_test.go
  • cmd/manager/backup/mysql/main_test.go
  • cmd/manager/compressor/main_test.go
  • cmd/manager/index/main_test.go
  • cmd/manager/replication/agent/main_test.go
  • cmd/manager/replication/controller/main_test.go
  • cmd/meta/cassandra/main_test.go
  • cmd/meta/redis/main_test.go
  • hack/benchmark/internal/assets/dataset_test.go
  • hack/benchmark/internal/assets/loader_test.go
  • hack/benchmark/internal/client/ngtd/grpc/client_test.go
  • hack/benchmark/internal/client/ngtd/grpc/option_test.go
  • hack/benchmark/internal/client/ngtd/rest/client_test.go
  • hack/benchmark/internal/client/ngtd/rest/option_test.go
  • hack/benchmark/internal/e2e/e2e_test.go
  • hack/benchmark/internal/e2e/option_test.go
  • hack/benchmark/internal/e2e/strategy/create_index_option_test.go
  • hack/benchmark/internal/e2e/strategy/create_index_test.go
  • hack/benchmark/internal/e2e/strategy/insert_option_test.go
  • hack/benchmark/internal/e2e/strategy/insert_test.go
  • hack/benchmark/internal/e2e/strategy/remove_option_test.go
  • hack/benchmark/internal/e2e/strategy/remove_test.go
  • hack/benchmark/internal/e2e/strategy/search_option_test.go
  • hack/benchmark/internal/e2e/strategy/search_test.go
  • hack/benchmark/internal/e2e/strategy/stream_insert_test.go
  • hack/benchmark/internal/e2e/strategy/stream_remove_test.go
  • hack/benchmark/internal/e2e/strategy/stream_search_option_test.go
  • hack/benchmark/internal/e2e/strategy/stream_search_test.go
  • hack/benchmark/internal/starter/agent/ngt/ngt_test.go
  • hack/benchmark/internal/starter/agent/ngt/option_test.go
  • hack/benchmark/internal/starter/external/ngtd/ngtd_test.go
  • hack/benchmark/internal/starter/external/ngtd/option_test.go
  • hack/benchmark/internal/starter/gateway/vald/vald_test.go
  • hack/license/gen/main_test.go
  • hack/swagger/main_test.go
  • hack/tools/config/agent/ngt/main_test.go
  • hack/tools/config/discoverer/k8s/main_test.go
  • hack/tools/config/gateway/vald/main_test.go
  • hack/tools/config/manager/backup/mysql/main_test.go
  • hack/tools/config/meta/redis/main_test.go
  • hack/tools/metrics/main_test.go
  • internal/cache/cache_test.go
  • internal/cache/cacher/cacher_test.go
  • internal/cache/gache/gache_test.go
  • internal/cache/gache/option_test.go
  • internal/cache/option_test.go
  • internal/client/agent/ngt/grpc/client_test.go
  • internal/client/agent/ngt/grpc/option_test.go
  • internal/client/agent/ngt/rest/client_test.go
  • internal/client/agent/ngt/rest/option_test.go
  • internal/client/compressor/client_test.go
  • internal/client/compressor/option.go
  • internal/client/compressor/option_test.go
  • internal/client/discoverer/discover_test.go
  • internal/client/discoverer/option_test.go
  • internal/client/gateway/vald/grpc/client_test.go
  • internal/client/gateway/vald/grpc/option_test.go
  • internal/client/gateway/vald/rest/client_test.go
  • internal/client/gateway/vald/rest/option_test.go
  • internal/config/backoff_test.go
  • internal/config/backup_test.go
  • internal/config/cassandra_test.go
  • internal/config/client_test.go
  • internal/config/compress.go
  • internal/config/compress_test.go
  • internal/config/config_test.go
  • internal/config/debug_test.go
  • internal/config/discoverer_test.go
  • internal/config/filter_test.go
  • internal/config/gateway_test.go
  • internal/config/grpc_test.go
  • internal/config/index_test.go
  • internal/config/log_test.go
  • internal/config/meta_test.go
  • internal/config/mysql_test.go
  • internal/config/ngt_test.go
  • internal/config/observability_test.go
  • internal/config/redis_test.go
  • internal/config/server_test.go
  • internal/config/tcp_test.go
  • internal/config/tls_test.go
  • internal/config/transport_test.go
  • internal/core/converter/tensorflow/option_test.go
  • internal/core/converter/tensorflow/tensorflow_test.go
  • internal/db/kvs/redis/option_test.go
  • internal/db/kvs/redis/redis_test.go
  • internal/db/nosql/cassandra/cassandra_test.go
  • internal/db/nosql/cassandra/conviction_test.go
  • internal/db/nosql/cassandra/option_test.go
  • internal/db/rdb/mysql/model_test.go
  • internal/db/rdb/mysql/mysql_test.go
  • internal/db/rdb/mysql/option_test.go
  • internal/errgroup/group_test.go
  • internal/errors/cassandra_test.go
  • internal/errors/compressor.go
  • internal/errors/mysql_test.go
  • internal/errors/redis_test.go
  • internal/info/info_test.go
  • internal/k8s/metrics/node/node_test.go
  • internal/k8s/metrics/node/option_test.go
  • internal/k8s/metrics/pod/option_test.go
  • internal/k8s/metrics/pod/pod_test.go
  • internal/k8s/node/node_test.go
  • internal/k8s/node/option_test.go
  • internal/k8s/option_test.go
  • internal/k8s/pod/option_test.go
  • internal/k8s/pod/pod_test.go
  • internal/k8s/reconciler_test.go
  • internal/log/mock/logger_test.go
  • internal/log/mock/retry_test.go
  • internal/net/grpc/metric/client_test.go
  • internal/net/grpc/metric/server_test.go
  • internal/net/grpc/proto/proto_test.go
  • internal/net/grpc/status/status_test.go
  • internal/net/net_test.go
  • internal/net/tcp/control_darwin_test.go
  • internal/net/tcp/control_other_test.go
  • internal/net/tcp/control_unix_test.go
  • internal/net/tcp/control_windows_test.go
  • internal/net/tcp/dialer_test.go
  • internal/net/tcp/option_dialer_test.go
  • internal/observability/collector/collector_option_test.go
  • internal/observability/collector/collector_test.go
  • internal/observability/exporter/jaeger/jaeger_option_test.go
  • internal/observability/exporter/jaeger/jaeger_test.go
  • internal/observability/exporter/prometheus/prometheus_option_test.go
  • internal/observability/exporter/prometheus/prometheus_test.go
  • internal/observability/metrics/agent/ngt/ngt_test.go
  • internal/observability/metrics/manager/compressor/compressor_test.go
  • internal/observability/metrics/mem/mem_test.go
  • internal/observability/metrics/metrics_test.go
  • internal/observability/metrics/runtime/cgo/cgo_test.go
  • internal/observability/metrics/runtime/goroutine/goroutine_test.go
  • internal/observability/metrics/version/version_test.go
  • internal/observability/observability_option_test.go
  • internal/observability/observability_test.go
  • internal/observability/trace/status_test.go
  • internal/observability/trace/trace_option_test.go
  • internal/observability/trace/trace_test.go
  • internal/params/option_test.go
  • internal/params/params_test.go
  • internal/runner/option_test.go
  • internal/runner/runner_test.go
  • internal/singleflight/singleflight_test.go
  • internal/tls/option_test.go
  • internal/tls/tls_test.go
  • internal/worker/queue_test.go
  • internal/worker/queue_option_test.go
  • internal/worker/worker_test.go
  • internal/worker/worker_option_test.go
  • pkg/agent/ngt/config/config_test.go
  • pkg/agent/ngt/handler/grpc/handler_test.go
  • pkg/agent/ngt/handler/grpc/option_test.go
  • pkg/agent/ngt/handler/rest/handler_test.go
  • pkg/agent/ngt/handler/rest/option_test.go
  • pkg/agent/ngt/router/option_test.go
  • pkg/agent/ngt/router/router_test.go
  • pkg/agent/ngt/service/kvs/kvs_test.go
  • pkg/agent/ngt/service/kvs/ou_test.go
  • pkg/agent/ngt/service/kvs/uo_test.go
  • pkg/agent/ngt/service/ngt_test.go
  • pkg/agent/ngt/service/vcaches_test.go
  • pkg/agent/ngt/usecase/agentd_test.go
  • pkg/discoverer/k8s/config/config_test.go
  • pkg/discoverer/k8s/handler/grpc/handler_test.go
  • pkg/discoverer/k8s/handler/grpc/option_test.go
  • pkg/discoverer/k8s/handler/rest/handler_test.go
  • pkg/discoverer/k8s/handler/rest/option_test.go
  • pkg/discoverer/k8s/router/option_test.go
  • pkg/discoverer/k8s/router/router_test.go
  • pkg/discoverer/k8s/service/discover_test.go
  • pkg/discoverer/k8s/service/nodemap_test.go
  • pkg/discoverer/k8s/service/nodemetricsmap_test.go
  • pkg/discoverer/k8s/service/option_test.go
  • pkg/discoverer/k8s/service/podmetricsmap_test.go
  • pkg/discoverer/k8s/service/podsmap_test.go
  • pkg/discoverer/k8s/usecase/discovered_test.go
  • pkg/gateway/vald/config/config_test.go
  • pkg/gateway/vald/handler/grpc/checklist_test.go
  • pkg/gateway/vald/handler/grpc/handler_test.go
  • pkg/gateway/vald/handler/grpc/option_test.go
  • pkg/gateway/vald/handler/rest/handler_test.go
  • pkg/gateway/vald/handler/rest/option_test.go
  • pkg/gateway/vald/router/option_test.go
  • pkg/gateway/vald/router/router_test.go
  • pkg/gateway/vald/service/backup_option_test.go
  • pkg/gateway/vald/service/backup_test.go
  • pkg/gateway/vald/service/filter_option_test.go
  • pkg/gateway/vald/service/filter_test.go
  • pkg/gateway/vald/service/gateway_option_test.go
  • pkg/gateway/vald/service/gateway_test.go
  • pkg/gateway/vald/service/meta_option_test.go
  • pkg/gateway/vald/service/meta_test.go
  • pkg/gateway/vald/usecase/vald_test.go
  • pkg/manager/backup/cassandra/config/config_test.go
  • pkg/manager/backup/cassandra/handler/grpc/handler_test.go
  • pkg/manager/backup/cassandra/handler/grpc/option_test.go
  • pkg/manager/backup/cassandra/handler/rest/handler_test.go
  • pkg/manager/backup/cassandra/handler/rest/option_test.go
  • pkg/manager/backup/cassandra/router/option_test.go
  • pkg/manager/backup/cassandra/router/router_test.go
  • pkg/manager/backup/cassandra/service/cassandra_test.go
  • pkg/manager/backup/cassandra/usecase/backupd_test.go
  • pkg/manager/backup/mysql/config/config_test.go
  • pkg/manager/backup/mysql/handler/grpc/handler_test.go
  • pkg/manager/backup/mysql/handler/grpc/option_test.go
  • pkg/manager/backup/mysql/handler/rest/handler_test.go
  • pkg/manager/backup/mysql/handler/rest/option_test.go
  • pkg/manager/backup/mysql/model/model_test.go
  • pkg/manager/backup/mysql/router/option_test.go
  • pkg/manager/backup/mysql/router/router_test.go
  • pkg/manager/backup/mysql/service/mysql_test.go
  • pkg/manager/backup/mysql/usecase/backupd_test.go
  • pkg/manager/compressor/config/config.go
  • pkg/manager/compressor/config/config_test.go
  • pkg/manager/compressor/handler/grpc/handler.go
  • pkg/manager/compressor/handler/grpc/handler_test.go
  • pkg/manager/compressor/handler/grpc/option.go
  • pkg/manager/compressor/handler/grpc/option_test.go
  • pkg/manager/compressor/handler/rest/handler_test.go
  • pkg/manager/compressor/handler/rest/option_test.go
  • pkg/manager/compressor/router/option_test.go
  • pkg/manager/compressor/router/router_test.go
  • pkg/manager/compressor/service/backup_option_test.go
  • pkg/manager/compressor/service/backup_test.go
  • pkg/manager/compressor/service/compress.go
  • pkg/manager/compressor/service/compress_option.go
  • pkg/manager/compressor/service/compress_option_test.go
  • pkg/manager/compressor/service/compress_test.go
  • pkg/manager/compressor/service/registerer.go
  • pkg/manager/compressor/service/registerer_option.go
  • pkg/manager/compressor/usecase/compressord.go
  • pkg/manager/compressor/usecase/compressord_test.go
  • pkg/manager/index/config/config_test.go
  • pkg/manager/index/handler/grpc/checklist_test.go
  • pkg/manager/index/handler/grpc/handler_test.go
  • pkg/manager/index/handler/grpc/option_test.go
  • pkg/manager/index/handler/rest/handler_test.go
  • pkg/manager/index/handler/rest/option_test.go
  • pkg/manager/index/router/option_test.go
  • pkg/manager/index/router/router_test.go
  • pkg/manager/index/service/indexer_test.go
  • pkg/manager/index/service/indexinfos_test.go
  • pkg/manager/index/service/option_test.go
  • pkg/manager/index/usecase/indexer_test.go
  • pkg/manager/replication/agent/config/config_test.go
  • pkg/manager/replication/agent/handler/grpc/handler_test.go
  • pkg/manager/replication/agent/handler/rest/handler_test.go
  • pkg/manager/replication/agent/handler/rest/option_test.go
  • pkg/manager/replication/agent/router/option_test.go
  • pkg/manager/replication/agent/router/router_test.go
  • pkg/manager/replication/agent/usecase/backupd_test.go
  • pkg/manager/replication/controller/config/config_test.go
  • pkg/manager/replication/controller/handler/grpc/handler_test.go
  • pkg/manager/replication/controller/handler/grpc/option_test.go
  • pkg/manager/replication/controller/handler/rest/handler_test.go
  • pkg/manager/replication/controller/handler/rest/option_test.go
  • pkg/manager/replication/controller/router/option_test.go
  • pkg/manager/replication/controller/router/router_test.go
  • pkg/manager/replication/controller/service/discover_test.go
  • pkg/manager/replication/controller/service/nodemap_test.go
  • pkg/manager/replication/controller/service/nodemetricsmap_test.go
  • pkg/manager/replication/controller/service/option_test.go
  • pkg/manager/replication/controller/service/podmetricsmap_test.go
  • pkg/manager/replication/controller/service/podsmap_test.go
  • pkg/manager/replication/controller/usecase/discovered_test.go
  • pkg/meta/cassandra/config/config_test.go
  • pkg/meta/cassandra/handler/grpc/handler_test.go
  • pkg/meta/cassandra/handler/grpc/option_test.go
  • pkg/meta/cassandra/handler/rest/handler_test.go
  • pkg/meta/cassandra/handler/rest/option_test.go
  • pkg/meta/cassandra/router/option_test.go
  • pkg/meta/cassandra/router/router_test.go
  • pkg/meta/cassandra/service/cassandra_test.go
  • pkg/meta/cassandra/usecase/meta_test.go
  • pkg/meta/redis/config/config_test.go
  • pkg/meta/redis/handler/grpc/handler_test.go
  • pkg/meta/redis/handler/grpc/option_test.go
  • pkg/meta/redis/handler/rest/handler_test.go
  • pkg/meta/redis/handler/rest/option_test.go
  • pkg/meta/redis/router/option_test.go
  • pkg/meta/redis/router/router_test.go/
  • pkg/meta/redis/service/redis_test.go
  • pkg/meta/redis/usecase/meta_test.go

Related Issue:

#325

How Has This Been Tested?:

Environment:

  • Golang Version: 1.14
  • Docker Version: 19.03.5
  • Kubernetes Version: 1.17.3
  • NGT Version: 1.9.1

Types of changes:

  • Bug fix [type/bug]
  • New feature [type/feature]
  • Add tests [type/test]
  • Security related changes [type/security]
  • Add documents [type/documentation]
  • Refactoring [type/refactoring]
  • Update dependencies [type/dependency]
  • Update benchmarks and performances [type/bench]
  • Update CI [type/ci]

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Checklist:

  • I have read the CONTRIBUTING document.
  • I have checked open Pull Requests for the similar feature or fixes?
  • I have added tests and benchmarks to cover my changes.
  • I have ensured all new and existing tests passed.
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly.

@pull-assistant
Copy link

pull-assistant bot commented Apr 10, 2020

Score: 1.00

Best reviewed: commit by commit


Optimal code review plan (4 warnings)

     ✅ generete missing test file

     ✅ generete missing test file

     ⏪ remove unnecessary test files

     ⏪ remove unnecessary test files

     ✅ added missing new test code

     ✅ added missing new test code

🔧 added make gentest for missing test code

Makefile.d/functions.mk 50% changes removed in draft gen-option-tes...

     🔥 removing files

     🔥 removing files

     feat: add template file

feat: add template file

...templates/common/function.tmpl 89% changes removed in refactor: adjust spa...

     refactor: adjust space

     refactor: adjust space

refactor: definition position

...templates/common/function.tmpl 50% changes removed in refactor: definition...

     refactor: definition position

     feat: function test case type

     draft gen-option-test

     refactor: benchmark script

     feat: add option

     fix: add fill type

     fix: add message

     fix: add message

fix: bug params name

...templates/common/function.tmpl 50% changes removed in fix: test template

     fix: bug of args parameter

     fix: commentout test case

     fix: test template

     🤖 Update license headers and formatting go codes

     Revert ":robot: Update license headers and formatting go codes"

     fix: exclude tempalte file

     fix: delete gotests package

     🤖 Update license headers and formatting go codes

Powered by Pull Assistant. Last update 24e4ec5 ... 14c9162. Read the comment docs.

@vdaas-ci
Copy link
Collaborator

[WARNING] Changes in interal/config may require you to change Helm charts. Please check.

@vankichi
Copy link
Contributor Author

/rebase

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by vankichi for branch: test/cmd-hack-internal-pkg/gen-missing-test-by-template-using-gotests

@vdaas-ci
Copy link
Collaborator

[REBASE] Failed to rebase.

@vankichi vankichi force-pushed the test/cmd-hack-internal-pkg/gen-missing-test-by-template-using-gotests branch from cf63529 to b12abfa Compare April 13, 2020 09:36
@vdaas-ci
Copy link
Collaborator

[WARNING] Changes in interal/config may require you to change Helm charts. Please check.

1 similar comment
@vdaas-ci
Copy link
Collaborator

[WARNING] Changes in interal/config may require you to change Helm charts. Please check.

@vdaas-ci
Copy link
Collaborator

[WARNING] Changes in interal/config may require you to change Helm charts. Please check.

1 similar comment
@vdaas-ci
Copy link
Collaborator

[WARNING] Changes in interal/config may require you to change Helm charts. Please check.

@vankichi
Copy link
Contributor Author

/rebase

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by vankichi for branch: test/cmd-hack-internal-pkg/gen-missing-test-by-template-using-gotests

@vdaas-ci vdaas-ci force-pushed the test/cmd-hack-internal-pkg/gen-missing-test-by-template-using-gotests branch from 48b9fda to cc27f84 Compare April 14, 2020 07:17
@vdaas-ci
Copy link
Collaborator

[WARNING] Changes in interal/config may require you to change Helm charts. Please check.

@vankichi
Copy link
Contributor Author

/rebase

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by vankichi for branch: test/cmd-hack-internal-pkg/gen-missing-test-by-template-using-gotests

@vankichi
Copy link
Contributor Author

@kpango
you can see generated test here

@vankichi
Copy link
Contributor Author

here are the examples:

pkg/manager/replication/controller/handler/rest/handler_test.go
//
// Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt )
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Package rest provides rest api logic
package rest

import (
	"net/http"
	"reflect"
	"testing"

	"github.com/cockroachdb/errors"
	"github.com/vdaas/vald/apis/grpc/manager/replication/controller"
)

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

		// TODO test cases
		/*
		   func() test {
		       return test {
		           name: "test_case_2",
		           args: args {
		           opts: nil,
		           },
		           want: want{},
		           checkFunc: defaultCheckFunc,
		       }
		   }(),
		*/
	}

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

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

		})
	}
}

func Test_handler_Index(t *testing.T) {
	type args struct {
		w http.ResponseWriter
		r *http.Request
	}
	type fields struct {
		rpl controller.ReplicationServer
	}
	type want struct {
		want int
		err  error
	}
	type test struct {
		name       string
		args       args
		fields     fields
		want       want
		checkFunc  func(want, int, error) error
		beforeFunc func(args)
		afterFunc  func(args)
	}
	defaultCheckFunc := func(w want, got int, err error) error {
		if !errors.Is(err, w.err) {
			return errors.Errorf("got error = %v, want %v", err, w.err)
		}
		if !reflect.DeepEqual(got, w.want) {
			return errors.Errorf("got = %v, want %v", got, w.want)
		}
		return nil
	}
	tests := []test{
		// TODO test cases
		/*
		   {
		       name: "test_case_1",
		       args: args {
		           w: nil,
		           r: nil,
		       },
		       fields: fields {
		           rpl: nil,
		       },
		       want: want{},
		       checkFunc: defaultCheckFunc,
		   },
		*/

		// TODO test cases
		/*
		   func() test {
		       return test {
		           name: "test_case_2",
		           args: args {
		           w: nil,
		           r: nil,
		           },
		           fields: fields {
		           rpl: nil,
		           },
		           want: want{},
		           checkFunc: defaultCheckFunc,
		       }
		   }(),
		*/
	}

	for _, test := range tests {
		t.Run(test.name, func(tt *testing.T) {
			if test.beforeFunc != nil {
				test.beforeFunc(test.args)
			}
			if test.afterFunc != nil {
				defer test.afterFunc(test.args)
			}
			if test.checkFunc == nil {
				test.checkFunc = defaultCheckFunc
			}
			h := &handler{
				rpl: test.fields.rpl,
			}

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

		})
	}
}
pkg/manager/replication/controller/handler/rest/option_test.go
//
// Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt )
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Package rest provides rest api logic
package rest

import (
	"testing"

	"github.com/vdaas/vald/apis/grpc/manager/replication/controller"
)

func TestWithReplicator(t *testing.T) {
	type T = interface{}
	type args struct {
		rpl controller.ReplicationServer
	}
	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 fmt.Errorf("got = %v, want %v", obj, w.c)
	       }
	       return nil
	   }
	*/

	tests := []test{
		// TODO test cases
		/*
		   {
		       name: "test_case_1",
		       args: args {
		           rpl: nil,
		       },
		       want: want {
		           obj: new(T),
		       },
		   },
		*/

		// TODO test cases
		/*
		   func() test {
		       return test {
		           name: "test_case_2",
		           args: args {
		           rpl: nil,
		           },
		           want: want {
		               obj: new(T),
		           },
		       }
		   }(),
		*/
	}

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

			// Uncomment this block if the option returns an error, otherwise delete it
			/*
			   if test.checkFunc == nil {
			       test.checkFunc = defaultCheckFunc
			   }
			   got := WithReplicator(test.args.rpl)
			   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
			/*
			   if test.checkFunc == nil {
			       test.checkFunc = defaultCheckFunc
			   }
			   got := WithReplicator(test.args.rpl)
			   obj := new(T)
			   got(obj)
			   if err := test.checkFunc(tt.want, obj); err != nil {
			       tt.Errorf("error = %v", err)
			   }
			*/
		})
	}
}

@kpango
Copy link
Collaborator

kpango commented Apr 24, 2020

@vdaas/set LGTM you guys did a great job!

@kpango
Copy link
Collaborator

kpango commented Apr 24, 2020

/rebase
/format
/approve

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by kpango for branch: test/cmd-hack-internal-pkg/gen-missing-test-by-template-using-gotests

@vdaas-ci
Copy link
Collaborator

[FORMAT] Updating license headers and formatting go codes triggered by kpango.

Signed-off-by: vdaas-ci <ci@vdaas.org>
@vdaas-ci vdaas-ci dismissed stale reviews from kevindiu and hlts2 via d95f55e April 24, 2020 05:11
vdaas-ci
vdaas-ci previously approved these changes Apr 24, 2020
Copy link
Collaborator

@vdaas-ci vdaas-ci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[APPROVED] This PR is approved by kpango.

@github-actions github-actions bot added size/XL and removed size/XL labels Apr 24, 2020
Signed-off-by: hlts2 <hiroto.funakoshi.hiroto@gmail.com>
@github-actions github-actions bot added size/L and removed size/L labels Apr 24, 2020
Signed-off-by: hlts2 <hiroto.funakoshi.hiroto@gmail.com>
@github-actions github-actions bot added size/L and removed size/L labels Apr 24, 2020
@kpango
Copy link
Collaborator

kpango commented Apr 24, 2020

/format
/approve

@vdaas-ci
Copy link
Collaborator

[FORMAT] Updating license headers and formatting go codes triggered by kpango.

Signed-off-by: vdaas-ci <ci@vdaas.org>
Copy link
Collaborator

@vdaas-ci vdaas-ci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[APPROVED] This PR is approved by kpango.

@github-actions github-actions bot added size/L and removed size/L labels Apr 24, 2020
@kpango kpango merged commit 80c8a24 into master Apr 24, 2020
@kpango kpango deleted the test/cmd-hack-internal-pkg/gen-missing-test-by-template-using-gotests branch April 24, 2020 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants