Skip to content

Commit

Permalink
Merge branch 'coverage'
Browse files Browse the repository at this point in the history
  • Loading branch information
EraKin575 committed Jan 25, 2024
2 parents 51f0457 + 9fd60c0 commit b310711
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 241 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golang-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ]; then
exit 0
else
exit 1
fi
fi
116 changes: 58 additions & 58 deletions .github/workflows/node-linux.sh
Original file line number Diff line number Diff line change
@@ -1,103 +1,103 @@
#! /bin/bash

source ./../../.github/workflows/test_workflow_scripts/test-iid.sh
# Checkout a different branch
git fetch origin
git checkout native-linux

# Start the docker container.
docker run --name mongoDb --rm -p 27017:27017 -d mongo
# Start the postgres database.
docker-compose up -d

# Install the required node dependencies.
npm install
# Install the dependencies.
pip3 install -r requirements.txt

# 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"
# Set the environment variable for the app to run correctly.
export PYTHON_PATH=./venv/lib/python3.10/site-packages/django

# Remove any preexisting keploy tests.
rm -rf keploy/
# 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 keploy in record mode.
sudo -E env PATH=$PATH ./../../keployv2 record -c 'npm start' &
# 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 -X GET http://localhost:8000/students; then
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 the application.
# Get the pid of keploy.
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 --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 --request POST \
--url http://localhost:8000/students \
--header 'content-type: application/json' \
--data '{
"name":"Alice Green",
"email":"green@alice.com",
"phone":"3939201584"
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 -X GET http://localhost:8000/students
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 keploy.
# Stop the gin-mongo app.
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 'npm start' --delay 10

sudo -E env PATH=$PATH ./../../keployv2 serve -c "npm test" --delay 5

sudo -E env PATH=$PATH ./../../keployv2 test -c 'npm start' --delay 10 --testsets test-set-0

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

# Update the global noise to ts.
config_file="./keploy-config.yaml"
sed -i '/tests:/a \ "test-set-0": ["test-1", "test-2"]' "$config_file"


sudo -E env PATH=$PATH ./../../keployv2 test -c 'npm start' --apiTimeout 30 --delay 10
# 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/test-run-1/report-1.yaml"
test_status1=$(grep 'status:' "$report_file" | head -n 1 | awk '{print $2}')
report_file2="./keploy/testReports/test-run-1/report-2.yaml"
test_status2=$(grep 'status:' "$report_file2" | head -n 1 | awk '{print $2}')
report_file3="./keploy/testReports/test-run-2/report-1.yaml"
test_status3=$(grep 'status:' "$report_file3" | head -n 1 | awk '{print $2}')
report_file4="./keploy/testReports/test-run-2/report-2.yaml"
test_status4=$(grep 'status:' "$report_file4" | head -n 1 | awk '{print $2}')
report_file5="./keploy/testReports/test-run-3/report-1.yaml"
test_status5=$(grep 'status:' "$report_file5" | head -n 1 | awk '{print $2}')
report_file6="./keploy/testReports/test-run-4/report-1.yaml"
test_status6=$(grep 'status:' "$report_file6" | head -n 1 | awk '{print $2}')
test_total6=$(grep 'total:' "$report_file6" | head -n 1 | awk '{print $2}')
test_failure=$(grep 'failure:' "$report_file6" | head -n 1 | awk '{print $2}')

# Return the exit code according to the status.
if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ] && [ "$test_status3" = "PASSED" ] && [ "$test_status4" = "PASSED" ] && [ "$test_status5" = "PASSED" ] && [ "$test_status6" = "PASSED" ] && [ "$test_total6" = "2" ] && [ "$test_failure" = "0" ]; then
if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ]; then
exit 0
else
exit 1
fi
fi
3 changes: 1 addition & 2 deletions .github/workflows/python-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,4 @@ if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ]; then
exit 0
else
exit 1
fi

fi
2 changes: 1 addition & 1 deletion .github/workflows/test_workflow_scripts/node-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ]; then
exit 0
else
exit 1
fi
fi
3 changes: 1 addition & 2 deletions .github/workflows/test_workflow_scripts/python-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,4 @@ if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ]; then
exit 0
else
exit 1
fi

fi
1 change: 0 additions & 1 deletion .github/workflows/test_workflow_scripts/python-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,3 @@ if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ]; then
else
exit 1
fi

152 changes: 0 additions & 152 deletions cmd/serve.go

This file was deleted.

12 changes: 5 additions & 7 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ func (t *Test) GetCmd() *cobra.Command {
path += "/keploy"

testReportPath := path + "/testReports"

testReportPath, err = pkg.GetNextTestReportDir(testReportPath, models.TestRunTemplateName)
subDirPrefix := "test-report-"
testReportPath, err = pkg.GetNextTestReportDir(testReportPath, subDirPrefix)
if err != nil {
t.logger.Error("failed to get the next test report directory", zap.Error(err))
return err
Expand Down Expand Up @@ -280,7 +280,7 @@ func (t *Test) GetCmd() *cobra.Command {
}
t.logger.Debug("the configuration for mocking mongo connection", zap.Any("password", mongoPassword))

if !t.tester.Test(path, testReportPath, appCmd, test.TestOptions{
t.tester.Test(path, testReportPath, appCmd, test.TestOptions{
Tests: tests,
AppContainer: appContainer,
AppNetwork: networkName,
Expand All @@ -294,9 +294,7 @@ func (t *Test) GetCmd() *cobra.Command {
TestsetNoise: testsetNoise,
WithCoverage: withCoverage,
CoverageReportPath: coverageReportPath,
}, enableTele) {
os.Exit(1)
}
}, enableTele)

return nil
},
Expand Down Expand Up @@ -336,4 +334,4 @@ func (t *Test) GetCmd() *cobra.Command {
testCmd.SilenceErrors = true

return testCmd
}
}
Loading

0 comments on commit b310711

Please sign in to comment.