statuses update
This commit is contained in:
65
watcher/internal/pipelinestatus/status_test.go
Normal file
65
watcher/internal/pipelinestatus/status_test.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package pipelinestatus
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEventJSON(t *testing.T) {
|
||||
ev := Event{
|
||||
TaskID: "01HXABCDEF",
|
||||
Filename: "call.wav",
|
||||
Status: StatusPending,
|
||||
Stage: StageQueued,
|
||||
Timestamp: 1717843200,
|
||||
}
|
||||
body, err := json.Marshal(ev)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var got Event
|
||||
if err := json.Unmarshal(body, &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.TaskID != ev.TaskID || got.Status != StatusPending || got.Stage != StageQueued {
|
||||
t.Fatalf("unexpected event: %+v", got)
|
||||
}
|
||||
if got.Error != "" {
|
||||
t.Fatalf("expected empty error, got %q", got.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEventJSONWithError(t *testing.T) {
|
||||
ev := Event{
|
||||
TaskID: "01HX",
|
||||
Status: StatusError,
|
||||
Stage: StageTranscribing,
|
||||
Error: "nexara timeout",
|
||||
}
|
||||
body, err := json.Marshal(ev)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !json.Valid(body) {
|
||||
t.Fatal("invalid json")
|
||||
}
|
||||
var got Event
|
||||
if err := json.Unmarshal(body, &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.Error != "nexara timeout" {
|
||||
t.Fatalf("error field: got %q", got.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusConstants(t *testing.T) {
|
||||
statuses := []string{StatusPending, StatusInProgress, StatusDone, StatusError}
|
||||
seen := make(map[string]bool)
|
||||
for _, s := range statuses {
|
||||
if seen[s] {
|
||||
t.Fatalf("duplicate status %q", s)
|
||||
}
|
||||
seen[s] = true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user