properly cleanup after tests (drop schema, rm cache)

master
Oliver Tonnhofer 2016-06-15 14:26:50 +02:00
parent 1a18adc6d0
commit 07a8726169
4 changed files with 60 additions and 8 deletions

View File

@ -2,6 +2,8 @@ package test
import (
"database/sql"
"io/ioutil"
"os"
"testing"
@ -9,7 +11,12 @@ import (
)
func TestAnyAny_Prepare(t *testing.T) {
ts.dir = "/tmp/imposm3test"
var err error
ts.dir, err = ioutil.TempDir("", "imposm3test")
if err != nil {
t.Fatal(err)
}
ts.config = importConfig{
connection: "postgis://",
cacheDir: ts.dir,
@ -18,7 +25,6 @@ func TestAnyAny_Prepare(t *testing.T) {
}
ts.g = geos.NewGeos()
var err error
ts.db, err = sql.Open("postgres", "sslmode=disable")
if err != nil {
t.Fatal(err)
@ -47,3 +53,10 @@ func TestAnyAny_InsertedNodes(t *testing.T) {
{"osm_amenities", 10003, "*", map[string]string{"random": "tag", "but": "mapped", "amenity": "shop"}},
})
}
func TestAnyAny_Cleanup(t *testing.T) {
ts.dropSchemas()
if err := os.RemoveAll(ts.dir); err != nil {
t.Error(err)
}
}

View File

@ -3,6 +3,8 @@ package test
import (
"database/sql"
"fmt"
"io/ioutil"
"os"
"github.com/omniscale/imposm3/cache"
@ -18,7 +20,12 @@ import (
var ts importTestSuite
func TestPrepare(t *testing.T) {
ts.dir = "/tmp/imposm3test"
var err error
ts.dir, err = ioutil.TempDir("", "imposm3test")
if err != nil {
t.Fatal(err)
}
ts.config = importConfig{
connection: "postgis://",
cacheDir: ts.dir,
@ -27,7 +34,6 @@ func TestPrepare(t *testing.T) {
}
ts.g = geos.NewGeos()
var err error
ts.db, err = sql.Open("postgres", "sslmode=disable")
if err != nil {
t.Fatal(err)
@ -738,3 +744,10 @@ func TestRemoveBackup(t *testing.T) {
t.Fatalf("table osm_roads exists in schema %s", dbschemaBackup)
}
}
func TestCleanup(t *testing.T) {
ts.dropSchemas()
if err := os.RemoveAll(ts.dir); err != nil {
t.Error(err)
}
}

View File

@ -2,14 +2,21 @@ package test
import (
"database/sql"
"io/ioutil"
"math"
"os"
"testing"
"github.com/omniscale/imposm3/geom/geos"
)
func TestRouteRelation_Prepare(t *testing.T) {
ts.dir = "/tmp/imposm3test"
var err error
ts.dir, err = ioutil.TempDir("", "imposm3test")
if err != nil {
t.Fatal(err)
}
ts.config = importConfig{
connection: "postgis://",
cacheDir: ts.dir,
@ -18,7 +25,6 @@ func TestRouteRelation_Prepare(t *testing.T) {
}
ts.g = geos.NewGeos()
var err error
ts.db, err = sql.Open("postgres", "sslmode=disable")
if err != nil {
t.Fatal(err)
@ -135,3 +141,10 @@ func TestRouteRelation_MemberUpdatedByNode(t *testing.T) {
t.Error(rows[0])
}
}
func TestRouteRelation_Cleanup(t *testing.T) {
ts.dropSchemas()
if err := os.RemoveAll(ts.dir); err != nil {
t.Error(err)
}
}

View File

@ -2,6 +2,8 @@ package test
import (
"database/sql"
"io/ioutil"
"os"
"strings"
"testing"
@ -12,7 +14,12 @@ import (
const RelOffset = -1e17
func TestSingleTable_Prepare(t *testing.T) {
ts.dir = "/tmp/imposm3test"
var err error
ts.dir, err = ioutil.TempDir("", "imposm3test")
if err != nil {
t.Fatal(err)
}
ts.config = importConfig{
connection: "postgis://",
cacheDir: ts.dir,
@ -21,7 +28,6 @@ func TestSingleTable_Prepare(t *testing.T) {
}
ts.g = geos.NewGeos()
var err error
ts.db, err = sql.Open("postgres", "sslmode=disable")
if err != nil {
t.Fatal(err)
@ -192,3 +198,10 @@ func TestSingleTable_ModifiedRelation2(t *testing.T) {
t.Errorf("found duplicate row: %v", rows)
}
}
func TestSingleTable_Cleanup(t *testing.T) {
ts.dropSchemas()
if err := os.RemoveAll(ts.dir); err != nil {
t.Error(err)
}
}