func newFromConfig(ld blobserver.Loader, config jsonconfig.Obj) (blobserver.Storage, error) { blobPrefix := config.RequiredString("blobSource") postgresConf, err := postgres.ConfigFromJSON(config) if err != nil { return nil, err } kv, err := postgres.NewKeyValue(postgresConf) if err != nil { return nil, err } ix, err := index.New(kv) if err != nil { return nil, err } sto, err := ld.GetStorage(blobPrefix) if err != nil { ix.Close() return nil, err } ix.BlobSource = sto // Good enough, for now: ix.KeyFetcher = ix.BlobSource return ix, nil }
func newSorted(t *testing.T) (kv sorted.KeyValue, clean func()) { skipOrFailIfNoPostgreSQL(t) dbname := "camlitest_" + osutil.Username() if err := closeAllSessions(postgres.Config{ User: "******", Password: "******", SSLMode: "require", Database: dbname, Host: "localhost", }); err != nil { t.Fatalf("Could not close all old sessions to %q: %v", dbname, err) } do(rootdb, "DROP DATABASE IF EXISTS "+dbname) do(rootdb, "CREATE DATABASE "+dbname+" LC_COLLATE = 'C' TEMPLATE = template0") testdb, err := sql.Open("postgres", "user=postgres password=postgres host=localhost sslmode=require dbname="+dbname) if err != nil { t.Fatalf("opening test database: " + err.Error()) } for _, tableSql := range postgres.SQLCreateTables() { do(testdb, tableSql) } for _, statement := range postgres.SQLDefineReplace() { do(testdb, statement) } doQuery(testdb, fmt.Sprintf(`SELECT replaceintometa('version', '%d')`, postgres.SchemaVersion())) kv, err = postgres.NewKeyValue(postgres.Config{ Host: "localhost", Database: dbname, User: "******", Password: "******", SSLMode: "require", }) if err != nil { t.Fatal(err) } return kv, func() { kv.Close() } }