package envitem import ( "encoding/json" "testing" ) func TestEnvItem_GetCurrentData(t *testing.T) { SetOptions(Options{GtServerIp: "47.96.12.136:8788"}) e := EnvItem{ ProjectId: 92, Item: "C.M.LT_CIP@out,C.M.RO1_DB@time_CS_display", } v, ht, err := e.getCurrentValue() t.Log(v, ht, err) } func TestMultiEnvItem_FillCurrentValue(t *testing.T) { SetOptions(Options{GtServerIp: "47.96.12.136:8788"}) m := make(MultiEnvItem, 2) m["C.M.LT_CIP@out"] = &EnvItem{ ProjectId: 92, Item: "C.M.LT_CIP@out", } m["C.M.RO1_DB@time_CS_display"] = &EnvItem{ ProjectId: 92, Item: "C.M.RO1_DB@time_CS_display", } err := m.FillCurrentValue() t.Log(err) for s, item := range m { t.Logf("item: %s value: %s htime: %s", s, item.Value, item.Htime) } } func TestMultiEnvItem_FillCurrentValue2(t *testing.T) { SetOptions(Options{GtServerIp: "47.96.12.136:8788"}) 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"}}` var multiEnvItems MultiEnvItem json.Unmarshal([]byte(js), &multiEnvItems) t.Log(multiEnvItems) err := multiEnvItems.FillCurrentValue() t.Log(err) for s, item := range multiEnvItems { t.Logf("item: %s value: %s htime: %s", s, item.Value, item.Htime) } }