Skip to content

Commit

Permalink
feat: Add ci tests to validate PR changes (#1176)
Browse files Browse the repository at this point in the history
* feat: added ci pipelline for testing gin-mongo

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated location of the app

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated keploy location

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated test command

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated keploy location

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updateed location

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removed eec

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated the pid mechanism

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated kill mechanism]

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: fixed sudo error

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* feat: made async

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: increased wait time

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added mongo

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removed keploy network

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: inc sleep time

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: changed the branch

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: fixed branch issues

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated the time

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated the tijme

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking if the application started or not

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added support for timestamp

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: fixed status

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removed echo

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* feat: checking python workflow

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: installed virtualenv before pushing

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* feat: added code to start keploy

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: fixed sed

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: fixed sed

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: udpated keploy binary

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated keploy location

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated the repo

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added migrations

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added sleep time

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated back to keploy

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removed virtualenv

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: check the containers

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated the config

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added back keploy

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removed keploy

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: changed to fork

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: now checking the logs

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking on a diff portr

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: just checking the logs now

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added keploy back

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: not checking the logs

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking if something is running on the port or not

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking with telnet

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: s

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: somethign

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: as

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: asd

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: asd

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated endpoint

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removed telnet

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removed migrations

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: changed starting of databse

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: starting the server again

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking docker containers

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added back pid

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added the logic for test

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added backward compatibility to the testcases

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removing keploy now

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* feat: added pipeline for node

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated workflow file

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated the docker container

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* feat: added java linux workflow

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated location of the script

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking java version

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated java version

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updating apt

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: just checking the application

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking the installed java versions

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking the directories

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated java version

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: starting with keploy now

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated keploy location

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added 2 extra steps

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: fixed indentation issues

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated the workflow

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added update script

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updating the java version again

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added the code for keploy test mode as well

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: just confirming where we are

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated the location of the script

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: increased the delay

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking the testcases

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: fixed location

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* feat: added postgres

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: running in detached mode

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: running in detached mode

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* feat: added java with docker

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: changed to java docker

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added code to expand aliases

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: stopped using aliases

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removed keploy alias

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: starting keploy network

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removed detached mode

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removed interactiveness of the shell

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removed Home

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* feat: added support for golang docker

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removed using keplopy binary

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated the command to start the applciation

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checming

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking again

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking if the file already exists or not

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: sending y

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removing keploy-config before

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: not checking out to a diff branch

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking again

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: building docker

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: stopping keploy differently

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: fixed test mode

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removing ginapp

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* feat: added support for python docker

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removed it

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: specifying host

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking logs

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking the logs again

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking logs again

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: switched docker network

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: not creating database

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated docker run command

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: comment added

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removed migrations

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added initialisation script

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: made the path absolute

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: absolute path

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: inspecting the network

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: using docker ps

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: ps again

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking logs

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checkj

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: running detached again

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: fixed test

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removing old keploy

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: stopping before removing

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: using rm -f

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking again

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: inc delay

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: added node docker

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: not using binary anymore

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: removing preexisting testcases

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: inc the delay

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking logs

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: check

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: check

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: check

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: check

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: only testing binaries

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* feat: added for loop

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: using binary now

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking both the results

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: fixed

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: checking update

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: reverted some changes

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: waiting before next iteration

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated java

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated go branch

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: fixed location of script

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated again

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated python branch

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

* fix: updated repo

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>

---------

Signed-off-by: Pranshu Srivastava <iampranshu24@gmail.com>
Co-authored-by: Gourav kumar <44055698+gouravkrosx@users.noreply.github.com>
  • Loading branch information
PranshuSrivastava and gouravkrosx committed Dec 6, 2023
1 parent 3f78251 commit 47d3de2
Show file tree
Hide file tree
Showing 11 changed files with 464 additions and 9 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/golang-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

# Checkout a different branch
git fetch origin
git checkout native-linux

# Start mongo before starting keploy.
docker run --rm -d -p27017:27017 --name mongoDb mongo

# Check if there is a keploy-config file, if there is, delete it.
if [ -f "./keploy-config.yaml" ]; then
rm ./keploy-config.yaml
fi

