dao_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package relation
  2. import (
  3. "context"
  4. "flag"
  5. "go-common/app/service/main/videoup/conf"
  6. "os"
  7. "testing"
  8. "github.com/davecgh/go-spew/spew"
  9. "github.com/smartystreets/goconvey/convey"
  10. "path/filepath"
  11. )
  12. var (
  13. d *Dao
  14. )
  15. func TestMain(m *testing.M) {
  16. if os.Getenv("DEPLOY_ENV") != "" {
  17. flag.Set("app_id", "main.archive.videoup-service")
  18. flag.Set("conf_token", "4b62721602981eb3635dba3b0d866ac5")
  19. flag.Set("tree_id", "2308")
  20. flag.Set("conf_version", "docker-1")
  21. flag.Set("deploy_env", "uat")
  22. flag.Set("conf_host", "config.bilibili.co")
  23. flag.Set("conf_path", "/tmp")
  24. flag.Set("region", "sh")
  25. flag.Set("zone", "sh001")
  26. } else {
  27. dir, _ := filepath.Abs("../../cmd/videoup-service.toml")
  28. flag.Set("conf", dir)
  29. }
  30. flag.Parse()
  31. if err := conf.Init(); err != nil {
  32. panic(err)
  33. }
  34. d = New(conf.Conf)
  35. m.Run()
  36. os.Exit(0)
  37. }
  38. func TestRelationPing(t *testing.T) {
  39. var (
  40. c = context.TODO()
  41. )
  42. convey.Convey("Ping", t, func(ctx convey.C) {
  43. err := d.Ping(c)
  44. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  45. ctx.So(err, convey.ShouldBeNil)
  46. })
  47. })
  48. }
  49. func TestRelation(t *testing.T) {
  50. var (
  51. c = context.TODO()
  52. )
  53. convey.Convey("Relation", t, func(ctx convey.C) {
  54. data, err := d.Relation(c, 27515314, 27515258, 1)
  55. spew.Dump(data)
  56. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  57. ctx.So(err, convey.ShouldBeNil)
  58. })
  59. })
  60. }
  61. func TestAddBlack(t *testing.T) {
  62. var (
  63. c = context.TODO()
  64. )
  65. convey.Convey("Relation", t, func(ctx convey.C) {
  66. err := d.AddBalck(c, 27515260, 2089809, 1)
  67. spew.Dump(err)
  68. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  69. ctx.So(err, convey.ShouldBeNil)
  70. })
  71. })
  72. }