-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_test.go
More file actions
38 lines (35 loc) · 882 Bytes
/
command_test.go
File metadata and controls
38 lines (35 loc) · 882 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 gerte
import "testing"
func TestCommandFromBytes(t *testing.T) {
cmd := []byte{byte(CommandState), byte(StateConnected)}
command := Command{
Command: CommandState,
Packet: Packet{},
Status: Status{
Status: StateConnected,
Size: 4,
Version: Version{
Major: 1,
Minor: 1,
Patch: 0,
},
},
}
verByte := Version{
Major: 1,
Minor: 1,
Patch: 0,
}.ToBytes()
cmd = append(cmd, verByte[0], verByte[1])
command2, err := CommandFromBytes(cmd)
if err != nil {
t.Errorf("error on unmarshal command: %+v", err)
}
if command.Command != command2.Command ||
string(command.Packet.Data) != string(command2.Packet.Data) ||
command.Packet.Target != command2.Packet.Target ||
command.Packet.Source != command2.Packet.Source ||
command.Status != command2.Status {
t.Errorf("commands don't match:\n%+v\n%+v", command, command2)
}
}