package medias import ( "context" "testing" "backend/pkg/path" "backend/pkg/pg" "backend/pkg/service/testx" "backend/providers/hashids" "backend/providers/postgres" "backend/providers/storage" log "github.com/sirupsen/logrus" . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/suite" "go.uber.org/dig" ) type ServiceInjectParams struct { dig.In Svc *Service } type ServiceTestSuite struct { suite.Suite ServiceInjectParams } func Test_DiscoverMedias(t *testing.T) { log.SetLevel(log.DebugLevel) providers := testx.Default( postgres.DefaultProvider(), storage.DefaultProvider(), hashids.DefaultProvider(), ).With( Provide, ) testx.Serve(providers, t, func(params ServiceInjectParams) { suite.Run(t, &ServiceTestSuite{ServiceInjectParams: params}) }) } func (t *ServiceTestSuite) Test_getM3U8() { FocusConvey("Test_ffmpegVideoToM3U8", t.T(), func() { Convey("Bought", func() { hash := "f464a6641a60e2722e4042db8fad2813" media, err := t.Svc.GetM3U8(context.Background(), 1, pg.MediaTypeVideo, hash, true) So(err, ShouldBeNil) t.T().Logf("%+v", media) }) FocusConvey("Not Bought", func() { hash := "f464a6641a60e2722e4042db8fad2813" media, err := t.Svc.GetM3U8(context.Background(), 1, pg.MediaTypeVideo, hash, false) So(err, ShouldBeNil) t.T().Logf("%+v", media) }) }) } func (t *ServiceTestSuite) Test_getMediaByHash() { Convey("Test_getMediaByHash", t.T(), func() { name, ext := path.SplitNameExt("0.ts") So(name, ShouldEqual, "0") So(ext, ShouldEqual, "ts") }) } func (t *ServiceTestSuite) Test_GetUserBalance() { Convey("Test_GetUserBalance", t.T(), func() { balance, err := t.Svc.GetUserBalance(context.Background(), 1, 1) So(err, ShouldBeNil) t.T().Logf("balance: %+v", balance) }) } func (t *ServiceTestSuite) Test_Checkout() { Convey("Test_Checkout", t.T(), func() { err := t.Svc.Checkout(context.TODO(), 1, 1, 1) So(err, ShouldBeNil) }) }