123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563 |
- package grpc
- import (
- "context"
- "flag"
- "fmt"
- "github.com/smartystreets/goconvey/convey"
- "go-common/app/service/main/relation/model"
- "os"
- "testing"
- "time"
- "go-common/app/service/main/relation/api"
- pb "go-common/app/service/main/relation/api"
- "go-common/app/service/main/relation/conf"
- "go-common/app/service/main/relation/service"
- "go-common/library/net/rpc/warden"
- xtime "go-common/library/time"
- )
- var (
- cli api.RelationClient
- svr *service.Service
- )
- func TestMain(m *testing.M) {
- if os.Getenv("DEPLOY_ENV") != "" {
- flag.Set("app_id", "main.account.relation-service")
- flag.Set("conf_token", "8hm3I5rWzuhChxrBI6VTqmCs7TpJwFhO")
- flag.Set("tree_id", "2139")
- flag.Set("conf_version", "docker-1")
- flag.Set("deploy_env", "uat")
- flag.Set("conf_host", "config.bilibili.co")
- flag.Set("conf_path", "/tmp")
- flag.Set("region", "sh")
- flag.Set("zone", "sh001")
- }
- flag.Parse()
- if err := conf.Init(); err != nil {
- panic(err)
- }
- svr = service.New(conf.Conf)
- cfg := &warden.ClientConfig{
- Dial: xtime.Duration(time.Second * 3),
- Timeout: xtime.Duration(time.Second * 3),
- }
- var err error
- cli, err = api.NewClient(cfg)
- if err != nil {
- panic(err)
- }
- m.Run()
- os.Exit(0)
- }
- func TestServerRelation(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("Relation", t, func(cv convey.C) {
- rr := pb.RelationReq{Mid: 1, Fid: 2, RealIp: "127.0.0.1"}
- fr, err := cli.Relation(c, &rr)
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(fr, convey.ShouldNotBeNil)
- })
- fmt.Println(fr)
- f, err2 := svr.Relation(c, 1, 2)
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(f, convey.ShouldNotBeNil)
- })
- fmt.Println(f)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- cv.So(f.Mid, convey.ShouldEqual, fr.Mid)
- cv.So(f.Attribute, convey.ShouldEqual, fr.Attribute)
- cv.So(f.CTime, convey.ShouldEqual, fr.CTime)
- })
- })
- }
- func TestServerRelations(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("Relations", t, func(cv convey.C) {
- rr := pb.RelationsReq{Mid: 1, Fid: []int64{2, 3}, RealIp: "127.0.0.1"}
- fr, err := cli.Relations(c, &rr)
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(fr, convey.ShouldNotBeNil)
- })
- fmt.Println(fr)
- f, err2 := svr.Relations(c, 1, []int64{2, 3})
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(f, convey.ShouldNotBeNil)
- })
- fmt.Println(f)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- f1 := fr.FollowingMap[2]
- cv.So(f[2].Attribute, convey.ShouldEqual, f1.Attribute)
- cv.So(f[2].CTime, convey.ShouldEqual, f1.CTime)
- })
- })
- }
- func TestServerStat(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("Stat", t, func(cv convey.C) {
- st, err := cli.Stat(c, &pb.MidReq{Mid: 2})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(st, convey.ShouldNotBeNil)
- })
- fmt.Println(st)
- s, err2 := svr.Stat(c, 2)
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(s, convey.ShouldNotBeNil)
- })
- fmt.Println(s)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- cv.So(st.CTime, convey.ShouldEqual, s.CTime)
- cv.So(st.Mid, convey.ShouldEqual, s.Mid)
- cv.So(st.Black, convey.ShouldEqual, s.Black)
- cv.So(st.Follower, convey.ShouldEqual, s.Follower)
- cv.So(st.Following, convey.ShouldEqual, s.Following)
- cv.So(st.MTime, convey.ShouldEqual, s.MTime)
- cv.So(st.Whisper, convey.ShouldEqual, s.Whisper)
- })
- })
- }
- func TestServerStats(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("Stats", t, func(cv convey.C) {
- st, err := cli.Stats(c, &pb.MidsReq{Mids: []int64{2, 3}, RealIp: "127.0.0.1"})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(st, convey.ShouldNotBeNil)
- })
- fmt.Println(st)
- s, err2 := svr.Stats(c, []int64{2, 3})
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(s, convey.ShouldNotBeNil)
- })
- fmt.Println(s)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- st2 := st.StatReplyMap[2]
- s2 := s[2]
- cv.So(s2.CTime, convey.ShouldEqual, st2.CTime)
- cv.So(s2.Mid, convey.ShouldEqual, st2.Mid)
- cv.So(s2.Black, convey.ShouldEqual, st2.Black)
- cv.So(s2.Follower, convey.ShouldEqual, st2.Follower)
- cv.So(s2.Following, convey.ShouldEqual, st2.Following)
- cv.So(s2.MTime, convey.ShouldEqual, st2.MTime)
- cv.So(s2.Whisper, convey.ShouldEqual, st2.Whisper)
- })
- })
- }
- func TestServerAttentions(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("Attentions", t, func(cv convey.C) {
- at, err := cli.Attentions(c, &pb.MidReq{Mid: 2})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(at, convey.ShouldNotBeNil)
- })
- fmt.Println(at)
- a, err2 := svr.Attentions(c, 2)
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(a, convey.ShouldNotBeNil)
- })
- fmt.Println(a)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- f1 := at.FollowingList[0]
- f2 := a[0]
- cv.So(f1.Mid, convey.ShouldEqual, f2.Mid)
- cv.So(f1.Attribute, convey.ShouldEqual, f2.Attribute)
- cv.So(f1.CTime, convey.ShouldEqual, f2.CTime)
- })
- })
- }
- func TestServerFollowings(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("Followings", t, func(cv convey.C) {
- at, err := cli.Followings(c, &pb.MidReq{Mid: 2})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(at, convey.ShouldNotBeNil)
- })
- fmt.Println(at)
- a, err2 := svr.Followings(c, 2)
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(a, convey.ShouldNotBeNil)
- })
- fmt.Println(a)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- f1 := at.FollowingList[0]
- f2 := a[0]
- cv.So(f1.Mid, convey.ShouldEqual, f2.Mid)
- cv.So(f1.Attribute, convey.ShouldEqual, f2.Attribute)
- cv.So(f1.CTime, convey.ShouldEqual, f2.CTime)
- })
- })
- }
- func TestServerWhispers(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("Whispers", t, func(cv convey.C) {
- at, err := cli.Whispers(c, &pb.MidReq{Mid: 2231365})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(at, convey.ShouldNotBeNil)
- })
- fmt.Println(at)
- a, err2 := svr.Whispers(c, 2231365)
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(a, convey.ShouldNotBeNil)
- })
- fmt.Println(a)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- f1 := at.FollowingList[0]
- f2 := a[0]
- cv.So(f1.Mid, convey.ShouldEqual, f2.Mid)
- cv.So(f1.Attribute, convey.ShouldEqual, f2.Attribute)
- cv.So(f1.CTime, convey.ShouldEqual, f2.CTime)
- })
- })
- }
- func TestServerFollowers(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("Followers", t, func(cv convey.C) {
- at, err := cli.Followers(c, &pb.MidReq{Mid: 2})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(at, convey.ShouldNotBeNil)
- })
- fmt.Println(at)
- a, err2 := svr.Followers(c, 2)
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(a, convey.ShouldNotBeNil)
- })
- fmt.Println(a)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- f1 := at.FollowingList[0]
- f2 := a[0]
- cv.So(f1.Mid, convey.ShouldEqual, f2.Mid)
- cv.So(f1.Attribute, convey.ShouldEqual, f2.Attribute)
- cv.So(f1.CTime, convey.ShouldEqual, f2.CTime)
- })
- })
- }
- func TestServerTag(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("Tag", t, func(cv convey.C) {
- t, err := cli.Tag(c, &pb.TagIdReq{Mid: 1, TagId: -10, RealIp: "127.0.0.1"})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(t, convey.ShouldNotBeNil)
- })
- fmt.Println(t)
- tg, err2 := svr.Tag(c, 1, -10, "127.0.0.1")
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(tg, convey.ShouldNotBeNil)
- })
- fmt.Println(tg)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- cv.So(len(t.Mids), convey.ShouldEqual, len(tg))
- cv.So(t.Mids[0], convey.ShouldEqual, tg[0])
- })
- })
- }
- func TestServerTags(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("Tags", t, func(cv convey.C) {
- t, err := cli.Tags(c, &pb.MidReq{Mid: 1})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(t, convey.ShouldNotBeNil)
- })
- fmt.Println(t)
- tg, err2 := svr.Tags(c, 1, "127.0.0.1")
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(tg, convey.ShouldNotBeNil)
- })
- fmt.Println(tg)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- cv.So(t.TagCountList[0].Tagid, convey.ShouldEqual, tg[0].Tagid)
- cv.So(t.TagCountList[0].Count, convey.ShouldEqual, tg[0].Count)
- cv.So(t.TagCountList[0].Name, convey.ShouldEqual, tg[0].Name)
- })
- })
- }
- func TestUserTag(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("UserTag", t, func(cv convey.C) {
- tt, err := cli.UserTag(c, &pb.RelationReq{Mid: 1, Fid: 2, RealIp: "127.0.0.1"})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(tt, convey.ShouldNotBeNil)
- })
- fmt.Println(tt)
- tg, err2 := svr.UserTag(c, 1, 2, "127.0.0.1")
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(tg, convey.ShouldNotBeNil)
- })
- fmt.Println(tg)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- cv.So(len(tt.Tags), convey.ShouldEqual, len(tg))
- })
- })
- }
- func TestSpecial(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("Special", t, func(cv convey.C) {
- s, err := cli.Special(c, &pb.MidReq{Mid: 1})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(s, convey.ShouldNotBeNil)
- })
- fmt.Println(s)
- sg, err2 := svr.Special(c, 1)
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(sg, convey.ShouldNotBeNil)
- })
- fmt.Println(sg)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- cv.So(len(sg), convey.ShouldEqual, len(s.Mids))
- })
- })
- }
- func TestFollowersUnread(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("FollowersUnread", t, func(cv convey.C) {
- s, err := cli.FollowersUnread(c, &pb.MidReq{Mid: 1})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(s, convey.ShouldNotBeNil)
- })
- fmt.Println(s)
- h, err2 := svr.Unread(c, 1)
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(h, convey.ShouldNotBeNil)
- })
- fmt.Println(h)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- cv.So(s.HasUnread, convey.ShouldEqual, h)
- })
- })
- }
- func TestFollowersUnreadCount(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("FollowersUnreadCount", t, func(cv convey.C) {
- s, err := cli.FollowersUnreadCount(c, &pb.MidReq{Mid: 1})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(s, convey.ShouldNotBeNil)
- })
- fmt.Println(s)
- h, err2 := svr.UnreadCount(c, 1)
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(h, convey.ShouldNotBeNil)
- })
- fmt.Println(h)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- cv.So(s.UnreadCount, convey.ShouldEqual, h)
- })
- })
- }
- func TestAchieveGet(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("FollowersUnreadCount", t, func(cv convey.C) {
- s, err := cli.AchieveGet(c, &pb.AchieveGetReq{Award: "10k", Mid: 3})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(s, convey.ShouldNotBeNil)
- })
- fmt.Println(s)
- s2, err := cli.Achieve(c, &pb.AchieveReq{AwardToken: s.AwardToken})
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(s2, convey.ShouldNotBeNil)
- })
- fmt.Println(s2)
- h, err2 := svr.AchieveGet(c, &model.ArgAchieveGet{Award: "10k", Mid: 3})
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(h, convey.ShouldNotBeNil)
- })
- fmt.Println(h)
- h2, err2 := svr.Achieve(c, &model.ArgAchieve{AwardToken: h.AwardToken})
- cv.Convey("Then err should be nil reslut should not be nil. ", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(h2, convey.ShouldNotBeNil)
- })
- fmt.Println(h2)
- cv.Convey("Then err should be nil reslut should not be nil.", func(cv convey.C) {
- cv.So(s2.Mid, convey.ShouldEqual, h2.Mid)
- cv.So(s2.Award, convey.ShouldEqual, h2.Award)
- })
- })
- }
- func TestFollowerNotifySetting(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("FollowerNotifySetting", t, func(cv convey.C) {
- s, err := cli.FollowerNotifySetting(c, &pb.MidReq{Mid: 3})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(s, convey.ShouldNotBeNil)
- })
- fmt.Println(s)
- h, err2 := svr.FollowerNotifySetting(c, &model.ArgMid{Mid: 3})
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(h, convey.ShouldNotBeNil)
- })
- fmt.Println(h)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- cv.So(s.Mid, convey.ShouldEqual, h.Mid)
- cv.So(s.Enabled, convey.ShouldEqual, h.Enabled)
- })
- })
- }
- func TestSameFollowings(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("SameFollowings", t, func(cv convey.C) {
- s, err := cli.SameFollowings(c, &pb.SameFollowingReq{Mid: 3, Mid2: 4})
- cv.Convey("Then err should be nil.reslut should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(s, convey.ShouldNotBeNil)
- })
- fmt.Println(s)
- h, err2 := svr.SameFollowings(c, &model.ArgSameFollowing{Mid1: 3, Mid2: 4})
- cv.Convey("Then err should be nil. reslut should not be nil.", func(cv convey.C) {
- cv.So(err2, convey.ShouldBeNil)
- cv.So(h, convey.ShouldNotBeNil)
- })
- fmt.Println(h)
- cv.Convey("the grpc result should be equal to service result", func(cv convey.C) {
- cv.So(len(s.FollowingList), convey.ShouldEqual, len(h))
- f1 := s.FollowingList[0]
- f2 := h[0]
- cv.So(f1.Mid, convey.ShouldEqual, f2.Mid)
- cv.So(f1.MTime, convey.ShouldEqual, f2.MTime)
- cv.So(f1.CTime, convey.ShouldEqual, f2.CTime)
- cv.So(f1.Attribute, convey.ShouldEqual, f2.Attribute)
- cv.So(f1.Source, convey.ShouldEqual, f2.Source)
- cv.So(f1.Special, convey.ShouldEqual, f2.Special)
- })
- })
- }
|