Go · 1054 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 }
16
17 func TestParsePayload(t *testing.T) {
18 t.Parallel()
19 tests := []struct {
20 name string
21 payload string
22 wantSeq int32
23 wantDone bool
24 wantOK bool
25 }{
26 {name: "chunk", payload: "7", wantSeq: 7, wantOK: true},
27 {name: "done", payload: "done", wantDone: true, wantOK: true},
28 {name: "trim", payload: " 8 ", wantSeq: 8, wantOK: true},
29 {name: "negative", payload: "-1"},
30 {name: "invalid", payload: "chunk:1"},
31 }
32 for _, tt := range tests {
33 t.Run(tt.name, func(t *testing.T) {
34 t.Parallel()
35 gotSeq, gotDone, gotOK := ParsePayload(tt.payload)
36 if gotSeq != tt.wantSeq || gotDone != tt.wantDone || gotOK != tt.wantOK {
37 t.Fatalf("ParsePayload(%q)=(%d,%v,%v)", tt.payload, gotSeq, gotDone, gotOK)
38 }
39 })
40 }
41 }
42