-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_test.go
More file actions
43 lines (31 loc) · 1.24 KB
/
Copy pathcommand_test.go
File metadata and controls
43 lines (31 loc) · 1.24 KB
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
39
40
41
42
43
package message_test
import (
"testing"
message "github.com/iij/legs-message"
"github.com/stretchr/testify/assert"
)
func TestNewCommandMessage(t *testing.T) {
msg := message.NewCommand("cm-id", "device-id", message.CommandExecutingStatus, "result", "command")
b, err := message.Marshal(msg)
assert.Nil(t, err)
parsed := &message.Command{}
err = message.Unmarshal(b, parsed)
assert.Nil(t, err)
assert.Equal(t, "execute", parsed.MessageType)
assert.Equal(t, "command", parsed.Model)
assert.Equal(t, "cm-id", parsed.Data.ID)
assert.Equal(t, "device-id", parsed.Data.DeviceID)
assert.Equal(t, "executing", string(parsed.Data.Status))
assert.Equal(t, "result", parsed.Data.Result)
assert.Equal(t, "command", parsed.Data.Command)
}
func TestCommand_SetStatus(t *testing.T) {
msg := message.NewCommand("cm-id", "device-id", message.CommandExecutingStatus, "result", "command")
msg.SetStatus(message.CommandExecutedStatus)
assert.Equal(t, "executed", string(msg.(*message.Command).Data.Status))
}
func TestCommand_SetResult(t *testing.T) {
msg := message.NewCommand("cm-id", "device-id", message.CommandExecutingStatus, "result", "command")
msg.SetResult("test result")
assert.Equal(t, "test result", msg.(*message.Command).Data.Result)
}