privilege_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package service
  2. import (
  3. "bytes"
  4. "context"
  5. "image/png"
  6. "os"
  7. "testing"
  8. "go-common/app/admin/main/vip/model"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. // go test -test.v -test.run TestServicePrivileges
  12. func TestServicePrivileges(t *testing.T) {
  13. Convey("TestServicePrivileges", t, func() {
  14. res, err := s.Privileges(context.TODO(), 0)
  15. for _, v := range res {
  16. t.Logf("%+v", v)
  17. }
  18. So(err, ShouldBeNil)
  19. })
  20. }
  21. // go test -test.v -test.run TestUpdatePrivilegeState
  22. func TestUpdatePrivilegeState(t *testing.T) {
  23. Convey("TestUpdatePrivilegeState", t, func() {
  24. err := s.UpdatePrivilegeState(context.TODO(), &model.Privilege{
  25. ID: 4,
  26. State: 1,
  27. })
  28. So(err, ShouldBeNil)
  29. })
  30. }
  31. // go test -test.v -test.run TestDeletePrivilege
  32. func TestDeletePrivilege(t *testing.T) {
  33. Convey("TestDeletePrivilege", t, func() {
  34. err := s.DeletePrivilege(context.TODO(), 4)
  35. So(err, ShouldBeNil)
  36. })
  37. }
  38. // go test -test.v -test.run TestUpdateOrder
  39. func TestUpdateOrder(t *testing.T) {
  40. Convey("TestUpdateOrder", t, func() {
  41. err := s.UpdateOrder(context.TODO(), &model.ArgOrder{
  42. AID: 5,
  43. BID: 4,
  44. })
  45. So(err, ShouldBeNil)
  46. })
  47. }
  48. // go test -test.v -test.run TestServiceUpload
  49. func TestServiceUpload(t *testing.T) {
  50. Convey("TestServiceUpload", t, func() {
  51. file, _ := os.Open("/Users/baihai/Documents/test.png")
  52. So(file, ShouldNotBeNil)
  53. buf := new(bytes.Buffer)
  54. img, _ := png.Decode(file)
  55. png.Encode(buf, img)
  56. bys := buf.Bytes()
  57. t.Logf("conf %+v", s.c.Bfs)
  58. iconURL, iconGrayURL, webImageURL, appImageURL, err := s.uploadImage(context.TODO(), &model.ArgImage{
  59. IconBody: bys,
  60. IconFileType: "image/png",
  61. IconGrayBody: bys,
  62. IconGrayFileType: "image/png",
  63. })
  64. t.Logf("url iconURL:%s iconGrayURL:%s webImageURL:%s appImageURL:%s", iconURL, iconGrayURL, webImageURL, appImageURL)
  65. So(err, ShouldBeNil)
  66. })
  67. }
  68. // go test -test.v -test.run TestServiceAddPrivilege
  69. func TestServiceAddPrivilege(t *testing.T) {
  70. Convey("TestServiceAddPrivilege", t, func() {
  71. file, _ := os.Open("/Users/baihai/Documents/test.png")
  72. So(file, ShouldNotBeNil)
  73. buf := new(bytes.Buffer)
  74. img, _ := png.Decode(file)
  75. png.Encode(buf, img)
  76. bys := buf.Bytes()
  77. t.Logf("conf %+v", s.c.Bfs)
  78. err := s.AddPrivilege(context.TODO(), &model.ArgAddPrivilege{
  79. Name: "超级",
  80. Title: "超级标题",
  81. Explain: "超级内容",
  82. Type: 0,
  83. Operator: "admin",
  84. WebLink: "http://www.baidu.com",
  85. AppLink: "http://www.baidu.com",
  86. }, &model.ArgImage{
  87. IconBody: bys,
  88. IconFileType: "image/png",
  89. IconGrayBody: bys,
  90. IconGrayFileType: "image/png",
  91. })
  92. So(err, ShouldBeNil)
  93. })
  94. }
  95. // go test -test.v -test.run TestServiceUpdatePrivilege
  96. func TestServiceUpdatePrivilege(t *testing.T) {
  97. Convey("TestServiceUpdatePrivilege", t, func() {
  98. file, _ := os.Open("/Users/baihai/Documents/test.png")
  99. So(file, ShouldNotBeNil)
  100. buf := new(bytes.Buffer)
  101. img, _ := png.Decode(file)
  102. png.Encode(buf, img)
  103. bys := buf.Bytes()
  104. t.Logf("conf %+v", s.c.Bfs)
  105. err := s.UpdatePrivilege(context.TODO(), &model.ArgUpdatePrivilege{
  106. ID: 3,
  107. Name: "超级",
  108. Title: "超级标题",
  109. Explain: "超级内容",
  110. Type: 0,
  111. Operator: "admin",
  112. WebLink: "http://www.baidu.com",
  113. AppLink: "http://www.baidu.com",
  114. }, &model.ArgImage{
  115. IconBody: bys,
  116. IconFileType: "image/png",
  117. IconGrayBody: bys,
  118. IconGrayFileType: "image/png",
  119. })
  120. So(err, ShouldBeNil)
  121. })
  122. }