package services
|
|
import "testing"
|
|
func TestEngineServiceDownloadStatusTracksCancelAndFinish(t *testing.T) {
|
service := NewEngineService(nil)
|
status := service.GetModelDownloadStatus()
|
if status["active"].(bool) {
|
t.Fatal("new service should not report an active model download")
|
}
|
|
_, finish, err := service.beginModelDownload("zipformer-ko")
|
if err != nil {
|
t.Fatal(err)
|
}
|
status = service.GetModelDownloadStatus()
|
if !status["active"].(bool) {
|
t.Fatal("active download was not reported")
|
}
|
if got := status["modelID"]; got != "zipformer-ko" {
|
t.Fatalf("modelID = %v, want zipformer-ko", got)
|
}
|
if status["cancelling"].(bool) {
|
t.Fatal("new download should not start in cancelling state")
|
}
|
|
service.updateModelDownloadProgress("zipformer-ko", 42.5, 425, 1000)
|
status = service.GetModelDownloadStatus()
|
if got := status["percent"]; got != 42.5 {
|
t.Fatalf("percent = %v, want 42.5", got)
|
}
|
if got := status["downloaded"]; got != int64(425) {
|
t.Fatalf("downloaded = %v, want 425", got)
|
}
|
if got := status["total"]; got != int64(1000) {
|
t.Fatalf("total = %v, want 1000", got)
|
}
|
|
if !service.CancelModelDownload("zipformer-ko") {
|
t.Fatal("expected active download to be cancelled")
|
}
|
status = service.GetModelDownloadStatus()
|
if !status["cancelling"].(bool) {
|
t.Fatal("cancelled download should report cancelling state until finish")
|
}
|
|
finish()
|
status = service.GetModelDownloadStatus()
|
if status["active"].(bool) {
|
t.Fatal("finished download should clear active state")
|
}
|
if got := status["modelID"]; got != "" {
|
t.Fatalf("modelID after finish = %v, want empty", got)
|
}
|
}
|