Skip to content

Commit

Permalink
Added test cases for debug.List method
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsalsaleem committed Nov 13, 2021
1 parent 8df11bd commit 51b6233
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tpl/debug/debug_test.go
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")
})

}

0 comments on commit 51b6233

Please sign in to comment.