Skip to content

Commit 24be2e6

Browse files
authored
Work not only in the public schema (#76)
1 parent 56ec015 commit 24be2e6

File tree

12 files changed

+137
-71
lines changed

12 files changed

+137
-71
lines changed

.github/workflows/testing.yml

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: Testing
23

34
on:
@@ -12,9 +13,11 @@ jobs:
1213
runs-on: ubuntu-latest
1314
steps:
1415
- name: Check out code
15-
uses: actions/checkout@v2
16+
uses: actions/checkout@v3
1617
- name: golangci-lint
1718
uses: golangci/golangci-lint-action@v2
19+
with:
20+
only-new-issues: ${{ github.event_name == 'pull_request' }}
1821

1922
go-test:
2023
name: Go ${{ matrix.go }} Test
@@ -23,7 +26,7 @@ jobs:
2326

2427
strategy:
2528
matrix:
26-
go: [ '~1.17', '~1.18' ]
29+
go: [ '1.17', '1.18', '1.19' ]
2730

2831
services:
2932
postgres:
@@ -41,12 +44,13 @@ jobs:
4144
--health-retries 5
4245
4346
steps:
47+
- name: Check out code
48+
uses: actions/checkout@v3
4449
- name: Set up Go
45-
uses: actions/setup-go@v2
50+
uses: actions/setup-go@v3
4651
with:
4752
go-version: ${{ matrix.go }}
48-
- name: Check out code
49-
uses: actions/checkout@v2
53+
5054
- name: Run unit tests
5155
run: make test-unit
5256
- name: Run examples tests
@@ -64,3 +68,41 @@ jobs:
6468
steps:
6569
- name: Done
6670
run: echo "All Golang versions tests are Green!"
71+
72+
test-non-public-schema:
73+
name: Test non-public PG schema
74+
runs-on: ubuntu-latest
75+
needs: [ lint ]
76+
77+
services:
78+
postgres:
79+
image: postgres:10
80+
ports:
81+
- "5432"
82+
env:
83+
POSTGRES_USER: goengine
84+
POSTGRES_PASSWORD: goengine
85+
POSTGRES_DB: goengine
86+
options: >-
87+
--health-cmd pg_isready
88+
--health-interval 10s
89+
--health-timeout 5s
90+
--health-retries 5
91+
92+
steps:
93+
- name: Check out code
94+
uses: actions/checkout@v3
95+
- name: Set up Go
96+
uses: actions/setup-go@v3
97+
with:
98+
go-version-file: ./go.mod
99+
100+
- name: Run unit tests
101+
run: make test-unit
102+
- name: Run examples tests
103+
run: make test-examples
104+
- name: Run integration tests
105+
run: make test-integration
106+
env:
107+
# integration tests suite creates new DB per test run and initialises schema as well
108+
POSTGRES_DSN: 'postgres://goengine:goengine@localhost:${{ job.services.postgres.ports[5432] }}/goengine?sslmode=disable&search_path=custom'

driver/sql/postgres/eventstore.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,21 @@ func (e *EventStore) tableName(s goengine.StreamName) (string, error) {
281281
}
282282

283283
func (e *EventStore) tableExists(ctx context.Context, tableName string) bool {
284+
var currentSchema string
285+
if err := e.db.QueryRowContext(ctx, `select current_schema()`).Scan(&currentSchema); err != nil {
286+
e.logger.Warn("error on getting current schema", func(e goengine.LoggerEntry) {
287+
e.Error(err)
288+
})
289+
290+
return false
291+
}
292+
284293
var exists bool
285-
err := e.db.QueryRowContext(
294+
if err := e.db.QueryRowContext(
286295
ctx,
287-
`SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = $1)`,
288-
tableName,
289-
).Scan(&exists)
290-
291-
if err != nil {
296+
`SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_schema = $1 AND table_name = $2)`,
297+
currentSchema, tableName,
298+
).Scan(&exists); err != nil {
292299
e.logger.Warn("error on reading from information_schema", func(e goengine.LoggerEntry) {
293300
e.Error(err)
294301
e.String("table", tableName)

driver/sql/postgres/eventstore_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import (
1111
"testing"
1212
"time"
1313

14-
sqlmock "github.com/DATA-DOG/go-sqlmock"
14+
"github.com/DATA-DOG/go-sqlmock"
1515
"github.com/golang/mock/gomock"
16+
"github.com/stretchr/testify/assert"
17+
"github.com/stretchr/testify/require"
18+
1619
"github.com/hellofresh/goengine/v2"
1720
"github.com/hellofresh/goengine/v2/aggregate"
1821
driverSQL "github.com/hellofresh/goengine/v2/driver/sql"
@@ -22,8 +25,6 @@ import (
2225
"github.com/hellofresh/goengine/v2/mocks"
2326
mockSQL "github.com/hellofresh/goengine/v2/mocks/driver/sql"
2427
strategyPostgres "github.com/hellofresh/goengine/v2/strategy/json/sql/postgres"
25-
"github.com/stretchr/testify/assert"
26-
"github.com/stretchr/testify/require"
2728
)
2829

2930
func TestNewEventStore(t *testing.T) {
@@ -384,8 +385,11 @@ func TestEventStore_Load(t *testing.T) {
384385
}
385386

386387
func mockHasStreamQuery(result bool, mock sqlmock.Sqlmock) {
387-
mockRows := sqlmock.NewRows([]string{"type"}).AddRow(result)
388-
mock.ExpectQuery(`SELECT EXISTS\((.+)`).WithArgs("events_orders").WillReturnRows(mockRows)
388+
schemaRows := sqlmock.NewRows([]string{"current_schema"}).AddRow("public")
389+
mock.ExpectQuery(`select current_schema()`).WillReturnRows(schemaRows)
390+
391+
existsRows := sqlmock.NewRows([]string{"type"}).AddRow(result)
392+
mock.ExpectQuery(`SELECT EXISTS\((.+)`).WithArgs("public", "events_orders").WillReturnRows(existsRows)
389393
}
390394

391395
func mockMessages(ctrl *gomock.Controller) (*mocks.MessagePayloadConverter, []goengine.Message) {

extension/amqp/amqp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package amqp
33
import (
44
"io"
55

6+
amqp "github.com/rabbitmq/amqp091-go"
7+
68
"github.com/hellofresh/goengine/v2"
7-
"github.com/streadway/amqp"
89
)
910

1011
// NotificationChannel represents a channel for notifications

extension/amqp/amqp_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ package amqp_test
66
import (
77
"testing"
88

9+
amqp "github.com/rabbitmq/amqp091-go"
10+
"github.com/stretchr/testify/assert"
11+
912
"github.com/hellofresh/goengine/v2"
1013
goengineAmqp "github.com/hellofresh/goengine/v2/extension/amqp"
11-
"github.com/streadway/amqp"
12-
"github.com/stretchr/testify/assert"
1314
)
1415

1516
type mockAcknowledger struct {

extension/amqp/listener.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"time"
77

88
"github.com/mailru/easyjson"
9-
"github.com/streadway/amqp"
9+
amqp "github.com/rabbitmq/amqp091-go"
1010

1111
"github.com/hellofresh/goengine/v2"
1212
"github.com/hellofresh/goengine/v2/driver/sql"

extension/amqp/listener_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"testing"
1111
"time"
1212

13+
libamqp "github.com/rabbitmq/amqp091-go"
1314
"github.com/sirupsen/logrus"
1415
"github.com/sirupsen/logrus/hooks/test"
15-
libamqp "github.com/streadway/amqp"
1616
"github.com/stretchr/testify/assert"
1717
"github.com/stretchr/testify/require"
1818

extension/amqp/publisher.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import (
66
"sync"
77
"time"
88

9+
"github.com/mailru/easyjson"
10+
amqp "github.com/rabbitmq/amqp091-go"
11+
912
"github.com/hellofresh/goengine/v2"
1013
"github.com/hellofresh/goengine/v2/driver/sql"
11-
"github.com/mailru/easyjson"
12-
"github.com/streadway/amqp"
1314
)
1415

1516
var _ sql.ProjectionTrigger = (&NotificationPublisher{}).Publish

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ require (
99
github.com/lib/pq v1.10.7
1010
github.com/mailru/easyjson v0.7.7
1111
github.com/prometheus/client_golang v1.13.0
12+
github.com/rabbitmq/amqp091-go v1.5.0
1213
github.com/sirupsen/logrus v1.9.0
13-
github.com/streadway/amqp v1.0.0
1414
github.com/stretchr/testify v1.8.0
1515
go.uber.org/zap v1.23.0
1616
)
@@ -31,7 +31,6 @@ require (
3131
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
3232
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 // indirect
3333
golang.org/x/tools v0.1.12 // indirect
34-
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
3534
google.golang.org/protobuf v1.28.1 // indirect
3635
gopkg.in/yaml.v3 v3.0.1 // indirect
3736
)

0 commit comments

Comments
 (0)