Skip to content

Commit 9ff7ae6

Browse files
committed
test: added unit testing for use cases
test: added unit testing for use cases
1 parent 0e3cc13 commit 9ff7ae6

13 files changed

+543
-70
lines changed

.mockery.yaml

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
disable-version-string: true
22
mockname: '{{.InterfaceName}}'
33
filename: '{{.MockName}}.go'
4-
outpkg: mocks
4+
outpkg: mock
5+
with-expecter: true
56
packages:
6-
github.com/sebajax/go-architecture-angrycoders/internal/user:
7+
github.com/sebajax/go-vertical-slice-architecture/internal/user:
78
# place your package-specific config here
89
config:
9-
dir: 'internal/{{.PackageName}}/mocks'
10+
dir: 'internal/{{.PackageName}}/mock'
1011
interfaces:
1112
# select the interfaces you want mocked
1213
UserRepository:
1314
# Modify package-level config for this specific interface (if applicable)
1415
config:
16+
github.com/sebajax/go-vertical-slice-architecture/internal/product:
17+
# place your package-specific config here
18+
config:
19+
dir: 'internal/{{.PackageName}}/mock'
20+
interfaces:
21+
# select the interfaces you want mocked
22+
ProductRepository:
23+
# Modify package-level config for this specific interface (if applicable)
24+
config:

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ A brief description of the layout:
6060

6161
## 🤜 How to create a new use case (Example)
6262

63-
### Database diagram for the project
64-
65-
![alt text](./image/db_diagram.png)
66-
6763
### Internal folder structure for a new domain all folders and files go in internal/product/
6864

6965
```tree
@@ -210,7 +206,7 @@ https://github.com/sebajax/go-vertical-slice-architecture/blob/eb79ccae805d23b6f
210206

211207
```bash
212208
# To run unit testing
213-
go test
209+
go test ./...
214210

215211
# To run unit testing coverage
216212
go test -cover ./...

go.mod

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/golang-migrate/migrate/v4 v4.17.0
99
github.com/jackc/pgx/v5 v5.5.3
1010
github.com/sebajax/go-architecture-angrycoders v0.0.0-20240215234534-8b0c71a519da
11+
github.com/stretchr/testify v1.8.4
1112
go.uber.org/dig v1.17.1
1213
)
1314

@@ -25,6 +26,7 @@ require (
2526
)
2627

2728
require (
29+
github.com/davecgh/go-spew v1.1.1 // indirect
2830
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
2931
github.com/go-playground/locales v0.14.1 // indirect
3032
github.com/go-playground/universal-translator v0.18.1 // indirect
@@ -33,12 +35,17 @@ require (
3335
github.com/jackc/pgpassfile v1.0.0 // indirect
3436
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
3537
github.com/jackc/puddle/v2 v2.2.1 // indirect
38+
github.com/kr/text v0.2.0 // indirect
3639
github.com/leodido/go-urn v1.2.4 // indirect
3740
github.com/lib/pq v1.10.9 // indirect
41+
github.com/pmezard/go-difflib v1.0.0 // indirect
42+
github.com/rogpeppe/go-internal v1.12.0 // indirect
43+
github.com/stretchr/objx v0.5.0 // indirect
3844
go.uber.org/atomic v1.7.0 // indirect
3945
golang.org/x/crypto v0.17.0 // indirect
4046
golang.org/x/net v0.18.0 // indirect
4147
golang.org/x/sync v0.5.0 // indirect
4248
golang.org/x/sys v0.16.0 // indirect
4349
golang.org/x/text v0.14.0 // indirect
50+
gopkg.in/yaml.v3 v3.0.1 // indirect
4451
)

go.sum

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
44
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
55
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
66
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
7+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
78
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
89
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
910
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -50,6 +51,10 @@ github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk
5051
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
5152
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
5253
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
54+
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
55+
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
56+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
57+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
5358
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
5459
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
5560
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
@@ -75,10 +80,13 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
7580
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7681
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
7782
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
83+
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
84+
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
7885
github.com/sebajax/go-architecture-angrycoders v0.0.0-20240215234534-8b0c71a519da h1:Y/IGfCNQJgGc+8nwxL9gnL7FrVPdmxGTXLJe7pxL5z8=
7986
github.com/sebajax/go-architecture-angrycoders v0.0.0-20240215234534-8b0c71a519da/go.mod h1:X7kYg0VhvL9alodexKrNZ26vFPF2ZlGrGE2Z538T4/4=
8087
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8188
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
89+
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
8290
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
8391
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
8492
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -114,6 +122,8 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
114122
golang.org/x/tools v0.10.0 h1:tvDr/iQoUqNdohiYm0LmmKcBk+q86lb9EprIUFhHHGg=
115123
golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM=
116124
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
125+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
126+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
117127
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
118128
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
119129
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/product/mock/ProductRepository.go

+156
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/product/mock/mockProductRepository.go

-28
This file was deleted.

internal/product/service/createProduct.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (service *CreateProductService) CreateProduct(p *product.Product) (int64, e
2626
// check if product sky does not exist and no database error ocurred
2727
if err != nil {
2828
// database error
29-
log.Fatalln(err)
29+
log.Println(err)
3030
err := apperror.InternalServerError()
3131
return 0, err
3232
}
@@ -41,7 +41,7 @@ func (service *CreateProductService) CreateProduct(p *product.Product) (int64, e
4141
id, err := service.productRepository.Save(p)
4242
if err != nil {
4343
// database error
44-
log.Fatalln(err)
44+
log.Println(err)
4545
err := apperror.InternalServerError()
4646
return 0, err
4747
}

0 commit comments

Comments
 (0)