github.com/cayleygraph/cayley@v0.7.7/graph/sql/postgres/postgres_test.go (about)

     1  // +build docker
     2  
     3  package postgres
     4  
     5  import (
     6  	"testing"
     7  
     8  	"github.com/cayleygraph/cayley/graph"
     9  	"github.com/cayleygraph/cayley/graph/sql/sqltest"
    10  	"github.com/cayleygraph/cayley/internal/dock"
    11  	"github.com/lib/pq"
    12  )
    13  
    14  func makePostgres(t testing.TB) (string, graph.Options, func()) {
    15  	var conf dock.Config
    16  
    17  	conf.Image = "postgres:9.5"
    18  	conf.OpenStdin = true
    19  	conf.Tty = true
    20  	conf.Env = []string{`POSTGRES_PASSWORD=postgres`}
    21  
    22  	addr, closer := dock.RunAndWait(t, conf, "5432", func(addr string) bool {
    23  		conn, err := pq.Open(`postgres://postgres:postgres@` + addr + `/postgres?sslmode=disable`)
    24  		if err != nil {
    25  			return false
    26  		}
    27  		conn.Close()
    28  		return true
    29  	})
    30  	addr = `postgres://postgres:postgres@` + addr + `/postgres?sslmode=disable`
    31  	return addr, nil, func() {
    32  		closer()
    33  	}
    34  }
    35  
    36  var conf = &sqltest.Config{
    37  	TimeRound: true,
    38  	TimeInMcs: true,
    39  }
    40  
    41  func TestPostgres(t *testing.T) {
    42  	sqltest.TestAll(t, Type, makePostgres, conf)
    43  }
    44  
    45  func BenchmarkPostgres(t *testing.B) {
    46  	sqltest.BenchmarkAll(t, Type, makePostgres, conf)
    47  }