Nyhetsjeger
Bachelor Project for SMP
Dev environment setup
In order to run and develop this project, you will need a set of tools.
-
Visual Studio Code - editor recommanded for this project, tools and plugins listed below transform it into an IDE.
-
WSL - We use it for consistant developer experience, as well as development in similar environment to production. Allows us to use Linux-specific toolchains. This simplifies development of scripts.
All tooling below must be accessible in WSL (Except if you are using all tools native to your OS)
Building and running locally
Use Make to run targets (build, run, etc.) specified in the Makefile. Make is included in most Linux distributions(as well as WSL). If it isnt included by default, use your distros package manager to install it.
Example:
make run
Alternatively, you can check out the commands in the Makefile and run them manually.
Initial setup
Before you can get started running the application you need to get a few things sorted.
Copy the .env.example file to .env.
cp .env.example .env
Change the default passwords and secrets to your own!
Standup the services in docker-compose.
make initialize-docker
And then migrate the database, either
make reset-db
Alternatively, if you don't want dummy/test data
make migrate-up
./scripts/add-db-usr.sh
./scripts/add-nickname-words.sh
Setup a Google Cloud project, generate client ID and secret, update the .env file. This is needed for the OAuth2 login.
Setup MinIO (dashboard can be accessed at localhost:9001). Create a bucket called "images", set public read, generate access and secret keys for write. Set the secrets in the .env file.
Testing
The project has unit and integration tests, they live in separate files and are tagged with go build tags.
unit tests: filename_test.go, build tag unit
integration tests: filename_integration_test.go, build tag integration
Add the build tags to your LSP configuration so you get syntax highlighting and autocompletion in the test files.
VScode settings.json example:
{
"go.buildFlags": [
"-tags=integration,unit"
],
"go.testTags": "integration,unit",
}
To run the tests, use specific Make targets
make test-unit
make test-integration
Note: Integration tests use Testcontainers, which requires Docker to be running.
API testing with Bruno
To run the Bruno tets, you need the application running locally.
make run
Then you can run the test suite
make run-bruno
The above uses bru CLI via npx, you may be asked to install it first time you run it.