func TestReadNSRecursive(t *testing.T) { _parentKey, _key, _childKey := "abc", "abc:name", "abc:name:last" expectedParentKeyVal := "abc:name,ABC XYZ\nabc:name:first,ABC\nabc:name:last,XYZ" expectedKeyVal := "abc:name,ABC XYZ\nabc:name:first,ABC\nabc:name:last,XYZ" expectedChildKeyVal := "abc:name:last,XYZ" db := abkleveldb.CreateDB(dbpath) setupTestData(db) resultParentKeyVal := golhashmap.HashMapToCSV(ReadNSRecursive(_parentKey, db)) resultKeyVal := golhashmap.HashMapToCSV(ReadNSRecursive(_key, db)) resultChildKeyVal := golhashmap.HashMapToCSV(ReadNSRecursive(_childKey, db)) golassert.AssertEqualStringArray( strings.Split(expectedParentKeyVal, "\n"), strings.Split(resultParentKeyVal, "\n"), ) golassert.AssertEqualStringArray( strings.Split(expectedKeyVal, "\n"), strings.Split(resultKeyVal, "\n"), ) golassert.AssertEqualStringArray( strings.Split(expectedChildKeyVal, "\n"), strings.Split(resultChildKeyVal, "\n"), ) abkleveldb.CloseAndDeleteDB(dbpath, db) }
func TestAppendKey(t *testing.T) { db := abkleveldb.CreateDB(dbpath) status := appendKey("abc:name:first", "title", db) expectedVal := "key::abc:name:first:title" resultVal := abkleveldb.GetVal("key::abc:name:first", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } status = appendKey("abc", "name", db) expectedVal = "key::abc:name" resultVal = abkleveldb.GetVal("key::abc", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } status = appendKey("abc", "age", db) expectedVal = "key::abc:name,key::abc:age" resultVal = abkleveldb.GetVal("key::abc", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } abkleveldb.CloseAndDeleteDB(dbpath, db) }
func TestCreateNS(t *testing.T) { db := abkleveldb.CreateDB(dbpath) status := CreateNS("abc:name:first", db) expectedVal := "key::abc:name:first" resultVal := abkleveldb.GetVal("key::abc:name", db) if expectedVal != resultVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } status = CreateNS("abc:name:last", db) expectedVal = "key::abc:name:first,key::abc:name:last" resultVal = abkleveldb.GetVal("key::abc:name", db) if expectedVal != resultVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } status = CreateNS("abc:name:last", db) expectedVal = "key::abc:name:first,key::abc:name:last" resultVal = abkleveldb.GetVal("key::abc:name", db) if expectedVal != resultVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } abkleveldb.CloseAndDeleteDB(dbpath, db) }
func TestDeleteNSRecursive(t *testing.T) { db := abkleveldb.CreateDB(dbpath) setupTestData(db) status := DeleteNSRecursive("abc", db) expectedVal := "" resultVal := abkleveldb.GetVal("key::abc", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } expectedVal = "" resultVal = abkleveldb.GetVal("key::abc:name", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } expectedVal = "" resultVal = abkleveldb.GetVal("val::abc:name:first", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } expectedVal = "" resultVal = abkleveldb.GetVal("val::abc:name:last", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } abkleveldb.CloseAndDeleteDB(dbpath, db) }
func TestDeleteNSKey(t *testing.T) { db := abkleveldb.CreateDB(dbpath) setupTestData(db) status := DeleteNSKey("abc:name:last", db) expectedVal := "" resultVal := abkleveldb.GetVal("val::abc:name:last", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } expectedVal = "ABC" resultVal = abkleveldb.GetVal("val::abc:name:first", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } status = DeleteNSKey("abc:name:last", db) if !status { t.Error("Fail: Success in deleting non-existent key.") } abkleveldb.CloseAndDeleteDB(dbpath, db) }
func TestReadKey(t *testing.T) { setupTestData() expected_val := "upstate:2014:January:2:12:1:20,down" result_val := golhashmap.HashMapToCSV(ReadKey("upstate:2014:January:2:12:1:20")) golassert.AssertEqual(expected_val, result_val) abkleveldb.CloseAndDeleteDB(test_dbpath, db) }
func TestGetVal(t *testing.T) { setupTestData() expected_val := "down" result_val := GetVal("upstate:2014:January:2:12:1:20") if expected_val != result_val { t.Error("Fail: Get", result_val, "instead of", expected_val) } abkleveldb.CloseAndDeleteDB(test_dbpath, db) }
func TestDelKeyNS(t *testing.T) { setupTestData() status := DelKeyNS("upstate:2014") expected_val := "" result_val := abkleveldb.GetVal("val::upstate:2014:January:2:12:1:20", db) if expected_val != result_val { t.Error("Fail: Get", result_val, "instead of", expected_val) } if !status { t.Error("Fail: Wrong status returned by DelKeyNS") } abkleveldb.CloseAndDeleteDB(test_dbpath, db) }
func TestPushKeyValNS(t *testing.T) { setupTestData() expected_val := "right" status := PushKeyValNS("oh:yeah", expected_val) result_val := abkleveldb.GetVal("val::oh:yeah", db) if expected_val != result_val { t.Error("Fail: Get", result_val, "instead of", expected_val) } if !status { t.Error("Fail: Wrong status returned by PushKeyValNS") } abkleveldb.CloseAndDeleteDB(test_dbpath, db) }
func TestPushKeyValTSDS(t *testing.T) { setupTestData() ohtime := goltime.Timestamp{ Year: 2014, Month: 1, Day: 2, Hour: 12, Min: 1, Sec: 20, } status := PushKeyValTSDS("oh", "yeah", ohtime) expected_val := "yeah" result_val := abkleveldb.GetVal("val::oh:2014:January:2:12:1:20", db) if expected_val != result_val { t.Error("Fail: Get", result_val, "instead of", expected_val) } if !status { t.Error("Fail: Wrong status returned by PushKeyValTSDS") } abkleveldb.CloseAndDeleteDB(test_dbpath, db) }
func TestDeleteNSChildren(t *testing.T) { db := abkleveldb.CreateDB(dbpath) setupTestData(db) expectedVal := "ABC XYZ" resultVal := abkleveldb.GetVal("val::abc:name", db) if resultVal != expectedVal { t.Error("Fail: Pre-req is bad.") } status := deleteNSChildren("key::abc:name", db) expectedVal = "" resultVal = abkleveldb.GetVal("val::abc:name", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } expectedVal = "" resultVal = abkleveldb.GetVal("key::abc:name", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } expectedVal = "XYZ" resultVal = abkleveldb.GetVal("val::abc:name:last", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } status = deleteNSChildren("key::abc:name:first,key::abc:name:last", db) expectedVal = "" resultVal = abkleveldb.GetVal("val::abc:name:first", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } abkleveldb.CloseAndDeleteDB(dbpath, db) }
func TestPushNS(t *testing.T) { db := abkleveldb.CreateDB(dbpath) status := PushNS("abc:name", "ABC XYZ", db) expectedVal := "ABC XYZ" resultVal := abkleveldb.GetVal("val::abc:name", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } expectedVal = "key::abc:name" resultVal = abkleveldb.GetVal("key::abc", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } abkleveldb.CloseAndDeleteDB(dbpath, db) }
func TestPushKeyValTSDS(t *testing.T) { setupTestData() packet := Packet{} packet.HashMap = make(golhashmap.HashMap) packet.HashMap["oh"] = "yeah" packet.ParentNS = "phrase" packet.TimeDot = goltime.Timestamp{ Year: 2014, Month: 1, Day: 2, Hour: 12, Min: 1, Sec: 20, } packet.KeyType = "tsds" status := PushFromPacket(packet) expected_val := "yeah" result_val := abkleveldb.GetVal("val::oh:2014:January:2:12:1:20", db) golassert.AssertEqual(expected_val, result_val) if !status { t.Error("Fail: Wrong status returned by PushKeyValTSDS") } abkleveldb.CloseAndDeleteDB(test_dbpath, db) }