From 761e75c013489c07de23510c0a71ade247fc2bfa Mon Sep 17 00:00:00 2001 From: Hans Date: Thu, 1 Aug 2024 23:40:14 +0200 Subject: [PATCH] test: test http-requests via intellij http-client and run in github action --- .github/workflows/docker.yml | 2 + .github/workflows/http-test.yml | 50 ++++++++++++++++++++++++ .gitignore | 3 +- http-test/get-items-empty.http | 19 +++++++++ http-test/get-noauth-users-empty.http | 19 +++++++++ http-test/http-client.env.json | 6 +++ http-test/post-logout-without-login.http | 12 ++++++ http-test/test.sh | 10 +++++ 8 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/http-test.yml create mode 100644 http-test/get-items-empty.http create mode 100644 http-test/get-noauth-users-empty.http create mode 100644 http-test/http-client.env.json create mode 100644 http-test/post-logout-without-login.http create mode 100755 http-test/test.sh diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index a3aa92f..83aa677 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -13,6 +13,8 @@ on: - "docker-compose.yaml" - "docker-compose.dev.yaml" - "openapi.yaml" + - ".run" + - "http-test" jobs: docker: runs-on: ubuntu-latest diff --git a/.github/workflows/http-test.yml b/.github/workflows/http-test.yml new file mode 100644 index 0000000..14b5cda --- /dev/null +++ b/.github/workflows/http-test.yml @@ -0,0 +1,50 @@ +name: http-test.yml +on: + push: + branches: + - "*" + +jobs: + HTTP-Tests: + permissions: + contents: read + actions: read + checks: write + runs-on: ubuntu-latest + services: + db: + image: postgres:16 + env: + POSTGRES_PASSWORD: "changeme" + POSTGRES_USER: "godrink" + POSTGRES_DB: "godrink" + ports: + - "5432:5432" + volumes: + - pgdata:/var/lib/postgresql/data + steps: + - name: Checkout + uses: actions/checkout@v4.1.7 + - name: Setup Go + uses: actions/setup-go@v5.0.2 + - name: Run Go-Drink + env: + GODRINK_DB: postgresql://godrink:changeme@localhost:5432/godrink?sslmode=disable + run: "go run . &" + - name: Execute HTTP requests + run: ./http-test/test.sh + timeout-minutes: 3 + - name: Publish Test Report + uses: mikepenz/action-junit-report@v4 + if: success() || failure() # always run even if the previous step fails + with: + detailed_summary: true + include_passed: true + require_passed_tests: true + update_check: true + report_paths: ./http-test-reports/report.xml + - name: Upload Test results + uses: actions/upload-artifact@v4.3.4 + with: + name: http-test-reports + path: ./http-test-reports/report.xml diff --git a/.gitignore b/.gitignore index 927878c..46cc484 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea go-drink.iml -go-drink \ No newline at end of file +go-drink +http-test-reports/ diff --git a/http-test/get-items-empty.http b/http-test/get-items-empty.http new file mode 100644 index 0000000..3861ce0 --- /dev/null +++ b/http-test/get-items-empty.http @@ -0,0 +1,19 @@ +GET {{godrink_url}}/items + +> {% + client.test("returns 200", () => { + client.assert(response.status === 200) + }) + + client.test("returns json", () => { + client.assert(response.contentType.mimeType === "application/json") + }) + + client.test("returns utf-8", () => { + client.assert(response.contentType.charset === "utf-8" || response.contentType.charset.length === 0) + }) + + client.test("returns empty array", () => { + client.assert(response.body.length === 0) + }) +%} diff --git a/http-test/get-noauth-users-empty.http b/http-test/get-noauth-users-empty.http new file mode 100644 index 0000000..4eb3593 --- /dev/null +++ b/http-test/get-noauth-users-empty.http @@ -0,0 +1,19 @@ +GET {{godrink_url}}/users/noauth + +> {% + client.test("returns 200", () => { + client.assert(response.status === 200) + }) + + client.test("returns json", () => { + client.assert(response.contentType.mimeType === "application/json") + }) + + client.test("returns utf-8", () => { + client.assert(response.contentType.charset === "utf-8" || response.contentType.charset.length === 0) + }) + + client.test("returns empty array", () => { + client.assert(response.body.length === 0) + }) +%} diff --git a/http-test/http-client.env.json b/http-test/http-client.env.json new file mode 100644 index 0000000..f9439d7 --- /dev/null +++ b/http-test/http-client.env.json @@ -0,0 +1,6 @@ +{ + "dev": { + "godrink_url": "http://localhost:8080" + } +} + diff --git a/http-test/post-logout-without-login.http b/http-test/post-logout-without-login.http new file mode 100644 index 0000000..4e08331 --- /dev/null +++ b/http-test/post-logout-without-login.http @@ -0,0 +1,12 @@ +POST {{godrink_url}}/logout + +> {% + client.test("returns 200", ()=>{ + client.assert(response.status === 200) + }) + + client.test("no body", () => { + client.assert(!response.body) + }) + +%} diff --git a/http-test/test.sh b/http-test/test.sh new file mode 100755 index 0000000..5bc7ba8 --- /dev/null +++ b/http-test/test.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set +e +while +(exec 6<>/dev/tcp/localhost/8080) 2>/dev/null +[ $? == 1 ] +do echo Waiting for Go Drink; sleep 1; done +set -e + +docker run --network="host" --rm -v $PWD:/workdir jetbrains/intellij-http-client -e dev -v http-test/http-client.env.json -r http-test-reports http-test/*.http