mem_test.go (985B)
1 package mem 2 3 import ( 4 "bytes" 5 "context" 6 "testing" 7 8 "git.defalsify.org/vise.git/db" 9 "git.defalsify.org/vise.git/db/dbtest" 10 ) 11 12 func TestCasesMem(t *testing.T) { 13 ctx := context.Background() 14 15 store := NewMemDb() 16 err := store.Connect(ctx, "") 17 if err != nil { 18 t.Fatal(err) 19 } 20 21 err = dbtest.RunTests(t, ctx, store) 22 if err != nil { 23 t.Fatal(err) 24 } 25 } 26 27 func TestPutGetMem(t *testing.T) { 28 var dbi db.Db 29 ctx := context.Background() 30 sid := "ses" 31 store := NewMemDb() 32 store.SetPrefix(db.DATATYPE_USERDATA) 33 store.SetSession(sid) 34 35 dbi = store 36 _ = dbi 37 38 err := store.Connect(ctx, "") 39 if err != nil { 40 t.Fatal(err) 41 } 42 err = store.Put(ctx, []byte("foo"), []byte("bar")) 43 if err != nil { 44 t.Fatal(err) 45 } 46 v, err := store.Get(ctx, []byte("foo")) 47 if err != nil { 48 t.Fatal(err) 49 } 50 if !bytes.Equal(v, []byte("bar")) { 51 t.Fatalf("expected value 'bar', found '%s'", v) 52 } 53 _, err = store.Get(ctx, []byte("bar")) 54 if err == nil { 55 t.Fatal("expected get error for key 'bar'") 56 } 57 }