Skip to content

Commit

Permalink
test: test http-requests via intellij http-client and run in github
Browse files Browse the repository at this point in the history
action
  • Loading branch information
hpr1999 committed Aug 3, 2024
1 parent f980bbf commit 761e75c
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ on:
- "docker-compose.yaml"
- "docker-compose.dev.yaml"
- "openapi.yaml"
- ".run"
- "http-test"
jobs:
docker:
runs-on: ubuntu-latest
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/http-test.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- name: Setup Go
uses: actions/[email protected]
- 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/[email protected]
with:
name: http-test-reports
path: ./http-test-reports/report.xml
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
go-drink.iml
go-drink
go-drink
http-test-reports/
19 changes: 19 additions & 0 deletions http-test/get-items-empty.http
Original file line number Diff line number Diff line change
@@ -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)
})
%}
19 changes: 19 additions & 0 deletions http-test/get-noauth-users-empty.http
Original file line number Diff line number Diff line change
@@ -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)
})
%}
6 changes: 6 additions & 0 deletions http-test/http-client.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dev": {
"godrink_url": "http://localhost:8080"
}
}

12 changes: 12 additions & 0 deletions http-test/post-logout-without-login.http
Original file line number Diff line number Diff line change
@@ -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)
})

%}
10 changes: 10 additions & 0 deletions http-test/test.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 761e75c

Please sign in to comment.