forked from brutella/canopen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
38 lines (31 loc) · 762 Bytes
/
client_test.go
File metadata and controls
38 lines (31 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package canopen
import (
"github.com/brutella/can"
"testing"
"time"
)
var testFrame = can.Frame{
ID: 0xAF,
Length: 0x8,
Flags: 0x0,
Res0: 0x0,
Res1: 0x0,
Data: [can.MaxFrameDataLength]uint8{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8},
}
func TestClientRequestResponse(t *testing.T) {
bus := can.NewBus(can.NewEchoReadWriteCloser())
go bus.ConnectAndPublish()
defer bus.Disconnect()
req := NewRequest(CANopenFrame(testFrame), testFrame.ID)
c := &Client{bus, time.Second * 1}
resp, err := c.Do(req)
if err != nil {
t.Fatal(err)
}
if is, want := resp.Frame.CANFrame().ID, testFrame.ID; is != want {
t.Fatalf("is=%v want=%v", is, want)
}
if is, want := resp.Request, req; is != want {
t.Fatalf("is=%v want=%v", is, want)
}
}