func TestUpdater(t *testing.T) { orig_data := make(map[string]interface{}) orig_data["key_a"] = "value_a" orig_data["key_100"] = 100 sm := SMI.NewWithData(orig_data) defer sm.Close() sm.Update("key_100", func(value interface{}, found bool) interface{} { if found { return value.(int) * 2 } return 1 }) ret, found := sm.Find("key_100") if !found { t.Errorf("fetch key:%s failed", "key_100") return } if ret_value, ok := ret.(int); !ok || ret_value != 100*2 { t.Errorf("fetch key:%s and cmp failed", "key_100") } }
func TestInitialWithData(t *testing.T) { orig_data := make(map[string]interface{}) orig_data["key_a"] = "value_a" orig_data["key_100"] = 100 sm := SMI.NewWithData(orig_data) defer sm.Close() ret, found := sm.Find("key_a") if found != true { t.Errorf("fetch key:%s failed", "key_a") return } if ret_value, ok := ret.(string); !ok || ret_value != "value_a" { t.Errorf("fetch key:%s and cmp failed", "key_a") } ret, found = sm.Find("key_100") if found != true { t.Errorf("fetch key:%s failed", "key_100") return } if ret_value, ok := ret.(int); !ok || ret_value != 100 { t.Errorf("fetch key:%s and cmp failed", "key_100") } }
func TestLen(t *testing.T) { orig_data := make(map[string]interface{}) orig_data["key_a"] = "value_a" orig_data["key_100"] = 100 sm := SMI.NewWithData(orig_data) defer sm.Close() sm_len := sm.Len() if sm_len != len(orig_data) { t.Errorf("fetch sm len failed, ret:%d, should:%d", sm_len, len(orig_data)) } }