-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from PDOK/create-index-idempotent
feat: make create search index idempotent, it shouldn't fail when it's already there.
- Loading branch information
Showing
2 changed files
with
40 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,7 @@ func TestCreateSearchIndex(t *testing.T) { | |
t.Error(err) | ||
} | ||
defer terminateContainer(ctx, t, postgisContainer) | ||
|
||
dbConn := fmt.Sprintf("postgres://postgres:[email protected]:%d/%s?sslmode=disable", dbPort.Int(), "test_db") | ||
dbConn := makeDbConnection(dbPort) | ||
|
||
// when/then | ||
err = CreateSearchIndex(dbConn, "search_index") | ||
|
@@ -47,6 +46,31 @@ func TestCreateSearchIndex(t *testing.T) { | |
assert.NoError(t, err) | ||
} | ||
|
||
func TestCreateSearchIndexIdempotent(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("Skipping integration test in short mode") | ||
} | ||
ctx := context.Background() | ||
|
||
// given | ||
dbPort, postgisContainer, err := setupPostgis(ctx, t) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
defer terminateContainer(ctx, t, postgisContainer) | ||
dbConn := makeDbConnection(dbPort) | ||
|
||
// when/then | ||
err = CreateSearchIndex(dbConn, "search_index") | ||
assert.NoError(t, err) | ||
err = CreateSearchIndex(dbConn, "search_index") // second time, should not fail | ||
assert.NoError(t, err) | ||
} | ||
|
||
func makeDbConnection(dbPort nat.Port) string { | ||
return fmt.Sprintf("postgres://postgres:[email protected]:%d/%s?sslmode=disable", dbPort.Int(), "test_db") | ||
} | ||
|
||
func TestImportGeoPackage(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("Skipping integration test in short mode") | ||
|
@@ -75,9 +99,7 @@ func TestImportGeoPackage(t *testing.T) { | |
if err != nil { | ||
t.Error(err) | ||
} | ||
defer terminateContainer(ctx, t, postgisContainer) | ||
|
||
dbConn := fmt.Sprintf("postgres://postgres:[email protected]:%d/%s?sslmode=disable", dbPort.Int(), "test_db") | ||
dbConn := makeDbConnection(dbPort) | ||
|
||
cfg, err := config.NewConfig(pwd + "/testdata/config.yaml") | ||
if err != nil { | ||
|
@@ -105,9 +127,11 @@ func TestImportGeoPackage(t *testing.T) { | |
assert.NoError(t, err) | ||
var count int | ||
err = db.QueryRow(ctx, "select count(*) from search_index").Scan(&count) | ||
defer db.Close(ctx) | ||
db.Close(ctx) | ||
assert.NoError(t, err) | ||
assert.Equal(t, tt.count, count) | ||
|
||
terminateContainer(ctx, t, postgisContainer) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters