service_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "path/filepath"
  7. "testing"
  8. "time"
  9. "go-common/app/admin/main/appstatic/conf"
  10. "go-common/app/admin/main/appstatic/model"
  11. . "github.com/smartystreets/goconvey/convey"
  12. )
  13. var srv *Service
  14. func init() {
  15. dir, _ := filepath.Abs("../cmd/appstatic-admin-test.toml")
  16. flag.Set("conf", dir)
  17. conf.Init()
  18. srv = New(conf.Conf)
  19. time.Sleep(time.Second)
  20. }
  21. func WithService(f func(s *Service)) func() {
  22. return func() {
  23. f(srv)
  24. }
  25. }
  26. func TestService_Ping(t *testing.T) {
  27. Convey("Ping", t, WithService(func(svf *Service) {
  28. svf.Ping(context.Background())
  29. fmt.Println("service ping successfully")
  30. }))
  31. }
  32. func TestService_Wait(t *testing.T) {
  33. Convey("Ping", t, WithService(func(svf *Service) {
  34. svf.Wait()
  35. fmt.Println("service wait successfully")
  36. }))
  37. }
  38. func TestService_Close(t *testing.T) {
  39. Convey("Close", t, WithService(func(svf *Service) {
  40. svf.Close()
  41. fmt.Println("service closed successfully")
  42. }))
  43. }
  44. func TestService_GenerateVer(t *testing.T) {
  45. Convey("Generate Version", t, WithService(func(svf *Service) {
  46. resID, version, err := svf.GenerateVer("myTestRes", &model.Limit{}, &model.FileInfo{
  47. Name: "testResFile",
  48. Size: 333,
  49. Type: "application/zip",
  50. Md5: "333",
  51. URL: "www.bilibili.com",
  52. }, &model.ResourcePool{
  53. ID: 1,
  54. Name: "resourcefile",
  55. }, 1)
  56. So(err, ShouldBeNil)
  57. So(resID, ShouldBeGreaterThan, 0)
  58. So(version, ShouldBeGreaterThan, 0)
  59. }))
  60. }