From 996ba31252a465079ba7328001aed6f8d7959257 Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava <37413698+PranshuSrivastava@users.noreply.github.com> Date: Wed, 6 Dec 2023 23:30:14 +0530 Subject: [PATCH] feat: Add ci tests to validate PR changes (#1176) * feat: added ci pipelline for testing gin-mongo Signed-off-by: Pranshu Srivastava * fix: updated location of the app Signed-off-by: Pranshu Srivastava * fix: updated Signed-off-by: Pranshu Srivastava * fix: updated keploy location Signed-off-by: Pranshu Srivastava * fix: updated test command Signed-off-by: Pranshu Srivastava * fix: updated keploy location Signed-off-by: Pranshu Srivastava * fix: updateed location Signed-off-by: Pranshu Srivastava * fix: removed eec Signed-off-by: Pranshu Srivastava * fix: updated the pid mechanism Signed-off-by: Pranshu Srivastava * fix: updated kill mechanism] Signed-off-by: Pranshu Srivastava * fix: fixed sudo error Signed-off-by: Pranshu Srivastava * feat: made async Signed-off-by: Pranshu Srivastava * fix: increased wait time Signed-off-by: Pranshu Srivastava * fix: added mongo Signed-off-by: Pranshu Srivastava * fix: removed keploy network Signed-off-by: Pranshu Srivastava * fix: inc sleep time Signed-off-by: Pranshu Srivastava * fix: changed the branch Signed-off-by: Pranshu Srivastava * fix: fixed branch issues Signed-off-by: Pranshu Srivastava * fix: updated the time Signed-off-by: Pranshu Srivastava * fix: updated the tijme Signed-off-by: Pranshu Srivastava * fix: checking if the application started or not Signed-off-by: Pranshu Srivastava * fix: added support for timestamp Signed-off-by: Pranshu Srivastava * fix: fixed status Signed-off-by: Pranshu Srivastava * fix: removed echo Signed-off-by: Pranshu Srivastava * feat: checking python workflow Signed-off-by: Pranshu Srivastava * fix: installed virtualenv before pushing Signed-off-by: Pranshu Srivastava * feat: added code to start keploy Signed-off-by: Pranshu Srivastava * fix: fixed sed Signed-off-by: Pranshu Srivastava * fix: fixed sed Signed-off-by: Pranshu Srivastava * fix: udpated keploy binary Signed-off-by: Pranshu Srivastava * fix: updated keploy location Signed-off-by: Pranshu Srivastava * fix: updated the repo Signed-off-by: Pranshu Srivastava * fix: added migrations Signed-off-by: Pranshu Srivastava * fix: added sleep time Signed-off-by: Pranshu Srivastava * fix: updated back to keploy Signed-off-by: Pranshu Srivastava * fix: removed virtualenv Signed-off-by: Pranshu Srivastava * fix: check the containers Signed-off-by: Pranshu Srivastava * fix: updated the config Signed-off-by: Pranshu Srivastava * fix: added back keploy Signed-off-by: Pranshu Srivastava * fix: removed keploy Signed-off-by: Pranshu Srivastava * fix: changed to fork Signed-off-by: Pranshu Srivastava * fix: now checking the logs Signed-off-by: Pranshu Srivastava * fix: checking on a diff portr Signed-off-by: Pranshu Srivastava * fix: just checking the logs now Signed-off-by: Pranshu Srivastava * fix: added keploy back Signed-off-by: Pranshu Srivastava * fix: not checking the logs Signed-off-by: Pranshu Srivastava * fix: checking if something is running on the port or not Signed-off-by: Pranshu Srivastava * fix: checking with telnet Signed-off-by: Pranshu Srivastava * fix: s Signed-off-by: Pranshu Srivastava * fix: somethign Signed-off-by: Pranshu Srivastava * fix: as Signed-off-by: Pranshu Srivastava * fix: asd Signed-off-by: Pranshu Srivastava * fix: asd Signed-off-by: Pranshu Srivastava * fix: updated endpoint Signed-off-by: Pranshu Srivastava * fix: removed telnet Signed-off-by: Pranshu Srivastava * fix: removed migrations Signed-off-by: Pranshu Srivastava * fix: changed starting of databse Signed-off-by: Pranshu Srivastava * fix: starting the server again Signed-off-by: Pranshu Srivastava * fix: checking docker containers Signed-off-by: Pranshu Srivastava * fix: added back pid Signed-off-by: Pranshu Srivastava * fix: added the logic for test Signed-off-by: Pranshu Srivastava * fix: added backward compatibility to the testcases Signed-off-by: Pranshu Srivastava * fix: removing keploy now Signed-off-by: Pranshu Srivastava * feat: added pipeline for node Signed-off-by: Pranshu Srivastava * fix: updated workflow file Signed-off-by: Pranshu Srivastava * fix: updated the docker container Signed-off-by: Pranshu Srivastava * fix: updated Signed-off-by: Pranshu Srivastava * feat: added java linux workflow Signed-off-by: Pranshu Srivastava * fix: updated location of the script Signed-off-by: Pranshu Srivastava * fix: checking java version Signed-off-by: Pranshu Srivastava * fix: updated java version Signed-off-by: Pranshu Srivastava * fix: updating apt Signed-off-by: Pranshu Srivastava * fix: just checking the application Signed-off-by: Pranshu Srivastava * fix: checking the installed java versions Signed-off-by: Pranshu Srivastava * fix: checking the directories Signed-off-by: Pranshu Srivastava * fix: updated java version Signed-off-by: Pranshu Srivastava * fix: starting with keploy now Signed-off-by: Pranshu Srivastava * fix: updated keploy location Signed-off-by: Pranshu Srivastava * fix: added 2 extra steps Signed-off-by: Pranshu Srivastava * fix: fixed indentation issues Signed-off-by: Pranshu Srivastava * fix: updated the workflow Signed-off-by: Pranshu Srivastava * fix: added update script Signed-off-by: Pranshu Srivastava * fix: updating the java version again Signed-off-by: Pranshu Srivastava * fix: added the code for keploy test mode as well Signed-off-by: Pranshu Srivastava * fix: just confirming where we are Signed-off-by: Pranshu Srivastava * fix: updated the location of the script Signed-off-by: Pranshu Srivastava * fix: increased the delay Signed-off-by: Pranshu Srivastava * fix: checking the testcases Signed-off-by: Pranshu Srivastava * fix: fixed location Signed-off-by: Pranshu Srivastava * feat: added postgres Signed-off-by: Pranshu Srivastava * fix: running in detached mode Signed-off-by: Pranshu Srivastava * fix: running in detached mode Signed-off-by: Pranshu Srivastava * feat: added java with docker Signed-off-by: Pranshu Srivastava * fix: changed to java docker Signed-off-by: Pranshu Srivastava * fix: added code to expand aliases Signed-off-by: Pranshu Srivastava * fix: stopped using aliases Signed-off-by: Pranshu Srivastava * fix: removed keploy alias Signed-off-by: Pranshu Srivastava * fix: starting keploy network Signed-off-by: Pranshu Srivastava * fix: removed detached mode Signed-off-by: Pranshu Srivastava * fix: removed interactiveness of the shell Signed-off-by: Pranshu Srivastava * fix: removed Home Signed-off-by: Pranshu Srivastava * feat: added support for golang docker Signed-off-by: Pranshu Srivastava * fix: removed using keplopy binary Signed-off-by: Pranshu Srivastava * fix: updated the command to start the applciation Signed-off-by: Pranshu Srivastava * fix: checming Signed-off-by: Pranshu Srivastava * fix: checking again Signed-off-by: Pranshu Srivastava * fix: checking if the file already exists or not Signed-off-by: Pranshu Srivastava * fix: sending y Signed-off-by: Pranshu Srivastava * fix: removing keploy-config before Signed-off-by: Pranshu Srivastava * fix: not checking out to a diff branch Signed-off-by: Pranshu Srivastava * fix: checking again Signed-off-by: Pranshu Srivastava * fix: building docker Signed-off-by: Pranshu Srivastava * fix: stopping keploy differently Signed-off-by: Pranshu Srivastava * fix: fixed test mode Signed-off-by: Pranshu Srivastava * fix: removing ginapp Signed-off-by: Pranshu Srivastava * feat: added support for python docker Signed-off-by: Pranshu Srivastava * fix: removed it Signed-off-by: Pranshu Srivastava * fix: specifying host Signed-off-by: Pranshu Srivastava * fix: checking logs Signed-off-by: Pranshu Srivastava * fix: checking the logs again Signed-off-by: Pranshu Srivastava * fix: checking logs again Signed-off-by: Pranshu Srivastava * fix: switched docker network Signed-off-by: Pranshu Srivastava * fix: not creating database Signed-off-by: Pranshu Srivastava * fix: updated docker run command Signed-off-by: Pranshu Srivastava * fix: comment added Signed-off-by: Pranshu Srivastava * fix: removed migrations Signed-off-by: Pranshu Srivastava * fix: added initialisation script Signed-off-by: Pranshu Srivastava * fix: made the path absolute Signed-off-by: Pranshu Srivastava * fix: absolute path Signed-off-by: Pranshu Srivastava * fix: inspecting the network Signed-off-by: Pranshu Srivastava * fix: using docker ps Signed-off-by: Pranshu Srivastava * fix: ps again Signed-off-by: Pranshu Srivastava * fix: checking logs Signed-off-by: Pranshu Srivastava * fix: checkj Signed-off-by: Pranshu Srivastava * fix: running detached again Signed-off-by: Pranshu Srivastava * fix: fixed test Signed-off-by: Pranshu Srivastava * fix: removing old keploy Signed-off-by: Pranshu Srivastava * fix: stopping before removing Signed-off-by: Pranshu Srivastava * fix: using rm -f Signed-off-by: Pranshu Srivastava * fix: checking again Signed-off-by: Pranshu Srivastava * fix: inc delay Signed-off-by: Pranshu Srivastava * fix: added node docker Signed-off-by: Pranshu Srivastava * fix: not using binary anymore Signed-off-by: Pranshu Srivastava * fix: removing preexisting testcases Signed-off-by: Pranshu Srivastava * fix: inc the delay Signed-off-by: Pranshu Srivastava * fix: checking logs Signed-off-by: Pranshu Srivastava * fix: check Signed-off-by: Pranshu Srivastava * fix: check Signed-off-by: Pranshu Srivastava * fix: check Signed-off-by: Pranshu Srivastava * fix: check Signed-off-by: Pranshu Srivastava * fix: only testing binaries Signed-off-by: Pranshu Srivastava * feat: added for loop Signed-off-by: Pranshu Srivastava * fix: using binary now Signed-off-by: Pranshu Srivastava * fix: checking both the results Signed-off-by: Pranshu Srivastava * fix: fixed Signed-off-by: Pranshu Srivastava * fix: checking update Signed-off-by: Pranshu Srivastava * fix: updated Signed-off-by: Pranshu Srivastava * fix: reverted some changes Signed-off-by: Pranshu Srivastava * fix: waiting before next iteration Signed-off-by: Pranshu Srivastava * fix: updated java Signed-off-by: Pranshu Srivastava * fix: updated go branch Signed-off-by: Pranshu Srivastava * fix: fixed location of script Signed-off-by: Pranshu Srivastava * fix: updated again Signed-off-by: Pranshu Srivastava * fix: updated python branch Signed-off-by: Pranshu Srivastava * fix: updated repo Signed-off-by: Pranshu Srivastava --------- Signed-off-by: Pranshu Srivastava Co-authored-by: Gourav kumar <44055698+gouravkrosx@users.noreply.github.com> Former-commit-id: 47d3de23877a91334e0bb14de5f41215d9382c50 --- .github/workflows/golang-linux.sh | 85 +++++++++++++++++++++++ .github/workflows/golang_linux.yml | 22 ++++++ .github/workflows/java-linux.sh | 77 +++++++++++++++++++++ .github/workflows/java_linux.yml | 34 ++++++++++ .github/workflows/node-linux.sh | 77 +++++++++++++++++++++ .github/workflows/node_linux.yml | 23 +++++++ .github/workflows/python-linux.sh | 104 +++++++++++++++++++++++++++++ .github/workflows/python_linux.yml | 21 ++++++ .github/workflows/update-java.sh | 6 ++ cmd/root.go | 22 +++--- pkg/service/test/test.go | 2 +- 11 files changed, 464 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/golang-linux.sh create mode 100644 .github/workflows/golang_linux.yml create mode 100644 .github/workflows/java-linux.sh create mode 100644 .github/workflows/java_linux.yml create mode 100644 .github/workflows/node-linux.sh create mode 100644 .github/workflows/node_linux.yml create mode 100644 .github/workflows/python-linux.sh create mode 100644 .github/workflows/python_linux.yml create mode 100644 .github/workflows/update-java.sh diff --git a/.github/workflows/golang-linux.sh b/.github/workflows/golang-linux.sh new file mode 100644 index 000000000..d43607c73 --- /dev/null +++ b/.github/workflows/golang-linux.sh @@ -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 \ No newline at end of file diff --git a/.github/workflows/golang_linux.yml b/.github/workflows/golang_linux.yml new file mode 100644 index 000000000..d4a46df87 --- /dev/null +++ b/.github/workflows/golang_linux.yml @@ -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 + diff --git a/.github/workflows/java-linux.sh b/.github/workflows/java-linux.sh new file mode 100644 index 000000000..2fd6a6455 --- /dev/null +++ b/.github/workflows/java-linux.sh @@ -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 \ No newline at end of file diff --git a/.github/workflows/java_linux.yml b/.github/workflows/java_linux.yml new file mode 100644 index 000000000..7462eebe0 --- /dev/null +++ b/.github/workflows/java_linux.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/node-linux.sh b/.github/workflows/node-linux.sh new file mode 100644 index 000000000..43af53748 --- /dev/null +++ b/.github/workflows/node-linux.sh @@ -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 diff --git a/.github/workflows/node_linux.yml b/.github/workflows/node_linux.yml new file mode 100644 index 000000000..babe52c30 --- /dev/null +++ b/.github/workflows/node_linux.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/python-linux.sh b/.github/workflows/python-linux.sh new file mode 100644 index 000000000..c5f9bec60 --- /dev/null +++ b/.github/workflows/python-linux.sh @@ -0,0 +1,104 @@ +#! /bin/bash + +# Checkout a different branch +git fetch origin +git checkout native-linux + +# Start the postgres database. +docker-compose up -d + +# Install the dependencies. +pip3 install -r requirements.txt + +# Set the environment variable for the app to run correctly. +export PYTHON_PATH=./venv/lib/python3.10/site-packages/django + +# Make the required migrations. +python3 manage.py makemigrations +python3 manage.py migrate + +# Generate the keploy-config file. +./../../../keployv2 generate-config + +#Clean any keploy folders. +sudo rm -rf keploy/ + +# Update the global noise to ignore the Allow header. +config_file="./keploy-config.yaml" +sed -i 's/"header": {}/"header":{"Allow":[]}/' "$config_file" + +# Wait for 5 seconds for it to complete +sleep 5 + +for i in {1..2}; do +# Start the django-postgres app in record mode and record testcases and mocks. +sudo -E env PATH="$PATH" ./../../../keployv2 record -c "python3 manage.py runserver" & + +# Wait for the application to start. +app_started=false +while [ "$app_started" = false ]; do + if curl --location 'http://127.0.0.1:8000/'; then + app_started=true + fi + sleep 3 # wait for 3 seconds before checking again. +done + +# Get the pid of keploy. +pid=$(pgrep keploy) + +# Start making curl calls to record the testcases and mocks. +curl --location 'http://127.0.0.1:8000/user/' \ +--header 'Content-Type: application/json' \ +--data-raw ' { + "name": "Jane Smith", + "email": "jane.smith@example.com", + "password": "smith567", + "website": "www.janesmith.com" + }' + +curl --location 'http://127.0.0.1:8000/user/' \ +--header 'Content-Type: application/json' \ +--data-raw ' { + "name": "John Doe", + "email": "john.doe@example.com", + "password": "john567", + "website": "www.johndoe.com" + }' + +curl --location 'http://127.0.0.1:8000/user/' + +curl --location 'http://127.0.0.1:8000/user/' \ +--header 'Content-Type: application/json' \ +--data-raw ' { + "name": "John Doe", + "email": "john.doe@example.com", + "password": "john567", + "website": "www.johndoe.com" + }' + +# 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 app in test mode. +sudo -E env PATH="$PATH" ./../../../keployv2 test -c "python3 manage.py runserver" --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 + diff --git a/.github/workflows/python_linux.yml b/.github/workflows/python_linux.yml new file mode 100644 index 000000000..74c15b103 --- /dev/null +++ b/.github/workflows/python_linux.yml @@ -0,0 +1,21 @@ +name: Python On Linux +on: [pull_request] +jobs: + python_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-python repository + uses: actions/checkout@v2 + with: + repository: keploy/samples-python + path: samples-python + - name: Run the sample python application + run: | + cd samples-python/django-postgres/django_postgres + source ../../../.github/workflows/python-linux.sh diff --git a/.github/workflows/update-java.sh b/.github/workflows/update-java.sh new file mode 100644 index 000000000..5955e9f29 --- /dev/null +++ b/.github/workflows/update-java.sh @@ -0,0 +1,6 @@ +#! /bin/bash + +# Update the java version +sudo apt update +sudo apt install openjdk-17-jre -y +export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 \ No newline at end of file diff --git a/cmd/root.go b/cmd/root.go index 50fb00e8e..32960c1cf 100755 --- a/cmd/root.go +++ b/cmd/root.go @@ -34,7 +34,7 @@ type colorConsoleEncoder struct { *zapcore.EncoderConfig zapcore.Encoder } - + func NewColorConsole(cfg zapcore.EncoderConfig) (enc zapcore.Encoder) { return colorConsoleEncoder{ EncoderConfig: &cfg, @@ -42,12 +42,12 @@ func NewColorConsole(cfg zapcore.EncoderConfig) (enc zapcore.Encoder) { Encoder: zapcore.NewConsoleEncoder(cfg), } } - + // EncodeEntry overrides ConsoleEncoder's EncodeEntry func (c colorConsoleEncoder) EncodeEntry(ent zapcore.Entry, fields []zapcore.Field) (buf *buffer.Buffer, err error) { buff, err := c.Encoder.EncodeEntry(ent, fields) // Utilize the existing implementation of zap if err != nil { - return nil, err + return nil, err } bytesArr := bytes.Replace(buff.Bytes(), []byte("\\u001b"), []byte("\u001b"), -1) @@ -68,12 +68,12 @@ func (c colorConsoleEncoder) Clone() zapcore.Encoder { func init() { _ = zap.RegisterEncoder("colorConsole", func(config zapcore.EncoderConfig) (zapcore.Encoder, error) { return NewColorConsole(config), nil - }) + }) } func setupLogger() *zap.Logger { logCfg := zap.NewDevelopmentConfig() - + logCfg.Encoding = "colorConsole" // Customize the encoder config to put the emoji at the beginning. @@ -84,7 +84,7 @@ func setupLogger() *zap.Logger { "stdout", "./keploy-logs.txt", } - + if debugMode { go func() { defer utils.HandlePanic() @@ -176,7 +176,7 @@ keploy record -c "docker run -p 8080:8080 --name --network keplo Test: keploy test --c "docker run -p 8080:8080 --name --network keploy-network " --delay 1 -Generate-Config: +Generate-Config: keploy generate-config -p "/path/to/localdir" ` @@ -190,7 +190,13 @@ func checkForDebugFlag(args []string) bool { } func deleteLogs(logger *zap.Logger) { - err := os.Remove("keploy-logs.txt") + //Check if keploy-log.txt exists + _, err := os.Stat("keploy-logs.txt") + if os.IsNotExist(err) { + return + } + //If it does, remove it. + err = os.Remove("keploy-logs.txt") if err != nil { logger.Error("Error removing log file: %v\n", zap.String("error", err.Error())) return diff --git a/pkg/service/test/test.go b/pkg/service/test/test.go index 6a634f8a3..faafd2f04 100755 --- a/pkg/service/test/test.go +++ b/pkg/service/test/test.go @@ -564,7 +564,7 @@ func (t *tester) RunTestSet(testSet, path, testReportPath, appCmd, appContainer, if tc.Version == "api.keploy-enterprise.io/v1beta1" { entTcs = append(entTcs, tc.Name) - } else if tc.Version != "api.keploy.io/v1beta1" { + } else if tc.Version != "api.keploy.io/v1beta1" && tc.Version != "api.keploy.io/v1beta2" { nonKeployTcs = append(nonKeployTcs, tc.Name) } select {