| 1 | package wire_test |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "errors" |
| 6 | "testing" |
| 7 | |
| 8 | "amadan.net/oficina/equipo/internal/wire" |
| 9 | ) |
| 10 | |
| 11 | // Warm (protocol 24) is the instance asking the person's primary to warm |
| 12 | // their Assistant now that they opened Base. It is a command like any |
| 13 | // other (durable, acked), and Encode refuses it below 24: an older |
| 14 | // runner's strict decoder would close the stream on it. |
| 15 | func TestEncodeWarmBelow24(t *testing.T) { |
| 16 | if wire.ProtocolWarm != 24 || wire.ProtocolCurrent != wire.ProtocolDesign || wire.Spoken(99) != 38 { |
| 17 | t.Fatalf("protocols %d %d", wire.ProtocolWarm, wire.ProtocolCurrent) |
| 18 | } |
| 19 | f, err := wire.NewFrame("c1", wire.FrameWarm, wire.WarmCommand{Person: "ana@example.com"}) |
| 20 | if err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | if !f.Durable() { |
| 24 | t.Fatal("a warm command is not durable") |
| 25 | } |
| 26 | body, err := f.Decode() |
| 27 | if w, ok := body.(*wire.WarmCommand); err != nil || !ok || w.Person != "ana@example.com" { |
| 28 | t.Fatalf("decode %+v %v", body, err) |
| 29 | } |
| 30 | if _, err := (wire.Frame{ID: "c2", Type: wire.FrameWarm, Data: json.RawMessage(`{"person":"a","more":1}`)}).Decode(); err == nil { |
| 31 | t.Fatal("an unknown warm field decoded") |
| 32 | } |
| 33 | for _, p := range []int{wire.Protocol1, wire.Protocol2, wire.ProtocolAssistant, wire.ProtocolJobs, wire.ProtocolGlance} { |
| 34 | if _, err := wire.Encode(f, p); !errors.Is(err, wire.ErrProtocol) { |
| 35 | t.Fatalf("a warm encoded at protocol %d: %v", p, err) |
| 36 | } |
| 37 | } |
| 38 | if got, err := wire.Encode(f, wire.ProtocolWarm); err != nil || string(got.Data) != string(f.Data) { |
| 39 | t.Fatalf("at 24 %s %v", got.Data, err) |
| 40 | } |
| 41 | } |
| 42 | |