-
Notifications
You must be signed in to change notification settings - Fork 78
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
create test template for using gotests #327
Conversation
Best reviewed: commit by commit
Optimal code review plan (4 warnings)
|
[WARNING] Changes in |
/rebase |
[REBASE] Rebase triggered by vankichi for branch: test/cmd-hack-internal-pkg/gen-missing-test-by-template-using-gotests |
[REBASE] Failed to rebase. |
cf63529
to
b12abfa
Compare
[WARNING] Changes in |
1 similar comment
[WARNING] Changes in |
[WARNING] Changes in |
1 similar comment
[WARNING] Changes in |
/rebase |
[REBASE] Rebase triggered by vankichi for branch: test/cmd-hack-internal-pkg/gen-missing-test-by-template-using-gotests |
48b9fda
to
cc27f84
Compare
[WARNING] Changes in |
/rebase |
[REBASE] Rebase triggered by vankichi for branch: test/cmd-hack-internal-pkg/gen-missing-test-by-template-using-gotests |
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)
}
*/
})
}
} |
@vdaas/set LGTM you guys did a great job! |
/rebase |
[REBASE] Rebase triggered by kpango for branch: test/cmd-hack-internal-pkg/gen-missing-test-by-template-using-gotests |
[FORMAT] Updating license headers and formatting go codes triggered by kpango. |
Signed-off-by: vdaas-ci <ci@vdaas.org>
There was a problem hiding this 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.
This reverts commit d95f55e.
Signed-off-by: hlts2 <hiroto.funakoshi.hiroto@gmail.com>
Signed-off-by: hlts2 <hiroto.funakoshi.hiroto@gmail.com>
/format |
[FORMAT] Updating license headers and formatting go codes triggered by kpango. |
Signed-off-by: vdaas-ci <ci@vdaas.org>
There was a problem hiding this 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.
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
Related Issue:
#325
How Has This Been Tested?:
Environment:
Types of changes:
Changes to Core Features:
Checklist: