dao_test.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. package audio
  2. import (
  3. "context"
  4. "flag"
  5. "go-common/app/interface/main/app-interface/conf"
  6. "go-common/app/interface/main/app-interface/model/audio"
  7. "go-common/library/net/ip"
  8. "path/filepath"
  9. "reflect"
  10. "testing"
  11. . "github.com/smartystreets/goconvey/convey"
  12. )
  13. var d *Dao
  14. func init() {
  15. dir, _ := filepath.Abs("../../cmd/app-interface-test.toml")
  16. flag.Set("conf", dir)
  17. conf.Init()
  18. d = New(conf.Conf)
  19. }
  20. func TestNew(t *testing.T) {
  21. type args struct {
  22. c *conf.Config
  23. }
  24. tests := []struct {
  25. name string
  26. args args
  27. wantD *Dao
  28. }{
  29. // TODO: Add test cases.
  30. }
  31. for _, tt := range tests {
  32. t.Run(tt.name, func(t *testing.T) {
  33. if gotD := New(tt.args.c); !reflect.DeepEqual(gotD, tt.wantD) {
  34. t.Errorf("New() = %v, want %v", gotD, tt.wantD)
  35. }
  36. })
  37. }
  38. }
  39. func TestDao_Audios(t *testing.T) {
  40. type args struct {
  41. c context.Context
  42. mid int64
  43. pn int
  44. ps int
  45. }
  46. tests := []struct {
  47. name string
  48. args args
  49. wantAudios []*audio.Audio
  50. wantTotal int
  51. wantErr bool
  52. }{
  53. // TODO: Add test cases.
  54. }
  55. for _, tt := range tests {
  56. t.Run(tt.name, func(t *testing.T) {
  57. gotAudios, gotTotal, err := d.Audios(tt.args.c, tt.args.mid, tt.args.pn, tt.args.ps)
  58. if (err != nil) != tt.wantErr {
  59. t.Errorf("Dao.Audios() error = %v, wantErr %v", err, tt.wantErr)
  60. return
  61. }
  62. if !reflect.DeepEqual(gotAudios, tt.wantAudios) {
  63. t.Errorf("Dao.Audios() gotAudios = %v, want %v", gotAudios, tt.wantAudios)
  64. }
  65. if gotTotal != tt.wantTotal {
  66. t.Errorf("Dao.Audios() gotTotal = %v, want %v", gotTotal, tt.wantTotal)
  67. }
  68. })
  69. }
  70. }
  71. func TestDao_AllAudio(t *testing.T) {
  72. type args struct {
  73. c context.Context
  74. vmid int64
  75. }
  76. tests := []struct {
  77. name string
  78. args args
  79. wantAus []*audio.Audio
  80. wantErr bool
  81. }{
  82. // TODO: Add test cases.
  83. }
  84. for _, tt := range tests {
  85. t.Run(tt.name, func(t *testing.T) {
  86. gotAus, err := d.AllAudio(tt.args.c, tt.args.vmid)
  87. if (err != nil) != tt.wantErr {
  88. t.Errorf("Dao.AllAudio() error = %v, wantErr %v", err, tt.wantErr)
  89. return
  90. }
  91. if !reflect.DeepEqual(gotAus, tt.wantAus) {
  92. t.Errorf("Dao.AllAudio() = %v, want %v", gotAus, tt.wantAus)
  93. }
  94. })
  95. }
  96. }
  97. func TestDao_AudioDetail(t *testing.T) {
  98. type args struct {
  99. c context.Context
  100. ids []int64
  101. }
  102. tests := []struct {
  103. name string
  104. args args
  105. wantAum map[int64]*audio.Audio
  106. wantErr bool
  107. }{
  108. // TODO: Add test cases.
  109. }
  110. for _, tt := range tests {
  111. t.Run(tt.name, func(t *testing.T) {
  112. gotAum, err := d.AudioDetail(tt.args.c, tt.args.ids)
  113. if (err != nil) != tt.wantErr {
  114. t.Errorf("Dao.AudioDetail() error = %v, wantErr %v", err, tt.wantErr)
  115. return
  116. }
  117. if !reflect.DeepEqual(gotAum, tt.wantAum) {
  118. t.Errorf("Dao.AudioDetail() = %v, want %v", gotAum, tt.wantAum)
  119. }
  120. })
  121. }
  122. }
  123. func TestDao_FavAudio(t *testing.T) {
  124. type args struct {
  125. c context.Context
  126. accessKey string
  127. mid int64
  128. pn int
  129. ps int
  130. }
  131. tests := []struct {
  132. name string
  133. args args
  134. wantAus []*audio.FavAudio
  135. wantErr bool
  136. }{
  137. // TODO: Add test cases.
  138. }
  139. for _, tt := range tests {
  140. t.Run(tt.name, func(t *testing.T) {
  141. gotAus, err := d.FavAudio(tt.args.c, tt.args.accessKey, tt.args.mid, tt.args.pn, tt.args.ps)
  142. if (err != nil) != tt.wantErr {
  143. t.Errorf("Dao.FavAudio() error = %v, wantErr %v", err, tt.wantErr)
  144. return
  145. }
  146. if !reflect.DeepEqual(gotAus, tt.wantAus) {
  147. t.Errorf("Dao.FavAudio() = %v, want %v", gotAus, tt.wantAus)
  148. }
  149. })
  150. }
  151. }
  152. func TestDao_UpperCert(t *testing.T) {
  153. type args struct {
  154. c context.Context
  155. uid int64
  156. }
  157. tests := []struct {
  158. name string
  159. args args
  160. wantCert *audio.UpperCert
  161. wantErr bool
  162. }{
  163. // TODO: Add test cases.
  164. }
  165. for _, tt := range tests {
  166. t.Run(tt.name, func(t *testing.T) {
  167. gotCert, err := d.UpperCert(tt.args.c, tt.args.uid)
  168. if (err != nil) != tt.wantErr {
  169. t.Errorf("Dao.UpperCert() error = %v, wantErr %v", err, tt.wantErr)
  170. return
  171. }
  172. if !reflect.DeepEqual(gotCert, tt.wantCert) {
  173. t.Errorf("Dao.UpperCert() = %v, want %v", gotCert, tt.wantCert)
  174. }
  175. })
  176. }
  177. }
  178. func TestDao_Card(t *testing.T) {
  179. type args struct {
  180. c context.Context
  181. ip string
  182. mid []int64
  183. }
  184. tests := []struct {
  185. name string
  186. args args
  187. wantCardm map[int64]*audio.Card
  188. wantErr error
  189. }{
  190. {
  191. "normal",
  192. args{
  193. context.TODO(),
  194. ip.InternalIP(),
  195. []int64{30047},
  196. },
  197. map[int64]*audio.Card{30047: &audio.Card{Type: 1, Status: 1}},
  198. nil,
  199. },
  200. }
  201. for _, tt := range tests {
  202. Convey(tt.name, t, func() {
  203. gotCardm, err := d.Card(tt.args.c, tt.args.mid...)
  204. So(err, ShouldBeNil)
  205. So(gotCardm, ShouldResemble, tt.wantCardm)
  206. })
  207. }
  208. }
  209. func TestDao_Fav(t *testing.T) {
  210. type args struct {
  211. c context.Context
  212. mid int64
  213. }
  214. tests := []struct {
  215. name string
  216. args args
  217. wantFav *audio.Fav
  218. wantErr bool
  219. }{
  220. // TODO: Add test cases.
  221. }
  222. for _, tt := range tests {
  223. t.Run(tt.name, func(t *testing.T) {
  224. gotFav, err := d.Fav(tt.args.c, tt.args.mid)
  225. if (err != nil) != tt.wantErr {
  226. t.Errorf("Dao.Fav() error = %v, wantErr %v", err, tt.wantErr)
  227. return
  228. }
  229. if !reflect.DeepEqual(gotFav, tt.wantFav) {
  230. t.Errorf("Dao.Fav() = %v, want %v", gotFav, tt.wantFav)
  231. }
  232. })
  233. }
  234. }