Skip to content

Commit a09f6dd

Browse files
committed
test containers implementation, working on #27
1 parent f16df65 commit a09f6dd

File tree

6 files changed

+216
-126
lines changed

6 files changed

+216
-126
lines changed

Diff for: README.md

+1-20
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,7 @@ For running the integration tests you should do :
4242
$ make integration
4343
```
4444

45-
These test requires to have PostgreSQL running with the following details :
46-
```text
47-
Server : localhost
48-
Port : 5432
49-
Database : pets
50-
User : petuser
51-
Password : petpwd
52-
```
53-
54-
If you have [docker](https://www.docker.com/products/docker-desktop) installed you could run a local database with this settings with :
55-
56-
```shell script
57-
$ ./scripts/local-db.sh start
58-
```
59-
60-
To stop the local database you could do :
61-
62-
```shell script
63-
$ ./scripts/local-db.sh stop
64-
```
45+
These test requires to have Docker running.
6546

6647
## Example requests using HTTPie
6748

Diff for: go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ go 1.14
44

55
require (
66
github.com/DATA-DOG/go-sqlmock v1.4.1
7+
github.com/docker/go-connections v0.4.0
78
github.com/lib/pq v1.5.1
9+
github.com/testcontainers/testcontainers-go v0.5.1
810
)

Diff for: go.sum

+116-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,120 @@
1+
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
2+
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
13
github.com/DATA-DOG/go-sqlmock v1.4.1 h1:ThlnYciV1iM/V0OSF/dtkqWb6xo5qITT1TJBG1MRDJM=
24
github.com/DATA-DOG/go-sqlmock v1.4.1/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
3-
github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
4-
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
5+
github.com/Microsoft/go-winio v0.4.11 h1:zoIOcVf0xPN1tnMVbTtEdI+P8OofVk3NObnwOQ6nK2Q=
6+
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
7+
github.com/Microsoft/hcsshim v0.8.6 h1:ZfF0+zZeYdzMIVMZHKtDKJvLHj76XCuVae/jNkjj0IA=
8+
github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg=
9+
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
10+
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
11+
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
12+
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc h1:TP+534wVlf61smEIq1nwLLAjQVEK2EADoW3CX9AuT+8=
13+
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
14+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
15+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
16+
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible h1:dvc1KSkIYTVjZgHf/CTC2diTYC8PzhaA5sFISRfNVrE=
17+
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
18+
github.com/docker/docker v0.7.3-0.20190506211059-b20a14b54661 h1:ZuxGvIvF01nfc/G9RJ5Q7Va1zQE2WJyG18Zv3DqCEf4=
19+
github.com/docker/docker v0.7.3-0.20190506211059-b20a14b54661/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
20+
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
21+
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
22+
github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk=
23+
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
24+
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
25+
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
26+
github.com/gin-gonic/gin v1.6.2/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
27+
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
28+
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
29+
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
30+
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
31+
github.com/go-redis/redis v6.15.7+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
32+
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
33+
github.com/gogo/protobuf v1.2.0 h1:xU6/SpYbvkNYiptHJYEDRseDLvYE7wSqhYYNy0QSUzI=
34+
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
35+
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
36+
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
37+
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
38+
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
39+
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
40+
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
41+
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
42+
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
43+
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
44+
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
45+
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
46+
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
47+
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
48+
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
49+
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
50+
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
51+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
52+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
53+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
54+
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
555
github.com/lib/pq v1.5.1 h1:Jn6HYxiYrtQ92CopqJLvfPCJUrrruw1+1cn0jM9dKrI=
656
github.com/lib/pq v1.5.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
57+
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
58+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
59+
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
60+
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
61+
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
62+
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
63+
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
64+
github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
65+
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
66+
github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI=
67+
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
68+
github.com/opencontainers/runc v0.1.1 h1:GlxAyO6x8rfZYN9Tt0Kti5a/cP41iuiO2yYT0IJGY8Y=
69+
github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
70+
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
71+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
72+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
73+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
74+
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
75+
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
76+
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
77+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
78+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
79+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
80+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
81+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
82+
github.com/testcontainers/testcontainers-go v0.5.1 h1:VbMekzjv6e5KmhiwMm5B1kjrCigoKYVORUVVe+QbAQc=
83+
github.com/testcontainers/testcontainers-go v0.5.1/go.mod h1:Oc/G02bjZiX0p3lzyh6b1GCELP0e4/6Cg3ciU/LnFvU=
84+
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
85+
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
86+
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
87+
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
88+
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
89+
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
90+
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
91+
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
92+
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
93+
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
94+
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
95+
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
96+
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
97+
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
98+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
99+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
100+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
101+
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
102+
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
103+
golang.org/x/tools v0.0.0-20180810170437-e96c4e24768d/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
104+
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
105+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
106+
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
107+
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
108+
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
109+
google.golang.org/grpc v1.17.0 h1:TRJYBgMclJvGYn2rIMjj+h9KtMt5r1Ij7ODVRIZkwhk=
110+
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
111+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
112+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
113+
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
114+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
115+
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
116+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
117+
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
118+
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
119+
gotest.tools v0.0.0-20181223230014-1083505acf35/go.mod h1:R//lfYlUuTOTfblYI3lGoAAAebUdzjvbmQsuB7Ykd90=
120+
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

Diff for: internal/app/store/psqlstore/psqlstore_integ_test.go

+97-30
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@
2323
package psqlstore
2424

2525
import (
26+
"context"
2627
"fmt"
2728
"github.com/LearningByExample/go-microservice/internal/app/data"
2829
"github.com/LearningByExample/go-microservice/internal/app/store"
30+
"github.com/docker/go-connections/nat"
31+
"github.com/testcontainers/testcontainers-go"
32+
"github.com/testcontainers/testcontainers-go/wait"
33+
"os"
2934
"reflect"
3035
"sync"
3136
"testing"
37+
"time"
3238
)
3339

3440
const (
@@ -37,31 +43,93 @@ const (
3743
integrationTestSkipped = "Integration test are skipped"
3844
)
3945

40-
func getIntegrationPetStore() *posgreSQLPetStore {
41-
return getPetStore(postgreSQLFile)
46+
var psqlC testcontainers.Container = nil
47+
var host string
48+
var port int
49+
50+
func TestMain(m *testing.M) {
51+
ctx := context.Background()
52+
code := m.Run()
53+
if psqlC != nil {
54+
defer psqlC.Terminate(ctx)
55+
}
56+
os.Exit(code)
57+
}
58+
59+
func getIntegrationPetStore(t *testing.T) *posgreSQLPetStore {
60+
t.Helper()
61+
if psqlC == nil {
62+
var err error = nil
63+
if psqlC, host, port, err = createContainer(); err != nil {
64+
t.Fatalf("error starting container %v", err)
65+
}
66+
}
67+
ps := getPetStore(postgreSQLFile)
68+
69+
ps.cfg.Store.Postgresql.Port = port
70+
ps.cfg.Store.Postgresql.Host = host
71+
72+
return ps
73+
}
74+
75+
func createContainer() (testcontainers.Container, string, int, error) {
76+
var err error = nil
77+
var container testcontainers.Container = nil
78+
79+
envs := make(map[string]string)
80+
envs["POSTGRES_USER"] = "petuser"
81+
envs["POSTGRES_PASSWORD"] = "petpwd"
82+
envs["POSTGRES_DB"] = "pets"
83+
84+
ctx := context.Background()
85+
req := testcontainers.ContainerRequest{
86+
Image: "postgres",
87+
ExposedPorts: []string{"5432/tcp"},
88+
WaitingFor: wait.ForLog("database system is ready").
89+
WithOccurrence(2).WithStartupTimeout(60 * time.Second).
90+
WithPollInterval(5 * time.Second),
91+
Env: envs,
92+
}
93+
container, err = testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
94+
ContainerRequest: req,
95+
Started: true,
96+
})
97+
98+
ip := "localhost"
99+
port := 5432
100+
101+
if err == nil {
102+
if ip, err = container.Host(ctx); err == nil {
103+
var natPort nat.Port
104+
if natPort, err = container.MappedPort(ctx, "5432"); err == nil {
105+
port = natPort.Int()
106+
}
107+
}
108+
}
109+
110+
return container, ip, port, err
42111
}
43112

44-
func runTestSQL(sql string) {
45-
ps := getIntegrationPetStore()
113+
func runTestSQL(sql string, t *testing.T) {
114+
ps := getIntegrationPetStore(t)
46115
_ = ps.Open()
47116
//noinspection GoUnhandledErrorResult
48117
defer ps.Close()
49118

50119
_, _ = ps.exec(sql)
51120
}
52121

53-
func resetDB() {
54-
runTestSQL(sqlResetDB)
122+
func resetDB(t *testing.T) {
123+
runTestSQL(sqlResetDB, t)
55124
}
56125

57126
func TestPSqlPetStore_OpenClose(t *testing.T) {
58127
if testing.Short() {
59128
t.Skip(integrationTestSkipped)
60129
}
61-
resetDB()
62-
defer resetDB()
130+
63131
t.Run("should work", func(t *testing.T) {
64-
ps := getPetStore(postgreSQLFile)
132+
ps := getIntegrationPetStore(t)
65133

66134
err := ps.Open()
67135
if err != nil {
@@ -93,9 +161,8 @@ func TestPSqlPetStore_IsReady(t *testing.T) {
93161
if testing.Short() {
94162
t.Skip(integrationTestSkipped)
95163
}
96-
resetDB()
97-
defer resetDB()
98-
ps := getIntegrationPetStore()
164+
165+
ps := getIntegrationPetStore(t)
99166
_ = ps.Open()
100167
//noinspection GoUnhandledErrorResult
101168
defer ps.Close()
@@ -111,9 +178,9 @@ func TestPSqlPetStore_AddPet(t *testing.T) {
111178
if testing.Short() {
112179
t.Skip(integrationTestSkipped)
113180
}
114-
resetDB()
115-
defer resetDB()
116-
ps := getIntegrationPetStore()
181+
182+
ps := getIntegrationPetStore(t)
183+
resetDB(t)
117184
_ = ps.Open()
118185
//noinspection GoUnhandledErrorResult
119186
defer ps.Close()
@@ -138,9 +205,9 @@ func TestPosgreSQLPetStore_UpdatePet(t *testing.T) {
138205
if testing.Short() {
139206
t.Skip(integrationTestSkipped)
140207
}
141-
resetDB()
142-
defer resetDB()
143-
ps := getIntegrationPetStore()
208+
209+
ps := getIntegrationPetStore(t)
210+
resetDB(t)
144211
_ = ps.Open()
145212
//noinspection GoUnhandledErrorResult
146213
defer ps.Close()
@@ -211,9 +278,9 @@ func TestPosgreSQLPetStore_DeletePet(t *testing.T) {
211278
if testing.Short() {
212279
t.Skip(integrationTestSkipped)
213280
}
214-
resetDB()
215-
defer resetDB()
216-
ps := getIntegrationPetStore()
281+
282+
ps := getIntegrationPetStore(t)
283+
resetDB(t)
217284
_ = ps.Open()
218285
//noinspection GoUnhandledErrorResult
219286
defer ps.Close()
@@ -250,9 +317,9 @@ func TestPSqlPetStore_GetPet(t *testing.T) {
250317
if testing.Short() {
251318
t.Skip(integrationTestSkipped)
252319
}
253-
resetDB()
254-
defer resetDB()
255-
ps := getIntegrationPetStore()
320+
321+
ps := getIntegrationPetStore(t)
322+
resetDB(t)
256323
_ = ps.Open()
257324
//noinspection GoUnhandledErrorResult
258325
defer ps.Close()
@@ -291,9 +358,9 @@ func TestPosgreSQLPetStore_GetAllPets(t *testing.T) {
291358
if testing.Short() {
292359
t.Skip(integrationTestSkipped)
293360
}
294-
resetDB()
295-
defer resetDB()
296-
ps := getIntegrationPetStore()
361+
362+
ps := getIntegrationPetStore(t)
363+
resetDB(t)
297364
_ = ps.Open()
298365
//noinspection GoUnhandledErrorResult
299366
defer ps.Close()
@@ -345,9 +412,9 @@ func TestPosgreSQLPetStore_Concurrency(t *testing.T) {
345412
if testing.Short() {
346413
t.Skip(integrationTestSkipped)
347414
}
348-
resetDB()
349-
defer resetDB()
350-
ps := getIntegrationPetStore()
415+
416+
ps := getIntegrationPetStore(t)
417+
resetDB(t)
351418
_ = ps.Open()
352419
//noinspection GoUnhandledErrorResult
353420
defer ps.Close()

Diff for: internal/app/store/psqlstore/psqlstore_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ func TestNewPostgresSQLPetStore(t *testing.T) {
6969
}
7070

7171
func TestPSqlPetStore_Logger(t *testing.T) {
72-
resetDB()
73-
defer resetDB()
7472
t.Run("should save logs", func(t *testing.T) {
7573
ps := getPetStore(postgreSQLFile)
7674
got := reflect.ValueOf(ps.logger)

0 commit comments

Comments
 (0)