]> git.giacomolli.uk - onehouse/blob - driver/transport_helper_test.go
Exchange bounded Alamo gateway requests
[onehouse] / driver / transport_helper_test.go
1 package driver
2
3 import (
4 "context"
5 "sync"
6
7 "onehouse/protocol"
8 )
9
10 const (
11 testDeviceID = "01K2K7M5TZ3J7W4Q9X8N6P2RVA"
12 testOtherDeviceID = "01K2K7M5TZ3J7W4Q9X8N6P2RVB"
13 testCommandID = "01K2K7M5TZ3J7W4Q9X8N6P2RVF"
14 )
15
16 type recordingTransport struct {
17 mu sync.Mutex
18 publications []protocol.Publication
19 err error
20 }
21
22 func (p *recordingTransport) Publish(_ context.Context, publication protocol.Publication) error {
23 p.mu.Lock()
24 defer p.mu.Unlock()
25
26 p.publications = append(p.publications, publication)
27
28 return p.err
29 }
30
31 func (p *recordingTransport) messages() []protocol.Publication {
32 p.mu.Lock()
33 defer p.mu.Unlock()
34
35 return append([]protocol.Publication(nil), p.publications...)
36 }
37
38 func (p *recordingTransport) setError(err error) {
39 p.mu.Lock()
40 defer p.mu.Unlock()
41
42 p.err = err
43 }