module_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package module
  2. import (
  3. "context"
  4. "encoding/json"
  5. "flag"
  6. "fmt"
  7. "path/filepath"
  8. "testing"
  9. "time"
  10. "go-common/app/interface/main/app-resource/conf"
  11. "go-common/app/interface/main/app-resource/model/module"
  12. . "github.com/smartystreets/goconvey/convey"
  13. )
  14. var (
  15. s *Service
  16. )
  17. func WithService(f func(s *Service)) func() {
  18. return func() {
  19. f(s)
  20. }
  21. }
  22. func init() {
  23. dir, _ := filepath.Abs("../../cmd/app-resource-test.toml")
  24. flag.Set("conf", dir)
  25. conf.Init()
  26. s = New(conf.Conf)
  27. time.Sleep(time.Second)
  28. }
  29. func TestList(t *testing.T) {
  30. Convey("get list data", t, WithService(func(s *Service) {
  31. res := s.List(context.TODO(), "iphone", "phone", "ios", "resourcefile", "1", 4500, 0, 0, 0, 0, []*module.Versions{}, time.Now())
  32. result, _ := json.Marshal(res)
  33. fmt.Printf("test list (%v) \n", string(result))
  34. So(res, ShouldNotBeEmpty)
  35. }))
  36. }
  37. func TestResource(t *testing.T) {
  38. Convey("get Resource data", t, WithService(func(s *Service) {
  39. res, err := s.Resource(context.TODO(), "iphone", "phone", "ios", "resourcefile", "我的测试包222", "1", 21, 3500, 0, 0, 0, 0, time.Now())
  40. result, _ := json.Marshal(res)
  41. fmt.Printf("test Resource (%v) \n", string(result))
  42. So(res, ShouldNotBeEmpty)
  43. So(err, ShouldBeNil)
  44. }))
  45. }