mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-09 01:50:30 +00:00
feat: move native communication to FFI (#1457)
This commit is contained in:
86 files changed
+4558
-886
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/GopeedLab/gopeed/pkg/download"
|
||||
)
|
||||
|
||||
func TestTaskEventSubscriptionFiltersMask(t *testing.T) {
|
||||
service := &Service{}
|
||||
var payloads []string
|
||||
service.SubscribeTaskEvents(TaskEventDone, func(payload string) {
|
||||
payloads = append(payloads, payload)
|
||||
})
|
||||
|
||||
task := &download.Task{ID: "task-1"}
|
||||
service.emitTaskEvent(&download.Event{Key: download.EventKeyError, Task: task})
|
||||
service.emitTaskEvent(&download.Event{Key: download.EventKeyDone, Task: task})
|
||||
|
||||
if len(payloads) != 1 {
|
||||
t.Fatalf("got %d callbacks, want 1", len(payloads))
|
||||
}
|
||||
var event TaskEvent
|
||||
if err := json.Unmarshal([]byte(payloads[0]), &event); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if event.Type != "task.done" || event.TaskID != task.ID {
|
||||
t.Fatalf("unexpected event: %#v", event)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskEventListenerPanicIsContained(t *testing.T) {
|
||||
service := &Service{}
|
||||
service.SubscribeTaskEvents(TaskEventDone, func(string) { panic("callback failed") })
|
||||
service.emitTaskEvent(&download.Event{Key: download.EventKeyDone, Task: &download.Task{ID: "task-1"}})
|
||||
}
|
||||
Reference in new issue
Block a user