123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- package dao
- import (
- "reflect"
- "testing"
- "go-common/app/admin/main/apm/model/need"
- "github.com/bouk/monkey"
- "github.com/jinzhu/gorm"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDaoNeedInfoAdd(t *testing.T) {
- convey.Convey("NeedInfoAdd", t, func() {
- arg := &need.NAddReq{
- Title: "wwe",
- Content: "sds",
- }
- err := d.NeedInfoAdd(arg, "fengshanshan")
- convey.So(err, convey.ShouldBeNil)
- })
- }
- func TestDaoNeedInfoList(t *testing.T) {
- convey.Convey("NeedInfoList", t, func() {
- arg := &need.NListReq{
- Status: 1,
- Ps: 10,
- Pn: 1,
- }
- res, err := d.NeedInfoList(arg)
- t.Logf("res:%+v", res)
- convey.So(err, convey.ShouldBeNil)
- convey.So(res, convey.ShouldNotBeNil)
- })
- }
- func TestDaoNeedInfoCount(t *testing.T) {
- convey.Convey("NeedInfoCount", t, func() {
- arg := &need.NListReq{
- Status: 1,
- }
- count, err := d.NeedInfoCount(arg)
- t.Logf("count:%+v", count)
- convey.So(err, convey.ShouldBeNil)
- convey.So(count, convey.ShouldNotBeNil)
- })
- }
- func TestDaoneedInfoCondition(t *testing.T) {
- convey.Convey("needInfoCondition", t, func() {
- arg := &need.NListReq{}
- p1 := d.needInfoCondition(arg)
- t.Logf("condition:%+v", p1)
- convey.So(p1, convey.ShouldNotBeNil)
- })
- }
- func TestDaoGetNeedInfo(t *testing.T) {
- convey.Convey("GetNeedInfo", t, func() {
- r, err := d.GetNeedInfo(97)
- t.Logf("GetNeedInfo:%+v", r)
- convey.So(err, convey.ShouldBeNil)
- convey.So(r, convey.ShouldNotBeNil)
- })
- }
- func TestDaoNeedInfoEdit(t *testing.T) {
- convey.Convey("NeedInfoEdit", t, func() {
- arg := &need.NEditReq{
- Content: "dsada",
- Title: "fsd",
- ID: 28,
- }
- err := d.NeedInfoEdit(arg)
- convey.So(err, convey.ShouldBeNil)
- })
- }
- func TestDaoNeedVerify(t *testing.T) {
- convey.Convey("NeedVerify", t, func() {
- v := &need.NVerifyReq{
- ID: 28,
- Status: 2,
- }
- err := d.NeedVerify(v)
- convey.So(err, convey.ShouldBeNil)
- })
- }
- func TestDaoLikeCountsAdd(t *testing.T) {
- convey.Convey("LikeCountsAdd", t, func() {
- v := &need.Likereq{
- ReqID: 148,
- LikeType: 1,
- }
- err := d.LikeCountsStats(v, 1, 0)
- convey.So(err, convey.ShouldBeNil)
- })
- }
- func TestDaoGetVoteInfo(t *testing.T) {
- convey.Convey("GetVoteInfo", t, func() {
- var (
- db = &gorm.DB{
- Error: nil,
- }
- v = &need.Likereq{
- ReqID: 148,
- LikeType: 1,
- }
- )
- guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.DB), "Find", func(_ *gorm.DB, _ interface{}, _ ...interface{}) *gorm.DB {
- return db
- })
- defer guard.Unpatch()
- res, err := d.GetVoteInfo(v, "fengshanshan")
- t.Logf("res:%+v", res)
- convey.So(err, convey.ShouldBeNil)
- convey.So(res, convey.ShouldNotBeNil)
- })
- }
- func TestDaoUpdateVoteInfo(t *testing.T) {
- convey.Convey("UpdateVoteInfo", t, func() {
- v := &need.Likereq{
- ReqID: 30,
- LikeType: 2,
- }
- err := d.UpdateVoteInfo(v, "fengshanshan")
- convey.So(err, convey.ShouldBeNil)
- })
- }
- func TestDaoVoteInfoList(t *testing.T) {
- convey.Convey("VoteInfoList", t, func() {
- arg := &need.Likereq{
- ReqID: 11,
- LikeType: 2,
- }
- res, err := d.VoteInfoList(arg)
- t.Logf("res:%+v", res)
- convey.So(err, convey.ShouldBeNil)
- convey.So(res, convey.ShouldNotBeNil)
- })
- }
- func TestDaoVoteInfoCounts(t *testing.T) {
- convey.Convey("VoteInfoCounts", t, func() {
- arg := &need.Likereq{
- ReqID: 11,
- LikeType: 1,
- }
- count, err := d.VoteInfoCounts(arg)
- t.Logf("count:%+v", count)
- convey.So(err, convey.ShouldBeNil)
- convey.So(count, convey.ShouldNotBeNil)
- })
- }
|