Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mvrilo/go-example-repo-mock
https://github.com/mvrilo/go-example-repo-mock
example go go-sqlmock golang mock model repository-pattern tests unit-testing
Last synced: about 22 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/mvrilo/go-example-repo-mock
- Owner: mvrilo
- Created: 2022-08-19T12:33:21.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-11T17:03:08.000Z (over 2 years ago)
- Last Synced: 2024-12-06T09:27:04.766Z (about 2 months ago)
- Topics: example, go, go-sqlmock, golang, mock, model, repository-pattern, tests, unit-testing
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## go-example-repo-mock
[![CI](https://github.com/mvrilo/go-example-repo-mock/actions/workflows/ci.yaml/badge.svg)](https://github.com/mvrilo/go-example-repo-mock/actions/workflows/ci.yaml)
Example of application (data storage layer only) for a `User` domain-scoped service using Go, repository pattern for data access and mysql as its implementation, github actions for ci and unit tests using `testify/suite` and `go-sqlmock`.
For a "model-only" package/architecture, head to [this branch](https://github.com/mvrilo/go-example-repo-mock/tree/model).
### Architecture:
- `entity`
data structures mapping to the database schema and other domain data, e.g. definition of user, custom errors, etc- `repository`
definition and implementation of storage access behavior, e.g. get data, save data, etc- `mock`
data mocking for each repository implementation, e.g. fake sql results### Testing
`make`
### Project structure
```
.
├── Makefile
├── README.md
├── go.mod
├── go.sum
├── mock # mock definitions
│ └── mysql # by repository implementation
│ └── user.go
├── entity # domain/database entity definitions
│ └── user.go
└── repository # repository interface
├── mysql # and implementation
│ ├── user.go
│ └── user_test.go # unit tests
└── repository.go5 directories, 9 files
```