service_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "os"
  7. "testing"
  8. "go-common/app/job/main/answer/conf"
  9. "go-common/app/job/main/answer/model"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var (
  13. s *Service
  14. )
  15. func TestMain(m *testing.M) {
  16. if os.Getenv("DEPLOY_ENV") != "" {
  17. flag.Set("app_id", "")
  18. flag.Set("conf_appid", "")
  19. flag.Set("conf_token", "")
  20. flag.Set("tree_id", "")
  21. flag.Set("conf_version", "server-1")
  22. flag.Set("deploy_env", "dev")
  23. flag.Set("conf_env", "10")
  24. flag.Set("conf_host", "config.bilibili.co")
  25. flag.Set("conf_path", "/tmp")
  26. flag.Set("region", "sh")
  27. flag.Set("zone", "sh001")
  28. } else {
  29. flag.Set("conf", "../cmd/answer-job-test.toml")
  30. }
  31. flag.Parse()
  32. if err := conf.Init(); err != nil {
  33. panic(err)
  34. }
  35. s = New(conf.Conf)
  36. os.Exit(m.Run())
  37. }
  38. func TestUpdateBfs(t *testing.T) {
  39. Convey("create img", t, func(s *Service) {
  40. err := s.createBFSImg(context.TODO(), &model.LabourQs{
  41. Question: "测试附加题3",
  42. ID: 3,
  43. })
  44. fmt.Println("err:", err)
  45. So(err, ShouldBeNil)
  46. })
  47. }
  48. func TestPing(t *testing.T) {
  49. Convey("Test_Ping", t, func(s *Service) {
  50. err := s.Ping(context.TODO())
  51. So(err, ShouldBeNil)
  52. })
  53. }
  54. // go test -test.v -test.run TestAddQue
  55. func TestCreateBFSImg(t *testing.T) {
  56. Convey("TestAddQue add question data", t, func(s *Service) {
  57. for i := 90; i < 100; i++ {
  58. que := &model.LabourQs{
  59. Question: fmt.Sprintf("测试d=====( ̄▽ ̄*)b厉害 %d", i),
  60. Ans: int8(i%2 + 1),
  61. AvID: int64(i),
  62. Status: int8(i%2 + 1),
  63. Source: int8(1),
  64. State: model.HadCreateImg,
  65. ID: int64(i),
  66. }
  67. err := s.createBFSImg(context.TODO(), que)
  68. So(err, ShouldBeNil)
  69. err = s.dao.AddQs(context.TODO(), que)
  70. So(err, ShouldBeNil)
  71. }
  72. })
  73. }