abtest_test.go 792 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package abtest
  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/service/main/resource/model"
  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 TestExperiment(t *testing.T) {
  30. Convey("get Experiment data", t, WithService(func(s *Service) {
  31. res := s.Experiment(context.TODO(), model.PlatAndroid, 100)
  32. result, _ := json.Marshal(res)
  33. fmt.Printf("test Experiment (%v) \n", string(result))
  34. So(res, ShouldNotBeEmpty)
  35. }))
  36. }