go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

pg_test.go (1311B)


      1 package postgres
      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 TestCasesPg(t *testing.T) {
     13 	ctx := context.Background()
     14 
     15 	store := NewPgDb().WithSchema("vvise")
     16 	t.Skip("need postgresql mock")
     17 
     18 	err := store.Connect(ctx, "postgres://vise:esiv@localhost:5432/visedb")
     19 	if err != nil {
     20 		t.Fatal(err)
     21 	}
     22 
     23 	err = dbtest.RunTests(t, ctx, store)
     24 	if err != nil {
     25 		t.Fatal(err)
     26 	}
     27 }
     28 
     29 func TestPutGetPg(t *testing.T) {
     30 	var dbi db.Db
     31 	ses := "xyzzy"
     32 	store := NewPgDb().WithSchema("vvise")
     33 	store.SetPrefix(db.DATATYPE_USERDATA)
     34 	store.SetSession(ses)
     35 	ctx := context.Background()
     36 
     37 	dbi = store 
     38 	_ = dbi
     39 
     40 	t.Skip("need postgresql mock")
     41 	err := store.Connect(ctx, "postgres://vise:esiv@localhost:5432/visedb")
     42 	if err != nil {
     43 		t.Fatal(err)
     44 	}
     45 	err = store.Put(ctx, []byte("foo"), []byte("bar"))
     46 	if err != nil {
     47 		t.Fatal(err)
     48 	}
     49 	b, err := store.Get(ctx, []byte("foo"))
     50 	if err != nil {
     51 		t.Fatal(err)
     52 	}
     53 	if !bytes.Equal(b, []byte("bar")) {
     54 		t.Fatalf("expected 'bar', got %x", b)
     55 	}
     56 	err = store.Put(ctx, []byte("foo"), []byte("plugh"))
     57 	if err != nil {
     58 		t.Fatal(err)
     59 	}
     60 	b, err = store.Get(ctx, []byte("foo"))
     61 	if err != nil {
     62 		t.Fatal(err)
     63 	}
     64 	if !bytes.Equal(b, []byte("plugh")) {
     65 		t.Fatalf("expected 'plugh', got %x", b)
     66 	}
     67 
     68 }