-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test cases for debug.List method
- Loading branch information
1 parent
8df11bd
commit 51b6233
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package debug | ||
|
||
import ( | ||
"testing" | ||
|
||
qt "github.com/frankban/quicktest" | ||
) | ||
|
||
type User struct { | ||
Name string | ||
Phone string | ||
city string | ||
} | ||
|
||
func (u User) GetName() string { | ||
return u.Name | ||
} | ||
|
||
func (u User) GetPhone() string { | ||
return u.Phone | ||
} | ||
|
||
func (u *User) getCity() string { | ||
return u.city | ||
} | ||
|
||
func (u *User) GetPhoneAndCity() string { | ||
return u.Phone + u.city | ||
} | ||
|
||
func TestList(t *testing.T) { | ||
user := User{"a name", "9876543210", "SF"} | ||
ns := Namespace{} | ||
|
||
t.Run("struct", func(t *testing.T) { | ||
c := qt.New(t) | ||
result := ns.List(user) | ||
c.Assert(result[0], qt.Equals, "GetName") | ||
c.Assert(result[1], qt.Equals, "GetPhone") | ||
c.Assert(result[2], qt.Equals, "Name") | ||
c.Assert(result[3], qt.Equals, "Phone") | ||
c.Assert(result[4], qt.Equals, "city") | ||
}) | ||
|
||
t.Run("pointer", func(t *testing.T) { | ||
c := qt.New(t) | ||
result := ns.List(&user) | ||
c.Assert(result[0], qt.Equals, "GetName") | ||
c.Assert(result[1], qt.Equals, "GetPhone") | ||
c.Assert(result[2], qt.Equals, "GetPhoneAndCity") | ||
c.Assert(result[3], qt.Equals, "Name") | ||
c.Assert(result[4], qt.Equals, "Phone") | ||
c.Assert(result[5], qt.Equals, "city") | ||
}) | ||
|
||
t.Run("map", func(t *testing.T) { | ||
c := qt.New(t) | ||
mapTestCase := map[string]string{ | ||
"name": "a name", | ||
"phone": "a phone", | ||
} | ||
result := ns.List(mapTestCase) | ||
c.Assert(result[0], qt.Equals, "name") | ||
c.Assert(result[1], qt.Equals, "phone") | ||
}) | ||
|
||
} |