klink_test.go 742 B

123456789101112131415161718192021222324252627282930313233343536
  1. package klink
  2. import (
  3. "github.com/gogf/gf/encoding/gjson"
  4. "github.com/stretchr/testify/assert"
  5. "testing"
  6. )
  7. func TestDevSend_Marshal(t *testing.T) {
  8. d := &DevSend{
  9. Action: "devSend",
  10. MsgId: 0,
  11. DeviceCode: "11111",
  12. Data: &DevSendData{
  13. Cmd: "powerOn",
  14. Params: gjson.New(`{}`),
  15. },
  16. }
  17. b, err := d.Marshal()
  18. if err != nil {
  19. t.Fatal(err)
  20. }
  21. newD := &DevSend{}
  22. err = newD.UnMarshal(b)
  23. if err != nil {
  24. t.Fatal(err)
  25. }
  26. assert.Equal(t, d.Action, newD.Action)
  27. }
  28. func TestDevSend_UnMarshal(t *testing.T) {
  29. j := gjson.New(`{"action":"devSend","data":{"cmd":"powerOn","params":{"power":1}},"deviceCode":"5566","msgId":1,"timestamp":1662432310}`)
  30. params := j.GetJson("data")
  31. t.Log(params.GetMap("params"))
  32. }