Skip to content

Commit

Permalink
Merge branch 'main' into Fix-keploy#1640
Browse files Browse the repository at this point in the history
  • Loading branch information
Tushar-kalsi committed Apr 29, 2024
2 parents 11dd50f + 7e6c138 commit b1ee858
Show file tree
Hide file tree
Showing 281 changed files with 19,083 additions and 17,178 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/--documentation-update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ labels: [Documentation]
body:
- type: markdown
attributes:
value: Thank you for taking the time to file a Documentation update.
value: Thank you for taking the time to file a Documentation tools.
- type: textarea
attributes:
label: What do you want to add to the docs? (please state reasons if any)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3.1.1
uses: sigstore/cosign-installer@v3.4.0


# Workaround: https://github.com/docker/build-push-action/issues/461
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: stefanbuck/github-issue-parser@v3
id: issue-parser
with:
template-path: .github/ISSUE_TEMPLATE/--documentation-update.yaml
template-path: .github/ISSUE_TEMPLATE/--documentation-tools.yaml

- name: Set labels based on repository field
uses: redhat-plumbers-in-action/advanced-issue-labeler@v2
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/golang_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ jobs:

- name: Build docker image
run: |
docker build -t keployv2 .
docker image build -t ghcr.io/keploy/keploy:v2-dev .
- name: Build binary
run: |
go build -o keployv2
- name: Checkout the samples-go repository
uses: actions/checkout@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ jobs:

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true

args: --out-format=colored-line-number
# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
install-mode: "goinstall"
6 changes: 4 additions & 2 deletions .github/workflows/node_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ jobs:

- name: Build docker image
run: |
docker build -t keployv2 .
docker image build -t ghcr.io/keploy/keploy:v2-dev .
- name: Build binary
run: |
go build -o keployv2
- name: Checkout samples-typescript repository
uses: actions/checkout@v2
with:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/python_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ jobs:

- name: Build docker image
run: |
docker build -t keployv2 .
docker image build -t ghcr.io/keploy/keploy:v2-dev .
- name: Build binary
run: |
go build -o keployv2
- name: Checkout the samples-python repository
uses: actions/checkout@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sample-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: "1.20"
go-version: "1.21"

- name: Build Keploy
run: |
Expand Down
90 changes: 48 additions & 42 deletions .github/workflows/test_workflow_scripts/golang-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,73 @@ docker network create keploy-network
docker run --name mongoDb --rm --net keploy-network -p 27017:27017 -d mongo

# Generate the keploy-config file.
docker run --name keploy-v2 -p 16789:16789 --privileged --pid=host -v $(pwd):$(pwd) -w $(pwd) -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock --rm keployv2 generate-config
sudo -E env PATH=$PATH ./../../keployv2 config --generate

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

# Remove any preexisting keploy tests and mocks.
rm -rf keploy/
sudo rm -rf keploy/
docker logs mongoDb &

# Start keploy in record mode.
docker build -t gin-mongo .
for i in {1..2}; do
docker run --name keploy-v2 -p 16789:16789 --privileged --pid=host -v $(pwd):$(pwd) -w $(pwd) -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock --rm keployv2 record -c 'docker run -p8080:8080 --net keploy-network --rm --name ginApp gin-mongo' &

# 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
docker rm -f ginApp 2>/dev/null || true

# 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 keploy.
docker stop keploy-v2
docker stop ginApp
for i in {1..2}; do
container_name="ginApp_${i}"
sudo -E env PATH=$PATH ./../../keployv2 record -c "docker run -p8080:8080 --net keploy-network --rm --name ${container_name} gin-mongo" --containerName "${container_name}" --generateGithubActions=false &

sleep 5

# 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

# 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 keploy.
docker rm -f keploy-v2
docker rm -f "${container_name}"
done

