Skip to content

Commit

Permalink
Merge pull request #5 from LinuxSuRen/springboot-test
Browse files Browse the repository at this point in the history
add springboot inital code
  • Loading branch information
LinuxSuRen authored Dec 4, 2023
2 parents 4c7988c + b34c962 commit eb36a9e
Show file tree
Hide file tree
Showing 21 changed files with 786 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build

on:
- pull_request

jobs:
Build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Image
run: make build-image
- name: Run e2e
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_REQUEST: ${{ github.event.number }}
run: |
sudo curl -L https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod u+x /usr/local/bin/docker-compose
export OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')
make test-e2e
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
4 changes: 4 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vscode:
extensions:
- linuxsuren.api-testing
- vscjava.vscode-maven
Binary file added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM maven:3.9.5-sapmachine-17

WORKDIR /workspace
COPY . .

RUN mvn package

CMD [ "java", "-jar", "target/demo-0.0.1-SNAPSHOT.jar" ]
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build-image:
docker build . -t ghcr.io/devops-ws/learn-springboot:master
test-e2e:
cd e2e && ./start.sh
run-demo:
cd e2e && docker compose up server
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# learn-springboot
# learn-springboot
This project aims to verify [linuxsuren/api-testing](https://github.com/LinuxSuRen/api-testing).

Run E2E testing:

```shell
make build-image test-e2e
```
6 changes: 6 additions & 0 deletions e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM ghcr.io/linuxsuren/api-testing:master

WORKDIR /workspace
COPY . .

CMD [ "/workspace/entrypoint.sh" ]
25 changes: 25 additions & 0 deletions e2e/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3.1'
services:
testing:
build:
context: .
environment:
SERVER: http://server:8080
OWNER: "$OWNER"
GITHUB_TOKEN: "$GITHUB_TOKEN"
PULL_REQUEST: "$PULL_REQUEST"
depends_on:
server:
condition: service_healthy
links:
- server
server:
image: ghcr.io/devops-ws/learn-springboot:master
ports:
- 8080:8080
healthcheck:
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/8080"]
interval: 3s
timeout: 60s
retries: 10
start_period: 3s
18 changes: 18 additions & 0 deletions e2e/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e

mkdir -p /var/data

atest run -p test-suite.yaml --report md

# cannot get the token in a pr
# if [[ "$PULL_REQUEST" == "" || "$GITHUB_TOKEN" == "" ]];
# then
# atest run -p test-suite.yaml --report md
# else
# atest run -p test-suite.yaml --report github \
# --report-github-identity e2e-testing \
# --report-file /var/data/report.json \
# --report-github-repo ${OWNER:-devops-ws}/learn-springboot \
# --report-github-pr ${PULL_REQUEST:-0}
# fi
31 changes: 31 additions & 0 deletions e2e/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

file=$1
if [ "$file" == "" ]
then
file=compose.yaml
fi

docker-compose version
docker-compose -f "$file" up --build -d

while true
do
docker-compose -f "$file" ps | grep testing
if [ $? -eq 1 ]
then
code=-1
docker-compose -f "$file" logs | grep e2e-testing
docker-compose -f "$file" logs | grep e2e-testing | grep Usage
if [ $? -eq 1 ]
then
code=0
echo "successed"
fi

docker-compose -f "$file" down
set -e
exit $code
fi
sleep 1
done
19 changes: 19 additions & 0 deletions e2e/test-suite.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!api-testing
# yaml-language-server: $schema=https://linuxsuren.github.io/api-testing/api-testing-schema.json
name: SpringBoot
api: |
{{default "http://localhost:8080" (env "SERVER")}}
items:
- name: health
request:
api: /health
- name: toLowerWithoutParam
request:
api: /lower
expect:
statusCode: 400
- name: toLower
request:
api: /lower?text=Hello
expect:
body: hello
Loading

0 comments on commit eb36a9e

Please sign in to comment.