MCPcopy
hub / github.com/perkeep/perkeep / TestSorted

Function TestSorted

pkg/sorted/kvtest/kvtest.go:29–88  ·  view source on GitHub ↗
(t *testing.T, kv sorted.KeyValue)

Source from the content-addressed store, hash-verified

27)
28
29func TestSorted(t *testing.T, kv sorted.KeyValue) {
30 defer test.TLog(t)()
31 if !isEmpty(t, kv) {
32 t.Fatal("kv for test is expected to be initially empty")
33 }
34 set := func(k, v string) {
35 if err := kv.Set(k, v); err != nil {
36 t.Fatalf("Error setting %q to %q: %v", k, v, err)
37 }
38 }
39 set("foo", "bar")
40 if isEmpty(t, kv) {
41 t.Fatalf("iterator reports the kv is empty after adding foo=bar; iterator must be broken")
42 }
43 if v, err := kv.Get("foo"); err != nil || v != "bar" {
44 t.Errorf("get(foo) = %q, %v; want bar", v, err)
45 }
46 if v, err := kv.Get("NOT_EXIST"); err != sorted.ErrNotFound {
47 t.Errorf("get(NOT_EXIST) = %q, %v; want error sorted.ErrNotFound", v, err)
48 }
49 for i := 0; i < 2; i++ {
50 if err := kv.Delete("foo"); err != nil {
51 t.Errorf("Delete(foo) (on loop %d/2) returned error %v", i+1, err)
52 }
53 }
54 set("a", "av")
55 set("b", "bv")
56 set("c", "cv")
57 testEnumerate(t, kv, "", "", "av", "bv", "cv")
58 testEnumerate(t, kv, "a", "", "av", "bv", "cv")
59 testEnumerate(t, kv, "b", "", "bv", "cv")
60 testEnumerate(t, kv, "a", "c", "av", "bv")
61 testEnumerate(t, kv, "a", "b", "av")
62 testEnumerate(t, kv, "a", "a")
63 testEnumerate(t, kv, "d", "")
64 testEnumerate(t, kv, "d", "e")
65
66 // Verify that < comparison works identically for all DBs (because it is affected by collation rules)
67 // http://postgresql.1045698.n5.nabble.com/String-comparison-and-the-SQL-standard-td5740721.html
68 set("foo|abc", "foo|abcv")
69 testEnumerate(t, kv, "foo|", "", "foo|abcv")
70 testEnumerate(t, kv, "foo|", "foo}", "foo|abcv")
71
72 // Verify that the value isn't being used instead of the key in the range comparison.
73 set("y", "x:foo")
74 testEnumerate(t, kv, "x:", "x~")
75
76 testInsertLarge(t, kv)
77 testInsertTooLarge(t, kv)
78
79 // TODO: test batch commits
80
81 // Deleting a non-existent item in a batch should not be an error
82 testDeleteNotFoundBatch(t, kv)
83 testDeletePartialNotFoundBatch(t, kv)
84
85 if txReader, ok := kv.(sorted.TransactionalReader); ok {
86 testReadTransaction(t, txReader)

Callers 13

TestMemoryKVFunction · 0.92
TestKvfileKVFunction · 0.92
TestPostgreSQLKVFunction · 0.92
TestMongoKVFunction · 0.92
TestMySQLKVFunction · 0.92
TestSQLiteKVFunction · 0.92
TestLeveldbKVFunction · 0.92
TestSorted_MySQLFunction · 0.92
TestSorted_KvfileFunction · 0.92
TestSorted_MongoFunction · 0.92
TestSorted_PostgresFunction · 0.92
TestSorted_LevelDBFunction · 0.92

Calls 13

TLogFunction · 0.92
isEmptyFunction · 0.85
testEnumerateFunction · 0.85
testInsertLargeFunction · 0.85
testInsertTooLargeFunction · 0.85
testDeleteNotFoundBatchFunction · 0.85
testReadTransactionFunction · 0.85
FatalMethod · 0.80
SetMethod · 0.65
FatalfMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected