Skip to content

Commit

Permalink
“testDB”
Browse files Browse the repository at this point in the history
  • Loading branch information
LordMoMA committed Sep 6, 2023
1 parent 08c05cd commit f764650
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ Now, let's dive into how to create a messaging backend that allows users to save
- ⌛️ Add Distributed services
- ⌛️ Add URL Queries

## How to keep the Test DB running and test the exact func with the triangle button in an IDE?

```bash
chmod +x testDB.sh
```
Now you can use the following command to start the test database:
```bash
./testDB.sh -t start
```
And use the following command to run tests and stop the test database afterwards:
```bash
./testDB.sh -t unit # For unit tests
./testDB.sh -t integration # For integration tests
./testDB.sh # For all tests
```
![badge](https://github.com/LordMoMA/Hexagonal-Architecture/.github/workflows/go.yml/badge.svg)

# 🚀 Pros and Cons of using GORM in this project
Expand Down
41 changes: 41 additions & 0 deletions testDB.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

start_test_db() {
docker run --name hex-arch-testing-db -p 5433:5432 -e POSTGRES_USER=test -e POSTGRES_PASSWORD=test -e POSTGRES_DB=template1 -d postgres
}

stop_test_db() {
docker stop hex-arch-testing-db
docker rm hex-arch-testing-db
}

while getopts t: flag; do
case "${flag}" in
t) type=${OPTARG} ;;
esac
done

case $type in
start)
start_test_db
echo "Test database started."
;;
unit)
start_test_db
CGO_ENABLED=0 go test -v -p 1 -count=1 -covermode=count -coverprofile=coverage/c.out -run Unit ./...
stop_test_db
echo "Test database stopped."
;;
integration)
start_test_db
CGO_ENABLED=0 go test -v -p 1 -count=1 -covermode=count -coverprofile=coverage/c.out -run Integration ./...
stop_test_db
echo "Test database stopped."
;;
*)
start_test_db
CGO_ENABLED=0 go test -v -p 1 -count=1 -covermode=count -coverprofile=coverage/c.out ./...
stop_test_db
echo "Test database stopped."
;;
esac

0 comments on commit f764650

Please sign in to comment.