1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00

protoio: Add a generic protobuf store

This patch adds a generic protobuf store, where one can put and retreive
protobufs, indexed by a string.

This will be used in subsequent patches.
This commit is contained in:
Alberto Bertogli
2016-10-09 19:08:24 +01:00
parent cf36003e3a
commit aa0486b54e
2 changed files with 99 additions and 0 deletions

View File

@@ -65,3 +65,41 @@ func TestText(t *testing.T) {
os.RemoveAll(dir)
}
}
func TestStore(t *testing.T) {
dir := mustTempDir(t)
st, err := NewStore(dir + "/store")
if err != nil {
t.Fatalf("failed to create store: %v", err)
}
if ids, err := st.ListIDs(); len(ids) != 0 || err != nil {
t.Errorf("expected no ids, got %v - %v", ids, err)
}
pb := &testpb.M{"hola"}
if err := st.Put("f", pb); err != nil {
t.Error(err)
}
pb2 := &testpb.M{}
if ok, err := st.Get("f", pb2); err != nil || !ok {
t.Errorf("Get(f): %v - %v", ok, err)
}
if pb.Content != pb2.Content {
t.Errorf("content mismatch, got %q, expected %q", pb2.Content, pb.Content)
}
if ok, err := st.Get("notexists", pb2); err != nil || ok {
t.Errorf("Get(notexists): %v - %v", ok, err)
}
if ids, err := st.ListIDs(); len(ids) != 1 || ids[0] != "f" || err != nil {
t.Errorf("expected [f], got %v - %v", ids, err)
}
if !t.Failed() {
os.RemoveAll(dir)
}
}