Go · 1153 bytes Raw Blame History
1 // SPDX-License-Identifier: AGPL-3.0-or-later
2
3 package logstream
4
5 import "testing"
6
7 func TestChannelAndListenSQL(t *testing.T) {
8 t.Parallel()
9 if got := Channel(42); got != "step_log_42" {
10 t.Fatalf("Channel=%q", got)
11 }
12 if got := ListenSQL(42); got != `LISTEN "step_log_42"` {
13 t.Fatalf("ListenSQL=%q", got)
14 }
15 if got := UnlistenSQL(42); got != `UNLISTEN "step_log_42"` {
16 t.Fatalf("UnlistenSQL=%q", got)
17 }
18 }
19
20 func TestParsePayload(t *testing.T) {
21 t.Parallel()
22 tests := []struct {
23 name string
24 payload string
25 wantSeq int32
26 wantDone bool
27 wantOK bool
28 }{
29 {name: "chunk", payload: "7", wantSeq: 7, wantOK: true},
30 {name: "done", payload: "done", wantDone: true, wantOK: true},
31 {name: "trim", payload: " 8 ", wantSeq: 8, wantOK: true},
32 {name: "negative", payload: "-1"},
33 {name: "invalid", payload: "chunk:1"},
34 }
35 for _, tt := range tests {
36 t.Run(tt.name, func(t *testing.T) {
37 t.Parallel()
38 gotSeq, gotDone, gotOK := ParsePayload(tt.payload)
39 if gotSeq != tt.wantSeq || gotDone != tt.wantDone || gotOK != tt.wantOK {
40 t.Fatalf("ParsePayload(%q)=(%d,%v,%v)", tt.payload, gotSeq, gotDone, gotOK)
41 }
42 })
43 }
44 }
45