Try to run pg tests on windows

This commit is contained in:
Dan Sosedoff
2015-01-13 21:32:47 -06:00
parent 076c40e624
commit 573737a9ae

View File

@@ -4,22 +4,38 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"runtime"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
var testClient *Client var testClient *Client
var testCommands map[string]string
func setupCommands() {
testCommands = map[string]string{
"createdb": "createdb",
"psql": "psql",
"dropdb": "dropdb",
}
if runtime.GOOS == "windows" {
for k, v := range testCommands {
testCommands[k] = v + ".exec"
}
}
}
func setup() { func setup() {
out, err := exec.Command("createdb", "-U", "postgres", "-h", "localhost", "booktown").CombinedOutput() out, err := exec.Command(testCommands["createdb"], "-U", "postgres", "-h", "localhost", "booktown").CombinedOutput()
if err != nil { if err != nil {
fmt.Print("Database creation failed:", string(out)) fmt.Print("Database creation failed:", string(out))
os.Exit(1) os.Exit(1)
} }
out, err = exec.Command("psql", "-U", "postgres", "-h", "localhost", "-f", "./sql/booktown.sql", "booktown").CombinedOutput() out, err = exec.Command(testCommands["psql"], "-U", "postgres", "-h", "localhost", "-f", "./sql/booktown.sql", "booktown").CombinedOutput()
if err != nil { if err != nil {
fmt.Print("Database import failed:", string(out)) fmt.Print("Database import failed:", string(out))
@@ -38,7 +54,7 @@ func teardownClient() {
} }
func teardown() { func teardown() {
out, err := exec.Command("dropdb", "-U", "postgres", "-h", "localhost", "booktown").CombinedOutput() out, err := exec.Command(testCommands["dropdb"], "-U", "postgres", "-h", "localhost", "booktown").CombinedOutput()
if err != nil { if err != nil {
fmt.Print(string(out)) fmt.Print(string(out))
@@ -202,6 +218,7 @@ func test_HistoryError(t *testing.T) {
} }
func TestAll(t *testing.T) { func TestAll(t *testing.T) {
setupCommands()
teardown() teardown()
setup() setup()
setupClient() setupClient()