# Generate the keploy-config file.
./../../keployv2 generate-config

# Update the global noise to ts.
config_file="./keploy-config.yaml"
sed -i 's/"body": {}/"body": {"ts":[]}/' "$config_file"

# Remove any preexisting keploy tests and mocks.
sudo rm -rf keploy/

# Build the binary.
go build -o ginApp

for i in {1..2}; do
# Start the gin-mongo app in record mode and record testcases and mocks.
sudo -E env PATH="$PATH" ./../../keployv2 record -c "./ginApp" &

# Wait for the application to start.
app_started=false
while [ "$app_started" = false ]; do
if curl -X GET http://localhost:8080/CJBKJd92; then
app_started=true
fi
sleep 3 # wait for 3 seconds before checking again.
done

# Get the pid of the application.
pid=$(pgrep keploy)

# Start making curl calls to record the testcases and mocks.
curl --request POST \
--url http://localhost:8080/url \
--header 'content-type: application/json' \
--data '{
"url": "https://google.com"
}'

curl --request POST \
--url http://localhost:8080/url \
--header 'content-type: application/json' \
--data '{
"url": "https://facebook.com"
}'

curl -X GET http://localhost:8080/CJBKJd92

# Wait for 5 seconds for keploy to record the tcs and mocks.
sleep 5

# Stop the gin-mongo app.
sudo kill $pid

# Wait for 5 seconds for keploy to stop.
sleep 5
done

# Start the gin-mongo app in test omde.
sudo -E env PATH="$PATH" ./../../keployv2 test -c "./ginApp" --delay 7

# Get the test results from the testReport file.
report_file="./keploy/testReports/report-1.yaml"
test_status1=$(grep 'status:' "$report_file" | head -n 1 | awk '{print $2}')
report_file2="./keploy/testReports/report-2.yaml"
test_status2=$(grep 'status:' "$report_file2" | head -n 1 | awk '{print $2}')

# Return the exit code according to the status.
if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ]; then
exit 0
else
exit 1
fi
22 changes: 22 additions & 0 deletions .github/workflows/golang_linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Golang On Linux
on: [pull_request]
jobs:
golang_linux:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Build binary
run: |
go build -o keployv2
- name: Checkout the samples-go repository
uses: actions/checkout@v2
with:
repository: keploy/samples-go
path: samples-go
- name: Run samples-go application
run: |
cd samples-go/gin-mongo
source ./../../.github/workflows/golang-linux.sh
77 changes: 77 additions & 0 deletions .github/workflows/java-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#! /bin/bash

# Start postgres instance.
docker run -d -e POSTGRES_USER=petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES_DB=petclinic -p 5432:5432 postgres:15.2

# Update the java version
source ./../../../.github/workflows/update-java.sh

# Remove any existing test and mocks by keploy.
sudo rm -rf keploy/

for i in {1..2}; do
# Start keploy in record mode.
sudo -E env PATH=$PATH ./../../../keployv2 record -c './mvnw spring-boot:run' &

# Wait for the application to start.
app_started=false
while [ "$app_started" = false ]; do
if curl -X GET http://localhost:9966/petclinic/api/pettypes; then
app_started=true
fi
sleep 3 # wait for 3 seconds before checking again.
done

# Get the pid of the application.
pid=$(pgrep keploy)

# Start making curl calls to record the testcases and mocks.
curl -X GET http://localhost:9966/petclinic/api/pettypes

curl --request POST \
--url http://localhost:9966/petclinic/api/pettypes \
--header 'content-type: application/json' \
--data '{
"name":"John Doe"}'

curl -X GET http://localhost:9966/petclinic/api/pettypes

curl --request POST \
--url http://localhost:9966/petclinic/api/pettypes \
--header 'content-type: application/json' \
--data '{
"name":"Alice Green"}'

curl -X GET http://localhost:9966/petclinic/api/pettypes

curl --request DELETE \
--url http://localhost:9966/petclinic/api/pettypes/1

curl -X GET http://localhost:9966/petclinic/api/pettypes

# Wait for 5 seconds for keploy to record the tcs and mocks.
sleep 5

