44 lines
925 B
Go
44 lines
925 B
Go
package publisher
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestAudioTaskJSON(t *testing.T) {
|
|
task := AudioTask{
|
|
TaskID: "01HXABCDEF",
|
|
FilePath: "/data/storage/processing/01HX.wav",
|
|
Filename: "call.wav",
|
|
Size: 1024,
|
|
CreatedAt: 1717843200,
|
|
}
|
|
body, err := json.Marshal(task)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
var got AudioTask
|
|
if err := json.Unmarshal(body, &got); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got.TaskID != task.TaskID || got.FilePath != task.FilePath || got.Size != 1024 {
|
|
t.Fatalf("unexpected task: %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestAudioTaskCreatedAtDefault(t *testing.T) {
|
|
task := AudioTask{TaskID: "x", Filename: "a.wav"}
|
|
if task.CreatedAt != 0 {
|
|
t.Fatal("zero value should have CreatedAt=0 before publish")
|
|
}
|
|
before := time.Now().Unix()
|
|
if task.CreatedAt == 0 {
|
|
task.CreatedAt = time.Now().Unix()
|
|
}
|
|
if task.CreatedAt < before {
|
|
t.Fatal("timestamp should be set")
|
|
}
|
|
}
|