Files
mp-qvyun/backend/modules/medias/service_test.go
2024-12-28 16:05:25 +08:00

86 lines
1.9 KiB
Go

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 := "907f1c8fd92704233600ae54a1d75092"
media, err := t.Svc.GetM3U8(context.Background(), 1, pg.MediaTypeVideo, hash, true, "hello")
So(err, ShouldBeNil)
t.T().Logf("%+v", media)
})
FocusConvey("Not Bought", func() {
hash := "907f1c8fd92704233600ae54a1d75092"
media, err := t.Svc.GetM3U8(context.Background(), 1, pg.MediaTypeVideo, hash, false, "hello")
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)
})
}