Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Aug 31, 2024
1 parent 6c2d684 commit f8446be
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 166 deletions.
85 changes: 85 additions & 0 deletions pkg/models/a_prep_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package models

import (
"database/sql"
"fmt"
"github.com/google/uuid"
"github.com/mynaparrot/plugnmeet-server/helpers"
"github.com/mynaparrot/plugnmeet-server/pkg/config"
"github.com/mynaparrot/plugnmeet-server/pkg/dbmodels"
dbservice "github.com/mynaparrot/plugnmeet-server/pkg/services/db"
"path/filepath"
"runtime"
"testing"
"time"
)

var (
_, b, _, _ = runtime.Caller(0)
root = filepath.Join(filepath.Dir(b), "../..")
)

var roomTableId uint64
var sid = uuid.NewString()
var roomId = "test01"
var roomCreationTime int64
var recordId string

func init() {
appCnf, err := helpers.ReadYamlConfigFile(root + "/config.yaml")
if err != nil {
panic(err)
}

appCnf.RootWorkingDir = root
// set this config for global usage
config.New(appCnf)

// now prepare server
err = helpers.PrepareServer(config.GetConfig())
if err != nil {
panic(err)
}
}

func Test_PrepareModel(t *testing.T) {
ds := dbservice.New(config.GetConfig().DB)
info := &dbmodels.RoomInfo{
RoomId: roomId,
RoomTitle: "Testing",
Sid: sid,
IsRunning: 1,
IsRecording: 0,
IsActiveRtmp: 0,
}

_, err := ds.InsertOrUpdateRoomInfo(info)
if err != nil {
panic(err)
}

roomTableId = info.ID
roomCreationTime = info.CreationTime
t.Logf("%+v", info)

v := sql.NullString{
String: sid,
Valid: true,
}

recordId = fmt.Sprintf("%s-%d", info.Sid, time.Now().UnixMilli())
data := &dbmodels.Recording{
RecordID: recordId,
RoomID: roomId,
RoomSid: v,
Size: 10.10,
RoomCreationTime: roomCreationTime,
}

_, err = ds.InsertRecordingData(data)
if err != nil {
panic(err)
}

t.Logf("%+v", data)
}
49 changes: 2 additions & 47 deletions pkg/models/analytics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,25 @@ import (
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/mynaparrot/plugnmeet-protocol/plugnmeet"
"github.com/mynaparrot/plugnmeet-server/helpers"
"github.com/mynaparrot/plugnmeet-server/pkg/config"
"github.com/mynaparrot/plugnmeet-server/pkg/dbmodels"
"os"
"path/filepath"
"runtime"
"testing"
"time"
)

var (
_, b, _, _ = runtime.Caller(0)
root = filepath.Join(filepath.Dir(b), "../..")
)

var roomTableId uint64
var sid = fmt.Sprintf("%d", time.Now().UnixNano())
var roomId = "test01"
var roomCreationTime int64
var fileId = fmt.Sprintf("%d", time.Now().Unix())

var analyticsModel *AnalyticsModel
var fileId = fmt.Sprintf("%d", time.Now().UnixNano())

func init() {
appCnf, err := helpers.ReadYamlConfigFile(root + "/config.yaml")
if err != nil {
panic(err)
}

appCnf.RootWorkingDir = root
// set this config for global usage
config.New(appCnf)

// now prepare server
err = helpers.PrepareServer(config.GetConfig())
if err != nil {
panic(err)
}
analyticsModel = NewAnalyticsModel(nil, nil, nil)
}

