Skip to content

Commit

Permalink
Fix internal/log/logger to match the test template (#371)
Browse files Browse the repository at this point in the history
* fix: to match the test template

Signed-off-by: hlts2 <hiroto.funakoshi.hiroto@gmail.com>

* fix: goleak bug. t -> tt

Signed-off-by: hlts2 <hiroto.funakoshi.hiroto@gmail.com>

* 🤖 Update license headers and formatting go codes

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

Co-authored-by: vdaas-ci <ci@vdaas.org>
  • Loading branch information
hlts2 and vdaas-ci authored May 13, 2020
1 parent fcabeaa commit 78486eb
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 120 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ require (
go.uber.org/automaxprocs v1.3.0
go.uber.org/goleak v1.0.0
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9
golang.org/x/tools v0.0.0-20200512001501-aaeff5de670a // indirect
golang.org/x/tools v0.0.0-20200513022744-65e69ff2d148 // indirect
gonum.org/v1/hdf5 v0.0.0-20200504100616-496fefe91614
gonum.org/v1/netlib v0.0.0-20200317120129-c5a04cffd98a // indirect
gonum.org/v1/plot v0.7.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,8 @@ golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5 h1:MeC2gMlMdkd67dn17MEby3r
golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200512001501-aaeff5de670a h1:vAa2fXRLbiVN3N/xCnodIT36K4QKZQNyQFq3hQJfQ1U=
golang.org/x/tools v0.0.0-20200512001501-aaeff5de670a/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200513022744-65e69ff2d148 h1:X3wiF+nWEwv11fBoJVQN0dSMu7rlvPkRKYAHuuJoyvc=
golang.org/x/tools v0.0.0-20200513022744-65e69ff2d148/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
Expand Down
282 changes: 163 additions & 119 deletions internal/log/logger/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//

package logger

import (
Expand All @@ -23,200 +24,243 @@ import (
"go.uber.org/goleak"
)

func TestString(t *testing.T) {
func TestType_String(t *testing.T) {
type want struct {
want string
}
type test struct {
name string
logType Type
want string
name string
m Type
want want
checkFunc func(want, string) error
beforeFunc func()
afterFunc func()
}
defaultCheckFunc := func(w want, got string) error {
if !reflect.DeepEqual(got, w.want) {
return errors.Errorf("got = %v, want %v", got, w.want)
}
return nil
}

tests := []test{
{
name: "returns glg",
logType: GLG,
want: "glg",
name: "returns glg when m is GLG",
m: GLG,
want: want{
want: "glg",
},
},

{
name: "returns zap",
logType: ZAP,
want: "zap",
name: "returns zap when m is ZAP",
m: ZAP,
want: want{
want: "zap",
},
},

{
name: "returns zerolog",
logType: ZEROLOG,
want: "zerolog",
name: "returns zerolog when m is ZEROLOG",
m: ZEROLOG,
want: want{
want: "zerolog",
},
},

{
name: "returns logrus",
logType: LOGRUS,
want: "logrus",
name: "returns logrus when m is LOGRUS",
m: LOGRUS,
want: want{
want: "logrus",
},
},

{
name: "returns klog",
logType: KLOG,
want: "klog",
name: "returns klog when m is KLOG",
m: KLOG,
want: want{
want: "klog",
},
},

{
name: "returns unknown",
logType: Type(100),
want: "unknown",
name: "returns unknown when m is unknown",
m: Type(100),
want: want{
want: "unknown",
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.logType.String()
if got != tt.want {
t.Errorf("not equals. want: %v, but got: %v", tt.want, got)
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
}

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

})
}
}

func TestAtot(t *testing.T) {
type test struct {
name string
str string
type args struct {
str string
}
type want struct {
want Type
}

type test struct {
name string
args args
want want
checkFunc func(want, Type) error
beforeFunc func(args)
afterFunc func(args)
}
defaultCheckFunc := func(w want, got Type) error {
if !reflect.DeepEqual(got, w.want) {
return errors.Errorf("got = %v, want %v", got, w.want)
}
return nil
}
tests := []test{
{
name: "returns GLG when str is glg",
str: "glg",
want: GLG,
name: "returns GLG when str is `glg`",
args: args{
str: "glg",
},
want: want{
want: GLG,
},
},

{
name: "returns GLG when str is GLg",
str: "GLg",
want: GLG,
name: "returns GLG when str is `GLg`",
args: args{
str: "GLg",
},
want: want{
want: GLG,
},
},

{
name: "returns ZAP when str is zap",
str: "zap",
want: ZAP,
name: "returns ZAP when str is `zap`",
args: args{
str: "zap",
},
want: want{
want: ZAP,
},
},

{
name: "returns ZAP when str is ZAp",
str: "ZAp",
want: ZAP,
name: "returns ZAP when str is `ZAp`",
args: args{
str: "ZAp",
},
want: want{
want: ZAP,
},
},

{
name: "returns ZEROLOG when str is zerolog",
str: "zerolog",
want: ZEROLOG,
name: "returns ZEROLOG when str is `zerolog`",
args: args{
str: "zerolog",
},
want: want{
want: ZEROLOG,
},
},

{
name: "returns ZEROLOG when str is ZEROLOg",
str: "ZEROLOg",
want: ZEROLOG,
name: "returns ZEROLOG when str is `ZEROLOg`",
args: args{
str: "ZEROLOg",
},
want: want{
want: ZEROLOG,
},
},

{
name: "returns LOGRUS when str is logrus",
str: "logrus",
want: LOGRUS,
name: "returns LOGRUS when str is `logrus`",
args: args{
str: "logrus",
},
want: want{
want: LOGRUS,
},
},

{
name: "returns LOGRUS when str is LOGRUs",
str: "LOGRUs",
want: LOGRUS,
name: "returns LOGRUS when str is `LOGRUs`",
args: args{
str: "LOGRUs",
},
want: want{
want: LOGRUS,
},
},

{
name: "returns KLOG when str is klog",
str: "klog",
want: KLOG,
name: "returns KLOG when str is `klog`",
args: args{
str: "klog",
},
want: want{
want: KLOG,
},
},

{
name: "returns KLOG when str is KLOg",
str: "KLog",
want: KLOG,
name: "returns KLOG when str is `KLOg`",
args: args{
str: "KLog",
},
want: want{
want: KLOG,
},
},

{
name: "returns unknown when str is Vald",
str: "Vald",
want: Unknown,
name: "returns unknown when str is `Vald`",
args: args{
str: "Vald",
},
want: want{
want: Unknown,
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := Atot(tt.str)
if got != tt.want {
t.Errorf("not equals. want: %v, but got: %v", tt.want, got)
}
})
}
}

func TestType_String(t *testing.T) {
type want struct {
want string
}
type test struct {
name string
m Type
want want
checkFunc func(want, string) error
beforeFunc func()
afterFunc func()
}
defaultCheckFunc := func(w want, got string) 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",
want: want{},
checkFunc: defaultCheckFunc,
},
*/

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

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 := test.m.String()
got := Atot(test.args.str)
if err := test.checkFunc(test.want, got); err != nil {
tt.Errorf("error = %v", err)
}
Expand Down

0 comments on commit 78486eb

Please sign in to comment.