Пример #1
0
func builder() (db.Backend, apperror.Error) {
	return sql.New("postgres", "postgres://@localhost:10001/test?sslmode=disable")
}
Пример #2
0
		"10001",

		"-c",
		"unix_socket_directories=" + tmpDir,
	}
	fmt.Printf("Starting postgres server\n")
	serverCmd = exec.Command("postgres", args...)

	err = serverCmd.Start()
	Expect(err).NotTo(HaveOccurred())

	// Give the server some time to start.
	time.Sleep(time.Second * 3)

	fmt.Printf("Connecting to postgres database\n")
	backend, err := sql.New("postgres", "postgres://@localhost:10001/postgres?sslmode=disable")
	//backend, err := sql.New("postgres", "postgres://*****:*****@localhost/test")
	Expect(err).ToNot(HaveOccurred())
	Expect(backend).ToNot(BeNil())

	fmt.Println("Creating test database.")
	_, err = backend.SqlExec("CREATE DATABASE test")
	Expect(err).ToNot(HaveOccurred())

	setupFailed = false
})

var _ = AfterSuite(func() {
	if serverCmd != nil {
		serverCmd.Process.Kill()
	}
Пример #3
0
	Expect(err).ToNot(HaveOccurred())

	args := []string{
		"--datadir=" + tmpDir,
		"--port=10002",
		"--pid-file=" + path.Join(tmpDir, "mysql.pid"),
		"--socket=" + path.Join(tmpDir, "mysql.sock"),
	}
	fmt.Printf("Starting mysql server\n")
	serverCmd = exec.Command("mysqld", args...)

	err = serverCmd.Start()
	Expect(err).NotTo(HaveOccurred())

	// Give the server some time to start.
	time.Sleep(time.Second * 5)

	fmt.Printf("Connecting to test database\n")
	backend, err := sql.New("mysql", "root@tcp(127.0.0.1:10002)/?charset=utf8&parseTime=True&loc=Local")
	Expect(err).ToNot(HaveOccurred())
	Expect(backend).ToNot(BeNil())

	_, err = backend.SqlExec("CREATE DATABASE test")
	Expect(err).ToNot(HaveOccurred())
})

var _ = AfterSuite(func() {
	serverCmd.Process.Kill()
	os.RemoveAll(tmpDir)
})