summaryrefslogtreecommitdiff
path: root/bilibili/streaming_test.go
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-09-16 21:14:50 +0800
committerKeuin <[email protected]>2022-09-16 21:14:50 +0800
commite36b9574037d3ddea06a65351b57840fe05bc4a8 (patch)
treef4ec8422a393d17bbf75b004362914f68a9c90d2 /bilibili/streaming_test.go
parent7d8ec5f208c645fef71e2b1fd9ce1f891edfda45 (diff)
Add test for core bilibili API wrappers.
Diffstat (limited to 'bilibili/streaming_test.go')
-rw-r--r--bilibili/streaming_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/bilibili/streaming_test.go b/bilibili/streaming_test.go
new file mode 100644
index 0000000..ef438db
--- /dev/null
+++ b/bilibili/streaming_test.go
@@ -0,0 +1,44 @@
+package bilibili
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "github.com/keuin/slbr/common"
+ "github.com/keuin/slbr/logging"
+ "log"
+ "os"
+ "testing"
+)
+
+func TestBilibili_CopyLiveStream(t *testing.T) {
+ // get an online live room for testing
+ liveList, err := common.GetLiveListForGuestUser()
+ if err != nil {
+ t.Fatalf("cannot get live list for testing: %v", err)
+ }
+ lives := liveList.Data.Data
+ if len(lives) <= 0 {
+ t.Fatalf("no live for guest available")
+ }
+ roomId := common.RoomId(lives[0].Roomid)
+
+ logger := log.Default()
+ bi := NewBilibili(logging.NewWrappedLogger(logger, "test-logger"))
+
+ si, err := bi.GetStreamingInfo(roomId)
+ if err != nil {
+ t.Fatalf("GetStreamingInfo: %v", err)
+ }
+
+ // test file open failure
+ testErr := fmt.Errorf("test error")
+ err = bi.CopyLiveStream(context.Background(), roomId, si.Data.URLs[0], func() (*os.File, error) {
+ return nil, testErr
+ }, 1048576)
+ if !errors.Is(err, testErr) {
+ t.Fatalf("Unexpected error from CopyLiveStream: %v", err)
+ }
+
+ // TODO more tests
+}