# Start the keploy in test mode.
docker run --name keploy-v2 -p 16789:16789 --privileged --pid=host -v $(pwd):$(pwd) -w $(pwd) -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock --rm keployv2 test -c 'docker run -p8080:8080 --net keploy-network --name ginApp gin-mongo' --apiTimeout 60 --delay 10
sudo -E env PATH=$PATH ./../../keployv2 test -c 'docker run -p8080:8080 --net keploy-network --name ginApp_test gin-mongo' --containerName "ginApp_test" --apiTimeout 60 --delay 20 --generateGithubActions=false
docker rm -f ginApp_test

# Get the test results from the testReport file.
report_file="./keploy/testReports/test-run-1/report-1.yaml"
report_file="./keploy/reports/test-run-0/test-set-0-report.yaml"
test_status1=$(grep 'status:' "$report_file" | head -n 1 | awk '{print $2}')
report_file2="./keploy/testReports/test-run-1/report-2.yaml"
report_file2="./keploy/reports/test-run-0/test-set-1-report.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
fi
34 changes: 17 additions & 17 deletions .github/workflows/test_workflow_scripts/golang-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ git checkout native-linux
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
if [ -f "./keploy.yml" ]; then
rm ./keploy.yml
fi

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

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

sed -i 's/ports: 0/ports: 27017/' "$config_file"

Expand All @@ -31,7 +31,7 @@ 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" &
sudo -E env PATH="$PATH" ./../../keployv2 record -c "./ginApp" --generateGithubActions=false &

# Wait for the application to start.
app_started=false
Expand Down Expand Up @@ -81,24 +81,24 @@ sleep 5
done

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

# move keployv2 to /usr/local/bin/keploy
mv ./../../keployv2 /usr/local/bin/keploy
# # move keployv2 to /usr/local/bin/keploy
# mv ./../../keployv2 /usr/local/bin/keploy

sed -i 's/<path for storing stubs>/\/home\/runner\/work\/keploy\/keploy\/samples-go\/gin-mongo/' main_test.go
# sed -i 's/<path for storing stubs>/\/home\/runner\/work\/keploy\/keploy\/samples-go\/gin-mongo/' main_test.go

# run in mockrecord mode
go test
# # run in mockrecord mode
# go test

sed -i 's/MOCK_RECORD/MOCK_TEST/' main_test.go
# run in mocktest mode
go test
# sed -i 's/MOCK_RECORD/MOCK_TEST/' main_test.go
# # run in mocktest mode
# go test

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

# Return the exit code according to the status.
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test_workflow_scripts/java-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ docker exec mypostgres psql -U petclinic -d petclinic -f /initDB.sql
for i in {1..2}; do
# Start keploy in record mode.
mvn clean install -Dmaven.test.skip=true
sudo -E env PATH=$PATH ./../../../keployv2 record -c 'java -jar target/spring-petclinic-rest-3.0.2.jar' &
sudo -E env PATH=$PATH ./../../../keployv2 record -c 'java -jar target/spring-petclinic-rest-3.0.2.jar' --generateGithubActions=false &

# Wait for the application to start.
app_started=false
Expand Down Expand Up @@ -72,12 +72,12 @@ sleep 5
done

# Start keploy in test mode.
sudo -E env PATH=$PATH ./../../../keployv2 test -c 'java -jar target/spring-petclinic-rest-3.0.2.jar' --delay 20
sudo -E env PATH=$PATH ./../../../keployv2 test -c 'java -jar target/spring-petclinic-rest-3.0.2.jar' --delay 20 --generateGithubActions=false

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

# Return the exit code according to the status.
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test_workflow_scripts/node-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ docker build -t node-app:1.0 .

for i in {1..2}; do
# Start keploy in record mode.
docker run --name keploy-v2 -p 16789:16789 --privileged --pid=host -v $(pwd):$(pwd) -w $(pwd) -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock --rm keployv2 record -c "docker run -p 8000:8000 --name nodeMongoApp --network keploy-network node-app:1.0" --containerName nodeMongoApp &
sudo -E env PATH=$PATH ./../../keployv2 record -c "docker run -p 8000:8000 --name nodeMongoApp --network keploy-network node-app:1.0" --containerName nodeMongoApp --generateGithubActions=false &

