hbase_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoSagaAuthKey(t *testing.T) {
  9. convey.Convey("sagaAuthKey", t, func(ctx convey.C) {
  10. var (
  11. projID = int(111)
  12. branch = "test"
  13. path = "."
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. p1 := sagaAuthKey(projID, branch, path)
  17. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  18. ctx.So(p1, convey.ShouldEqual, "saga_auth_111_test_.")
  19. })
  20. })
  21. })
  22. }
  23. func TestDaoSetPathAuthH(t *testing.T) {
  24. convey.Convey("SetPathAuthH", t, func(ctx convey.C) {
  25. var (
  26. c = context.Background()
  27. projID = int(111)
  28. branch = "master"
  29. path = "."
  30. owners = []string{"zhanglin", "wuwei"}
  31. reviewers = []string{"tangyongqiang", "changhengyuan"}
  32. )
  33. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  34. err := d.SetPathAuthH(c, projID, branch, path, owners, reviewers)
  35. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  36. ctx.So(err, convey.ShouldBeNil)
  37. })
  38. })
  39. })
  40. }
  41. func TestDaoPathAuthH(t *testing.T) {
  42. convey.Convey("PathAuthH", t, func(ctx convey.C) {
  43. var (
  44. c = context.Background()
  45. projID = int(111)
  46. branch = "master"
  47. path = "."
  48. owner = []string{"zhanglin", "wuwei"}
  49. reviewer = []string{"tangyongqiang", "changhengyuan"}
  50. )
  51. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  52. owners, reviewers, err := d.PathAuthH(c, projID, branch, path)
  53. ctx.Convey("Then err should be nil.owners,reviewers should not be nil.", func(ctx convey.C) {
  54. ctx.So(err, convey.ShouldBeNil)
  55. ctx.So(fmt.Sprint(reviewers), convey.ShouldEqual, fmt.Sprint(reviewer))
  56. ctx.So(fmt.Sprint(owners), convey.ShouldEqual, fmt.Sprint(owner))
  57. })
  58. })
  59. })
  60. }
  61. func TestDaoDeletePathAuthH(t *testing.T) {
  62. convey.Convey("DeletePathAuthH", t, func(ctx convey.C) {
  63. var (
  64. c = context.Background()
  65. projID = int(111)
  66. branch = "master"
  67. path = "."
  68. owners = []string{"zhanglin", "wuwei"}
  69. reviewers = []string{"tangyongqiang", "changhengyuan"}
  70. path2 = "test"
  71. owners2 = []string{"zhang", "wu"}
  72. reviewers2 = []string{"tang", "chang"}
  73. )
  74. ctx.Convey("When data not exist", func(ctx convey.C) {
  75. err := d.DeletePathAuthH(c, projID, branch, path)
  76. ctx.Convey("delete err should be nil.", func(ctx convey.C) {
  77. ctx.So(err, convey.ShouldBeNil)
  78. })
  79. })
  80. ctx.Convey("When data exist", func(ctx convey.C) {
  81. err := d.SetPathAuthH(c, projID, branch, path, owners, reviewers)
  82. ctx.Convey("save path auth.", func(ctx convey.C) {
  83. ctx.So(err, convey.ShouldBeNil)
  84. })
  85. err = d.SetPathAuthH(c, projID, branch, path2, owners2, reviewers2)
  86. ctx.Convey("save path auth 2.", func(ctx convey.C) {
  87. ctx.So(err, convey.ShouldBeNil)
  88. })
  89. os, rs, err := d.PathAuthH(c, projID, branch, path)
  90. ctx.Convey("get path auth", func(ctx convey.C) {
  91. ctx.So(err, convey.ShouldBeNil)
  92. ctx.So(fmt.Sprint(rs), convey.ShouldEqual, fmt.Sprint(reviewers))
  93. ctx.So(fmt.Sprint(os), convey.ShouldEqual, fmt.Sprint(owners))
  94. })
  95. os, rs, err = d.PathAuthH(c, projID, branch, path2)
  96. ctx.Convey("get path auth 2.", func(ctx convey.C) {
  97. ctx.So(err, convey.ShouldBeNil)
  98. ctx.So(fmt.Sprint(rs), convey.ShouldEqual, fmt.Sprint(reviewers2))
  99. ctx.So(fmt.Sprint(os), convey.ShouldEqual, fmt.Sprint(owners2))
  100. })
  101. err = d.DeletePathAuthH(c, projID, branch, path)
  102. ctx.Convey("delete auth path.", func(ctx convey.C) {
  103. ctx.So(err, convey.ShouldBeNil)
  104. })
  105. os, rs, err = d.PathAuthH(c, projID, branch, path)
  106. ctx.Convey("get again path auth.", func(ctx convey.C) {
  107. ctx.So(err, convey.ShouldBeNil)
  108. ctx.So(fmt.Sprint(rs), convey.ShouldEqual, "[]")
  109. ctx.So(fmt.Sprint(os), convey.ShouldEqual, "[]")
  110. ctx.So(len(rs), convey.ShouldEqual, 0)
  111. ctx.So(len(os), convey.ShouldEqual, 0)
  112. })
  113. os, rs, err = d.PathAuthH(c, projID, branch, path2)
  114. ctx.Convey("get again path auth 2.", func(ctx convey.C) {
  115. ctx.So(err, convey.ShouldBeNil)
  116. ctx.So(fmt.Sprint(rs), convey.ShouldEqual, fmt.Sprint(reviewers2))
  117. ctx.So(fmt.Sprint(os), convey.ShouldEqual, fmt.Sprint(owners2))
  118. })
  119. })
  120. })
  121. }