func TestAnalyticsAuthModel_AddAnalyticsFileToDB(t *testing.T) {
info := &dbmodels.RoomInfo{
RoomId: roomId,
RoomTitle: "Testing",
Sid: sid,
IsRunning: 1,
IsRecording: 0,
IsActiveRtmp: 0,
}

_, err := analyticsModel.ds.InsertOrUpdateRoomInfo(info)
if err != nil {
t.Error(err)
}

t.Logf("%+v", info)
roomTableId = info.ID
stat, err := os.Stat(root + "/config.yaml")
if err != nil {
t.Error(err)
}

_, err = analyticsModel.AddAnalyticsFileToDB(info.ID, info.CreationTime, info.RoomId, fileId, stat)
_, err = analyticsModel.AddAnalyticsFileToDB(roomTableId, roomCreationTime, roomId, fileId, stat)
if err != nil {
t.Error(err)
}
Expand Down
58 changes: 1 addition & 57 deletions pkg/models/bbb_test.go
Original file line number Diff line number Diff line change
@@ -1,68 +1,12 @@
package models

import (
"database/sql"
"github.com/mynaparrot/plugnmeet-protocol/bbbapiwrapper"
"github.com/mynaparrot/plugnmeet-server/helpers"
"github.com/mynaparrot/plugnmeet-server/pkg/config"
"github.com/mynaparrot/plugnmeet-server/pkg/dbmodels"
"testing"
"time"
)

var bbbm *BBBApiWrapperModel

func init() {
appCnf, err := helpers.ReadYamlConfigFile(root + "/config.yaml")
if err != nil {
panic(err)
}

appCnf.RootWorkingDir = root
// set this config for global usage
config.New(appCnf)

// now prepare server
err = helpers.PrepareServer(config.GetConfig())
if err != nil {
panic(err)
}
bbbm = NewBBBApiWrapperModel(nil, nil, nil)

info := &dbmodels.RoomInfo{
RoomId: roomId,
RoomTitle: "Testing",
Sid: sid,
IsRunning: 1,
IsRecording: 0,
IsActiveRtmp: 0,
Created: time.Now().UTC(),
}

_, err = analyticsModel.ds.InsertOrUpdateRoomInfo(info)
if err != nil {
panic(err)
}

v := sql.NullString{
String: sid,
Valid: true,
}
data := &dbmodels.Recording{
RecordID: recordId,
RoomID: roomId,
RoomSid: v,
Size: 10.10,
RoomCreationTime: roomCreationTime,
}

_, err = analyticsModel.ds.InsertRecordingData(data)
if err != nil {
panic(err)
}
}

func TestBBBApiWrapperModel_GetRecordings(t *testing.T) {
bbbm := NewBBBApiWrapperModel(nil, nil, nil)
recordings, pag, err := bbbm.GetRecordings("https://demo.plugnmeet.com", &bbbapiwrapper.GetRecordingsReq{
MeetingID: roomId,
})
Expand Down
72 changes: 10 additions & 62 deletions pkg/models/recording_test.go
Original file line number Diff line number Diff line change
@@ -1,71 +1,19 @@
package models

import (
"database/sql"
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/mynaparrot/plugnmeet-protocol/plugnmeet"
"github.com/mynaparrot/plugnmeet-server/helpers"
"github.com/mynaparrot/plugnmeet-server/pkg/config"
"github.com/mynaparrot/plugnmeet-server/pkg/dbmodels"
"testing"
"time"
)

var m *RecordingModel
var recordId = fmt.Sprintf("rec-%d", time.Now().UnixMilli())

func init() {
appCnf, err := helpers.ReadYamlConfigFile(root + "/config.yaml")
if err != nil {
panic(err)
}

appCnf.RootWorkingDir = root
// set this config for global usage
config.New(appCnf)

// now prepare server
err = helpers.PrepareServer(config.GetConfig())
if err != nil {
panic(err)
}

m = NewRecordingModel(nil, nil, nil)
info := &dbmodels.RoomInfo{
RoomId: roomId,
RoomTitle: "Testing",
Sid: sid,
IsRunning: 1,
IsRecording: 0,
IsActiveRtmp: 0,
}

_, err = m.ds.InsertOrUpdateRoomInfo(info)
if err != nil {
panic(err)
}

v := sql.NullString{
String: sid,
Valid: true,
}
data := &dbmodels.Recording{
RecordID: recordId,
RoomID: roomId,
RoomSid: v,
Size: 10.10,
RoomCreationTime: roomCreationTime,
}

_, err = m.ds.InsertRecordingData(data)
if err != nil {
panic(err)
}
}
var recordingModel *RecordingModel

func TestAuthRecording_FetchRecordings(t *testing.T) {
result, err := m.FetchRecordings(&plugnmeet.FetchRecordingsReq{
recordingModel = NewRecordingModel(nil, nil, nil)

result, err := recordingModel.FetchRecordings(&plugnmeet.FetchRecordingsReq{
RoomIds: []string{roomId},
})
if err != nil {
Expand All @@ -80,7 +28,7 @@ func TestAuthRecording_FetchRecordings(t *testing.T) {
}

func TestAnalyticsAuthModel_FetchRecording(t *testing.T) {
result, err := m.FetchRecording(recordId)
result, err := recordingModel.FetchRecording(recordId)
if err != nil {
t.Error(err)
}
Expand All @@ -91,14 +39,14 @@ func TestAnalyticsAuthModel_FetchRecording(t *testing.T) {

t.Logf("%+v", result)

_, err = m.FetchRecording(fmt.Sprintf("%d", time.Now().UnixMilli()))
_, err = recordingModel.FetchRecording(fmt.Sprintf("%d", time.Now().UnixMilli()))
if err == nil {
t.Error("should got not found error")
}
}

func TestAnalyticsAuthModel_RecordingInfo(t *testing.T) {
result, err := m.RecordingInfo(&plugnmeet.RecordingInfoReq{
result, err := recordingModel.RecordingInfo(&plugnmeet.RecordingInfoReq{
RecordId: recordId,
})
if err != nil {
Expand All @@ -116,7 +64,7 @@ func TestAnalyticsAuthModel_RecordingInfo(t *testing.T) {
}

func TestAnalyticsAuthModel_DeleteRecording(t *testing.T) {
err := m.DeleteRecording(&plugnmeet.DeleteRecordingReq{
err := recordingModel.DeleteRecording(&plugnmeet.DeleteRecordingReq{
RecordId: recordId,
})
if err != nil {
Expand All @@ -125,11 +73,11 @@ func TestAnalyticsAuthModel_DeleteRecording(t *testing.T) {
}

func TestAnalyticsAuthModel_CreateAndVerifyToken(t *testing.T) {
token, err := m.CreateTokenForDownload("test.mp4")
token, err := recordingModel.CreateTokenForDownload("test.mp4")
if err != nil {
t.Error(err)
}
_, res, err := m.VerifyRecordingToken(token)
_, res, err := recordingModel.VerifyRecordingToken(token)
if err == nil {
t.Error("should not found the file")
return
Expand Down

0 comments on commit f8446be

Please sign in to comment.