From 51b623304b4035b0ab1cbc643a640681caac8207 Mon Sep 17 00:00:00 2001 From: Mohamed Saleem Date: Sat, 13 Nov 2021 20:58:51 +0530 Subject: [PATCH] Added test cases for debug.List method --- tpl/debug/debug_test.go | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tpl/debug/debug_test.go diff --git a/tpl/debug/debug_test.go b/tpl/debug/debug_test.go new file mode 100644 index 00000000000..33bd9c482e4 --- /dev/null +++ b/tpl/debug/debug_test.go @@ -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") + }) + +}