Skip to content

Commit

Permalink
fix: to match the test template
Browse files Browse the repository at this point in the history
Signed-off-by: hlts2 <[email protected]>
  • Loading branch information
hlts2 authored and actions-user committed May 13, 2020
1 parent 78486eb commit 36e587d
Showing 1 changed file with 98 additions and 93 deletions.
191 changes: 98 additions & 93 deletions internal/log/format/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,153 +23,160 @@ import (
"go.uber.org/goleak"
)

func TestString(t *testing.T) {
func TestFormat_String(t *testing.T) {
type want struct {
want string
}
type test struct {
name string
format Format
want string
name string
f Format
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 raw",
format: RAW,
want: "raw",
name: "returns raw when f is RAW",
f: RAW,
want: want{
want: "raw",
},
},

{
name: "returns json",
format: JSON,
want: "json",
name: "returns json when f is JSON",
f: JSON,
want: want{
want: "json",
},
},

{
name: "returns ltsv",
format: LTSV,
want: "ltsv",
name: "returns ltsv when f is LTSV",
f: LTSV,
want: want{
want: "ltsv",
},
},

{
name: "returns unknown",
format: Format(100),
want: "unknown",
name: "returns unknown when f is 100",
f: Format(100),
want: want{
want: "unknown",
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.format.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.f.String()
if err := test.checkFunc(test.want, got); err != nil {
tt.Errorf("error = %v", err)
}

})
}
}

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

tests := []test{
{
name: "returns RAW when str is raw",
name: "returns RAW when str is `raw`",
str: "raw",
want: RAW,
want: want{
want: RAW,
},
},

{
name: "returns RAW when str is RAw",
name: "returns RAW when str is `RAw`",
str: "RAw",
want: RAW,
want: want{
want: RAW,
},
},

{
name: "returns JSON when str is json",
name: "returns JSON when str is `json`",
str: "json",
want: JSON,
want: want{
want: JSON,
},
},

{
name: "returns JSON when str is JSOn",
name: "returns JSON when str is `JSOn`",
str: "JSOn",
want: JSON,
want: want{
want: JSON,
},
},

{
name: "returns LTSV when str is ltsv",
name: "returns LTSV when str is `ltsv`",
str: "ltsv",
want: LTSV,
want: want{
want: LTSV,
},
},

{
name: "returns LTSV when str is LTSv",
name: "returns LTSV when str is `LTSv`",
str: "LTSv",
want: LTSV,
want: want{
LTSV,
},
},

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

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

func TestFormat_String(t *testing.T) {
type want struct {
want string
}
type test struct {
name string
f Format
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()
}
Expand All @@ -179,12 +186,10 @@ func TestFormat_String(t *testing.T) {
if test.checkFunc == nil {
test.checkFunc = defaultCheckFunc
}

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

})
}
}

0 comments on commit 36e587d

Please sign in to comment.