Skip to content

Commit

Permalink
Improved Pg test matrix (#616)
Browse files Browse the repository at this point in the history
* Add postgres 10/11 to test  matrix
* Add docker-compose file fo running multiple postgres versions locally
* Fix client test for pg 10, modify function details to include specific fields
* Try to install latest postgres client
* Add concurrency setting
  • Loading branch information
sosedoff authored Dec 13, 2022
1 parent 4c40eef commit 0dfec50
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 11 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ env:
GO_VERSION: 1.19
CGO_ENABLED: 0

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
name: tests
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
pg_version: [12, 13, 14]
pg_version: [9.6, 10, 11, 12, 13, 14, 15]

services:
postgres:
Expand All @@ -32,6 +36,13 @@ jobs:
--health-timeout 5s
--health-retries 5
steps:
- name: Install latest Postgres client
run: |
sudo rm -f /etc/apt/sources.list.d/pgdg.list
curl --silent https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt-get update && sudo apt-get install -y postgresql-client-15
- uses: actions/checkout@v3
with:
fetch-depth: 0
Expand Down
4 changes: 2 additions & 2 deletions data/booktown.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
DROP DATABASE IF EXISTS "booktown";
CREATE DATABASE "booktown";

\connect booktown postgres
-- \connect booktown postgres
--
-- TOC Entry ID 2 (OID 2991542)
--
Expand Down Expand Up @@ -1293,7 +1293,7 @@ CREATE VIEW "recent_shipments" as SELECT count(*) AS num_shipped, max(shipments.


COPY "publishers" FROM stdin;
150 Kids Can Press Kids Can Press, 29 Birch Ave. Toronto, ON  M4V 1E2
150 Kids Can Press Kids Can Press, 29 Birch Ave. Toronto,ON��M4V 1E2
91 Henry Holt & Company, Inc. Henry Holt & Company, Inc. 115 West 18th Street New York, NY 10011
113 O'Reilly & Associates O'Reilly & Associates, Inc. 101 Morris St, Sebastopol, CA 95472
62 Watson-Guptill Publications 1515 Boradway, New York, NY 10036
Expand Down
48 changes: 48 additions & 0 deletions docker-compose-pg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
version: "3.9"

x-base: &base
environment: &env
POSTGRES_DB: pgweb
POSTGRES_PASSWORD: pgweb
POSTGRES_USER: pgweb
healthcheck:
test: pg_isready -U pgweb -h 127.0.0.1
interval: 5s

services:
postgres15:
<<: *base
image: postgres:15
ports:
- 5433:5432
postgres14:
<<: *base
image: postgres:14
ports:
- 5434:5432
postgres13:
<<: *base
image: postgres:13
ports:
- 5435:5432
postgres12:
<<: *base
image: postgres:12
ports:
- 5436:5432
postgres11:
<<: *base
image: postgres:11
ports:
- 5437:5432
postgres10:
<<: *base
image: postgres:10
ports:
- 5438:5432
postgres9.6:
<<: *base
image: postgres:9.6
ports:
- 5439:5432
17 changes: 11 additions & 6 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"
"runtime"
"sort"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -143,7 +144,7 @@ func teardownClient() {
}
}

func teardown() {
func teardown(t *testing.T, allowFail bool) {
output, err := exec.Command(
testCommands["dropdb"],
"-U", serverUser,
Expand All @@ -152,9 +153,13 @@ func teardown() {
serverDatabase,
).CombinedOutput()

if err != nil {
fmt.Println("Teardown error:", err)
fmt.Printf("%s\n", output)
if err != nil && strings.Contains(err.Error(), "does not exist") {
t.Log("Teardown error:", err)
t.Logf("%s\n", output)

if !allowFail {
assert.NoError(t, err)
}
}
}

Expand Down Expand Up @@ -602,7 +607,7 @@ func TestAll(t *testing.T) {

initVars()
setupCommands()
teardown()
teardown(t, false)
setup()
setupClient()

Expand Down Expand Up @@ -632,5 +637,5 @@ func TestAll(t *testing.T) {
testDumpExport(t)

teardownClient()
teardown()
teardown(t, true)
}
5 changes: 4 additions & 1 deletion pkg/statements/sql/function.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
SELECT
p.*,
p.oid,
p.proname,
p.pronamespace,
p.proowner,
pg_get_functiondef(oid) AS functiondef
FROM
pg_catalog.pg_proc p
Expand Down
1 change: 0 additions & 1 deletion pkg/statements/sql/objects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ WITH all_objects AS (
WHERE
n.nspname !~ '^pg_toast'
AND n.nspname NOT IN ('information_schema', 'pg_catalog')
AND p.prokind = 'f'
)
SELECT * FROM all_objects
ORDER BY 1, 2

0 comments on commit 0dfec50

Please sign in to comment.