Skip to content

Commit

Permalink
test: added unit testing for use cases
Browse files Browse the repository at this point in the history
test: added unit testing for use cases
  • Loading branch information
sebajax committed Feb 23, 2024
1 parent 0e3cc13 commit 9ff7ae6
Show file tree
Hide file tree
Showing 13 changed files with 543 additions and 70 deletions.
16 changes: 13 additions & 3 deletions .mockery.yaml
@@ -1,14 +1,24 @@
disable-version-string: true
mockname: '{{.InterfaceName}}'
filename: '{{.MockName}}.go'
outpkg: mocks
outpkg: mock
with-expecter: true
packages:
github.com/sebajax/go-architecture-angrycoders/internal/user:
github.com/sebajax/go-vertical-slice-architecture/internal/user:
# place your package-specific config here
config:
dir: 'internal/{{.PackageName}}/mocks'
dir: 'internal/{{.PackageName}}/mock'
interfaces:
# select the interfaces you want mocked
UserRepository:
# Modify package-level config for this specific interface (if applicable)
config:
github.com/sebajax/go-vertical-slice-architecture/internal/product:
# place your package-specific config here
config:
dir: 'internal/{{.PackageName}}/mock'
interfaces:
# select the interfaces you want mocked
ProductRepository:
# Modify package-level config for this specific interface (if applicable)
config:
6 changes: 1 addition & 5 deletions README.md
Expand Up @@ -60,10 +60,6 @@ A brief description of the layout:

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

### Database diagram for the project

![alt text](./image/db_diagram.png)

### Internal folder structure for a new domain all folders and files go in internal/product/

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

```bash
# To run unit testing
go test
go test ./...

# To run unit testing coverage
go test -cover ./...
Expand Down
7 changes: 7 additions & 0 deletions go.mod
Expand Up @@ -8,6 +8,7 @@ require (
github.com/golang-migrate/migrate/v4 v4.17.0
github.com/jackc/pgx/v5 v5.5.3
github.com/sebajax/go-architecture-angrycoders v0.0.0-20240215234534-8b0c71a519da
github.com/stretchr/testify v1.8.4
go.uber.org/dig v1.17.1
)

Expand All @@ -25,6 +26,7 @@ require (
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
Expand All @@ -33,12 +35,17 @@ require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Expand Up @@ -4,6 +4,7 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -50,6 +51,10 @@ github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
Expand All @@ -75,10 +80,13 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/sebajax/go-architecture-angrycoders v0.0.0-20240215234534-8b0c71a519da h1:Y/IGfCNQJgGc+8nwxL9gnL7FrVPdmxGTXLJe7pxL5z8=
github.com/sebajax/go-architecture-angrycoders v0.0.0-20240215234534-8b0c71a519da/go.mod h1:X7kYg0VhvL9alodexKrNZ26vFPF2ZlGrGE2Z538T4/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down Expand Up @@ -114,6 +122,8 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.10.0 h1:tvDr/iQoUqNdohiYm0LmmKcBk+q86lb9EprIUFhHHGg=
golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
156 changes: 156 additions & 0 deletions internal/product/mock/ProductRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 0 additions & 28 deletions internal/product/mock/mockProductRepository.go

This file was deleted.

4 changes: 2 additions & 2 deletions internal/product/service/createProduct.go
Expand Up @@ -26,7 +26,7 @@ func (service *CreateProductService) CreateProduct(p *product.Product) (int64, e
// check if product sky does not exist and no database error ocurred
if err != nil {
// database error
log.Fatalln(err)
log.Println(err)
err := apperror.InternalServerError()
return 0, err
}
Expand All @@ -41,7 +41,7 @@ func (service *CreateProductService) CreateProduct(p *product.Product) (int64, e
id, err := service.productRepository.Save(p)
if err != nil {
// database error
log.Fatalln(err)
log.Println(err)
err := apperror.InternalServerError()
return 0, err
}
Expand Down

0 comments on commit 9ff7ae6

Please sign in to comment.