We use the standard test suite in combination with github.com/stretchr/testify to do our unit testing. Mocks are generated using mockery a mock generator using this command mockery --all --keeptree
.
To run them, please run:
go test $(go list ./... | sed 1d) -v
We use docker to run a Badaas instance in combination with one node of CockroachDB.
Run:
docker compose -f "scripts/e2e/docker-compose.yml" up -d --build
Then in an another shell:
go test -v
The feature files can be found in the feature
folder.
We use ubber's zap to log stuff, please take zap.Logger
as an argument for your services constructors. fx will provide your service with an instance.
This is the directory structure we use for the project:
commands/
(Go code): Contains all the CLI commands. This package relies heavily on github.com/ditrit/verdeter.configuration/
(Go code): Contains all the configuration holders. Please only use the interfaces, they are all mocked for easy testingcontrollers/
(Go code): Contains all the http controllers, they handle http requests and consume services.docs/
: Contains the documentation.features/
: Contains all the feature tests (or end to end tests).logger/
(Go code): Contains the logger creation logic. Please don't call it from your own services and code, use the dependency injection system.persistance/
(Go code):/gormdatabase/
(Go code): Contains the logic to create a https://gorm.io database. Also contains a go package namedgormzap
: it is a compatibility layer between gorm.io/gorm and github.com/uber-go/zap./models/
(Go code): Contains the models. (For a structure to me considered a valid model, it has to embedmodels.BaseModel
and satisfy themodels.Tabler
interface. This interface returns the name of the sql table.)/dto/
(Go code): Contains the Data Transfert Objects. They are used mainly to decode json payloads.
/pagination/
(Go code): Contains the pagination logic./repository/
(Go code): Contains the repository interface and implementation. Use uint as ID when using gorm models.
resources/
(Go code): Contains the resources shared with the rest of the codebase (ex: API version).router/
(Go code): Contains http router of badaas./middlewares/
(Go code): Contains the various http middlewares that we use.
scripts/e2e/
: Contains the docker-compose file for end-to-end test./api/
: Contains the Dockerfile to build badaas with a dedicated config file./db/
: Contains the Dockerfile to build a developpement version of CockroachDB.
services/
(Go code): Contains the Dockerfile to build a developpement version of CockroachDB./auth/protocols/
: Contains the implementations of authentication clients for differents protocols./basicauth/
(Go code): Handle the authentification using email/password./oidc/
(Go code): Handle the authentication via Open-ID Connect.
/sessionservice/
(Go code): Handle sessions and their lifecycle./userservice/
(Go code): Handle users.validators/
(Go code): Contains validators such as an email validator.
At the root of the project, you will find:
- The README.
- The changelog.
- The files for the E2E test http support.
- The LICENCE file.
[BRANCH_TYPE]/[BRANCH_NAME]
-
BRANCH_TYPE
is a prefix to describe the purpose of the branch.Accepted prefixes are:
feature
, used for feature developmentbugfix
, used for bug fiximprovement
, used for refactolibrary
, used for updating libraryprerelease
, used for preparing the branch for the releaserelease
, used for releasing projecthotfix
, used for applying a hotfix on mainpoc
, used for proof of concept
-
BRANCH_NAME
is managed by this regex:[a-z0-9._-]
(_
is used as space character).
The default branch is main
. Direct commit on it is forbidden. The only way to update the application is through pull request.
Release tag are only done on the main
branch.
We use Semantic Versioning as guideline for the version management.
Steps to release:
- Create a new branch labeled
release/vX.Y.Z
from the latestmain
. - Improve the version number in
changelog.md
andresources/api.go
. - Verify the content of the
changelog.md
. - Commit the modifications with the label
Release version X.Y.Z
. - Create a pull request on github for this branch into
main
. - Once the pull request validated and merged, tag the
main
branch withvX.Y.Z
- After the tag is pushed, make the release on the tag in GitHub