# Wait for the application to start.
app_started=false
Expand Down Expand Up @@ -55,12 +55,12 @@ docker rm -f nodeMongoApp
done

# Start keploy in test mode.
docker run --name keploy-v2 -p 16789:16789 --privileged --pid=host -v $(pwd):$(pwd) -w $(pwd) -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock --rm keployv2 test -c "docker run -p 8000:8000 --name nodeMongoApp --network keploy-network node-app:1.0" --containerName nodeMongoApp --apiTimeout 30 --delay 30
sudo -E env PATH=$PATH ./../../keployv2 test -c "docker run -p 8000:8000 --name nodeMongoApp --network keploy-network node-app:1.0" --containerName nodeMongoApp --apiTimeout 30 --delay 30 --generateGithubActions=false

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

# Return the exit code according to the status.
Expand Down
42 changes: 23 additions & 19 deletions .github/workflows/test_workflow_scripts/node-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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.
# Edit the conn.js file to connect to local mongodb.
file_path="src/db/connection.js"
sed -i "s/mongoDb:27017/localhost:27017/" "$file_path"

Expand All @@ -17,7 +17,7 @@ rm -rf keploy/

for i in {1..2}; do
# Start keploy in record mode.
sudo -E env PATH=$PATH ./../../keployv2 record -c 'npm start' &
sudo -E env PATH=$PATH ./../../keployv2 record -c 'npm start' --generateGithubActions=false &

# Wait for the application to start.
app_started=false
Expand Down Expand Up @@ -63,40 +63,44 @@ 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 test -c 'npm start' --delay 10 --generateGithubActions=false

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

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

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

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


sudo -E env PATH=$PATH ./../../keployv2 test -c 'npm start' --apiTimeout 30 --delay 10
sudo -E env PATH=$PATH ./../../keployv2 test -c 'npm start' --apiTimeout 30 --delay 10 --generateGithubActions=false

# Get the test results from the testReport file.
report_file="./keploy/testReports/test-run-1/report-1.yaml"
report_file="./keploy/reports/test-run-0/test-set-0-report.yaml"
test_status1=$(grep 'status:' "$report_file" | head -n 1 | awk '{print $2}')
report_file2="./keploy/testReports/test-run-1/report-2.yaml"
report_file2="./keploy/reports/test-run-0/test-set-1-report.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"
# report_file3="./keploy/reports/test-run-1/report-1.yaml"
# test_status3=$(grep 'status:' "$report_file3" | head -n 1 | awk '{print $2}')
# report_file4="./keploy/reports/test-run-1/report-2.yaml"
# test_status4=$(grep 'status:' "$report_file4" | head -n 1 | awk '{print $2}')
report_file5="./keploy/reports/test-run-1/test-set-0-report.yaml"
test_status5=$(grep 'status:' "$report_file5" | head -n 1 | awk '{print $2}')
report_file6="./keploy/testReports/test-run-4/report-1.yaml"
report_file6="./keploy/reports/test-run-2/test-set-0-report.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" ] && [ "$test_status3" = "PASSED" ] && [ "$test_status4" = "PASSED" ] && [ "$test_status5" = "PASSED" ] && [ "$test_status6" = "PASSED" ] && [ "$test_total6" = "2" ] && [ "$test_failure" = "0" ]; then
# exit 0
# else
# exit 1
# fi
if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ] && [ "$test_status5" = "PASSED" ] && [ "$test_status6" = "PASSED" ] && [ "$test_total6" = "2" ] && [ "$test_failure" = "0" ]; then
exit 0
else
exit 1
Expand Down

0 comments on commit b1ee858

Please sign in to comment.