From fc7c6f46a8352244bb9473f291f3e946b3bf4bb7 Mon Sep 17 00:00:00 2001 From: AbdouTlili Date: Thu, 11 Jan 2024 21:08:42 +0100 Subject: [PATCH 1/4] Updating the run script to use compose plugin instead of legacy docker-compose command Adding CreateTableIfNotExists() function in the add initialization so the app works out-of-the-box in case the user did not run the tests --- app/app.go | 1 + run.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/app.go b/app/app.go index 28b0c36..a772de3 100644 --- a/app/app.go +++ b/app/app.go @@ -31,6 +31,7 @@ func (app *RESTApp) Initialize(user, password, dbname string) { if err != nil { log.Fatal(err) } + app.CreateTableIfNotExists() app.Router = mux.NewRouter() app.initializeRoutes() diff --git a/run.sh b/run.sh index 5ad6380..cb847d4 100755 --- a/run.sh +++ b/run.sh @@ -2,7 +2,7 @@ startdb() { echo "Starting postgres database" - docker-compose up -d + docker compose up -d echo "Started." } From e546b3eb38339d1defd7a17269617d767d178774 Mon Sep 17 00:00:00 2001 From: AbdouTlili Date: Thu, 11 Jan 2024 22:21:00 +0100 Subject: [PATCH 2/4] adding ci file for github actions automated testing --- .github/workflows/ci.yaml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..5bf1a01 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,20 @@ +name: Ci Test +on: push +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Init db + run: | + ./run.sh startdb + ./run.sh initdb products_db + + - name: Running tests + run: | + go test ./app/ + + - name: Cleaning + run: | + ./run.sh stopdb + ./run.sh cleanup From b8cd846a8c092182af5bb67faa807b21de9da18c Mon Sep 17 00:00:00 2001 From: AbdouTlili Date: Thu, 11 Jan 2024 22:23:18 +0100 Subject: [PATCH 3/4] sleeping after postgress initialization in github workflows and deleting the -t option in docker exec as it is braking the workflow execution --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index cb847d4..c5e2b53 100755 --- a/run.sh +++ b/run.sh @@ -20,7 +20,7 @@ dblogs() { initdb() { if [[ -n "$1" ]]; then echo "Initializing database with name: $1" - docker exec -it go_postgres psql -U postgres -c "create database $1" # db-name + docker exec -i go_postgres psql -U postgres -c "create database $1" # db-name else echo "No database name provided, use initdb " fi From 66c0b901120702b8f836ae90631f99c4be985909 Mon Sep 17 00:00:00 2001 From: AbdouTlili Date: Thu, 11 Jan 2024 22:24:43 +0100 Subject: [PATCH 4/4] sleeping more time after the postres launch --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5bf1a01..fa1b439 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,6 +8,7 @@ jobs: - name: Init db run: | ./run.sh startdb + sleep 6 ./run.sh initdb products_db - name: Running tests