func_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package envitem
  2. import (
  3. "encoding/json"
  4. "testing"
  5. )
  6. func TestEnvItem_GetCurrentData(t *testing.T) {
  7. SetOptions(Options{GtServerIp: "47.96.12.136:8788"})
  8. e := EnvItem{
  9. ProjectId: 92,
  10. Item: "C.M.LT_CIP@out,C.M.RO1_DB@time_CS_display",
  11. }
  12. v, ht, err := e.getCurrentValue()
  13. t.Log(v, ht, err)
  14. }
  15. func TestMultiEnvItem_FillCurrentValue(t *testing.T) {
  16. SetOptions(Options{GtServerIp: "47.96.12.136:8788"})
  17. m := make(MultiEnvItem, 2)
  18. m["C.M.LT_CIP@out"] = &EnvItem{
  19. ProjectId: 92,
  20. Item: "C.M.LT_CIP@out",
  21. }
  22. m["C.M.RO1_DB@time_CS_display"] = &EnvItem{
  23. ProjectId: 92,
  24. Item: "C.M.RO1_DB@time_CS_display",
  25. }
  26. err := m.FillCurrentValue()
  27. t.Log(err)
  28. for s, item := range m {
  29. t.Logf("item: %s value: %s htime: %s", s, item.Value, item.Htime)
  30. }
  31. }
  32. func TestMultiEnvItem_FillCurrentValue2(t *testing.T) {
  33. SetOptions(Options{GtServerIp: "47.96.12.136:8788"})
  34. js := `{"tmp":{"project_id":92,"item":"C.M.UF2_DB@press_PV"},"feed_flow":{"project_id":92,"item":"C.M.UF2_FT_JS@out"},"feed_pressure":{"project_id":92,"item":"C.M.UF2_PT_JS@out"},"product_pressure":{"project_id":92,"item":"C.M.UF2_PT_CS@out"},"feed_wq_turbidity":{"project_id":92,"item":"C.M.UF_Tur_ZJS@out"},"water_temperature":{"project_id":92,"item":"C.M.RO_TT_ZJS@out"},"product_wq_ph":{"project_id":92,"item":"C.M.UF_PH_ZCS@out"}}`
  35. var multiEnvItems MultiEnvItem
  36. json.Unmarshal([]byte(js), &multiEnvItems)
  37. t.Log(multiEnvItems)
  38. err := multiEnvItems.FillCurrentValue()
  39. t.Log(err)
  40. for s, item := range multiEnvItems {
  41. t.Logf("item: %s value: %s htime: %s", s, item.Value, item.Htime)
  42. }
  43. }