# Stop keploy.
sudo kill $pid

# Wait for 5 seconds for keploy to stop.
sleep 5

done

# Start keploy in test mode.
sudo -E env PATH=$PATH ./../../../keployv2 test -c './mvnw spring-boot:run' --delay 20

# Get the test results from the testReport file.
report_file="./keploy/testReports/report-1.yaml"
test_status1=$(grep 'status:' "$report_file" | head -n 1 | awk '{print $2}')
report_file2="./keploy/testReports/report-2.yaml"
test_status2=$(grep 'status:' "$report_file2" | head -n 1 | awk '{print $2}')

# Return the exit code according to the status.
if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ]; then
exit 0
else
exit 1
fi
34 changes: 34 additions & 0 deletions .github/workflows/java_linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Java on Linux
on: [pull_request]
jobs:
java_linux:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Build Keploy binary
run: |
go build -o keployv2
- name: Checkout samples-java repository
uses: actions/checkout@v2
with:
repository: keploy/samples-java
path: samples-java

- name: Installing the necessary dependencies
run: |
cd samples-java/spring-petclinic/spring-petclinic-rest
./mvnw dependency:resolve
- name: Compile the project
run: |
cd samples-java/spring-petclinic/spring-petclinic-rest
source ./../../../.github/workflows/update-java.sh
./mvnw compile
- name: Run the spring-petclinic-rest app
run: |
cd samples-java/spring-petclinic/spring-petclinic-rest
source ./../../../.github/workflows/java-linux.sh
77 changes: 77 additions & 0 deletions .github/workflows/node-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#! /bin/bash

# Start the docker container.
sudo docker run --name mongoDb --rm -p 27017:27017 -d mongo

# Install the required node dependencies.
npm install

# Edit the connection.js file to connect to local mongodb.
file_path="src/db/connection.js"
sed -i "s/mongoDb:27017/localhost:27017/" "$file_path"

# Remove any preexisting keploy tests.
sudo rm -rf keploy/

for i in {1..2}; do
# Start keploy in record mode.
sudo -E env PATH=$PATH ./../../keployv2 record -c 'node src/app.js' &

# Wait for the application to start.
app_started=false
while [ "$app_started" = false ]; do
if curl -X GET http://localhost:8000/students; then
app_started=true
fi
sleep 3 # wait for 3 seconds before checking again.
done

# Get the pid of the application.
pid=$(pgrep keploy)

# Start making curl calls to record the testcases and mocks.
curl --request POST \
--url http://localhost:8000/students \
--header 'content-type: application/json' \
--data '{
"name":"John Do",
"email":"john@xyiz.com",
"phone":"0123456799"
}'

curl --request POST \
--url http://localhost:8000/students \
--header 'content-type: application/json' \
--data '{
"name":"Alice Green",
"email":"green@alice.com",
"phone":"3939201584"
}'

curl -X GET http://localhost:8000/students

# Wait for 5 seconds for keploy to record the tcs and mocks.
sleep 5

# Stop keploy.
sudo kill $pid

# Wait for 5 seconds for keploy to stop.
sleep 5
done

# Start keploy in test mode.
sudo -E env PATH=$PATH ./../../keployv2 test -c 'node src/app.js' --delay 10

# Get the test results from the testReport file.
report_file="./keploy/testReports/report-1.yaml"
test_status1=$(grep 'status:' "$report_file" | head -n 1 | awk '{print $2}')
report_file2="./keploy/testReports/report-2.yaml"
test_status2=$(grep 'status:' "$report_file2" | head -n 1 | awk '{print $2}')

# Return the exit code according to the status.
if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ]; then
exit 0
else
exit 1
fi
23 changes: 23 additions & 0 deletions .github/workflows/node_linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Node on Linux
on: [pull_request]
jobs:
node_linux:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Build Keploy binary
run: |
go build -o keployv2
- name: Checkout samples-typescript repository
uses: actions/checkout@v2
with:
repository: keploy/samples-typescript
path: samples-typescript

- name: Run the express-mongoose app
run: |
cd samples-typescript/express-mongoose
source ./../../.github/workflows/node-linux.sh
Loading

0 comments on commit 47d3de2

Please sign in to comment.