diff --git a/.github/workflows/golang-linux.sh b/.github/workflows/golang-linux.sh index 41f0fd0a0..c18271078 100644 --- a/.github/workflows/golang-linux.sh +++ b/.github/workflows/golang-linux.sh @@ -82,4 +82,4 @@ if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ]; then exit 0 else exit 1 -fi \ No newline at end of file +fi diff --git a/.github/workflows/node-linux.sh b/.github/workflows/node-linux.sh index 64e3447bb..218f3d031 100755 --- a/.github/workflows/node-linux.sh +++ b/.github/workflows/node-linux.sh @@ -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 \ No newline at end of file diff --git a/.github/workflows/python-linux.sh b/.github/workflows/python-linux.sh index 785246401..218f3d031 100644 --- a/.github/workflows/python-linux.sh +++ b/.github/workflows/python-linux.sh @@ -100,5 +100,4 @@ if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ]; then exit 0 else exit 1 -fi - +fi \ No newline at end of file diff --git a/.github/workflows/test_workflow_scripts/node-docker.sh b/.github/workflows/test_workflow_scripts/node-docker.sh index 66aa5e2a4..ae0f51848 100755 --- a/.github/workflows/test_workflow_scripts/node-docker.sh +++ b/.github/workflows/test_workflow_scripts/node-docker.sh @@ -68,4 +68,4 @@ if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ]; then exit 0 else exit 1 -fi +fi \ No newline at end of file diff --git a/.github/workflows/test_workflow_scripts/python-docker.sh b/.github/workflows/test_workflow_scripts/python-docker.sh index 8a31d5b83..d2e8625fd 100755 --- a/.github/workflows/test_workflow_scripts/python-docker.sh +++ b/.github/workflows/test_workflow_scripts/python-docker.sh @@ -67,5 +67,4 @@ if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ]; then exit 0 else exit 1 -fi - +fi \ No newline at end of file diff --git a/.github/workflows/test_workflow_scripts/python-linux.sh b/.github/workflows/test_workflow_scripts/python-linux.sh index 69fb3488c..c636b4b28 100755 --- a/.github/workflows/test_workflow_scripts/python-linux.sh +++ b/.github/workflows/test_workflow_scripts/python-linux.sh @@ -103,4 +103,3 @@ if [ "$test_status1" = "PASSED" ] && [ "$test_status2" = "PASSED" ]; then else exit 1 fi - diff --git a/cmd/serve.go b/cmd/serve.go deleted file mode 100644 index e43c15459..000000000 --- a/cmd/serve.go +++ /dev/null @@ -1,152 +0,0 @@ -package cmd - -import ( - "os" - "path/filepath" - - "github.com/spf13/cobra" - "go.keploy.io/server/pkg" - "go.keploy.io/server/pkg/models" - "go.keploy.io/server/pkg/service/serve" - "go.uber.org/zap" -) - -func NewCmdServe(logger *zap.Logger) *Serve { - server := serve.NewServer(logger) - return &Serve{ - server: server, - logger: logger, - } -} - -type Serve struct { - server serve.Server - logger *zap.Logger -} - -func (s *Serve) GetCmd() *cobra.Command { - var serveCmd = &cobra.Command{ - Use: "serve", - Short: "run the keploy server to expose test apis", - Run: func(cmd *cobra.Command, args []string) { - - path, err := cmd.Flags().GetString("path") - if err != nil { - s.logger.Error("failed to read the testcase path input") - return - } - - //if user provides relative path - if len(path) > 0 && path[0] != '/' { - absPath, err := filepath.Abs(path) - if err != nil { - s.logger.Error("failed to get the absolute path from relative path", zap.Error(err)) - return - } - path = absPath - } else if len(path) == 0 { // if user doesn't provide any path - cdirPath, err := os.Getwd() - if err != nil { - s.logger.Error("failed to get the path of current directory", zap.Error(err)) - } - path = cdirPath - } else { - // user provided the absolute path - s.logger.Debug("", zap.Any("testPath", path)) - } - - path += "/keploy" - - testReportPath := path + "/testReports" - - testReportPath, err = pkg.GetNextTestReportDir(testReportPath, models.TestRunTemplateName) - if err != nil { - s.logger.Error("failed to get the next test report directory", zap.Error(err)) - return - } - - s.logger.Info("", zap.Any("keploy test and mock path", path), zap.Any("keploy testReport path", testReportPath)) - - delay, err := cmd.Flags().GetUint64("delay") - - if err != nil { - s.logger.Error("Failed to get the delay flag", zap.Error((err))) - return - } - - pid, err := cmd.Flags().GetUint32("pid") - - if err != nil { - s.logger.Error("Failed to get the pid of the application", zap.Error((err))) - return - } - - apiTimeout, err := cmd.Flags().GetUint64("apiTimeout") - if err != nil { - s.logger.Error("Failed to get the apiTimeout flag", zap.Error((err))) - } - - port, err := cmd.Flags().GetUint32("port") - - if err != nil { - s.logger.Error("Failed to get the port of keploy server", zap.Error((err))) - return - } - appCmd, err := cmd.Flags().GetString("command") - - if err != nil { - s.logger.Error("Failed to get the command to run the user application", zap.Error((err))) - } - language, err := cmd.Flags().GetString("language") - if err != nil { - s.logger.Error("failed to read the programming language") - return - } - ports, err := cmd.Flags().GetUintSlice("passThroughPorts") - if err != nil { - s.logger.Error("failed to read the ports of outgoing calls to be ignored") - return - } - - enableTele, err := cmd.Flags().GetBool("enableTele") - if err != nil { - s.logger.Error("failed to read the disable telemetry flag") - return - } - - proxyPort, err := cmd.Flags().GetUint32("proxyport") - if err != nil { - s.logger.Error("failed to read the proxy port") - return - } - s.logger.Debug("the ports are", zap.Any("ports", ports)) - - s.server.Serve(path, proxyPort, testReportPath, delay, pid, port, language, ports, apiTimeout, appCmd, enableTele) - }, - } - - serveCmd.Flags().Uint32("pid", 0, "Process id of your application.") - - serveCmd.Flags().Uint32("proxyport", 0, "Choose a port to run Keploy Proxy.") - - serveCmd.Flags().Uint32("port", 6789, "Port at which you want to run graphql Server") - - serveCmd.Flags().StringP("path", "p", "", "Path to local directory where generated testcases/mocks are stored") - - serveCmd.Flags().Uint64P("delay", "d", 5, "User provided time to run its application") - serveCmd.MarkFlagRequired("delay") - - serveCmd.Flags().Uint64("apiTimeout", 5, "User provided timeout for calling its application") - - serveCmd.Flags().UintSlice("passThroughPorts", []uint{}, "Ports of Outgoing dependency calls to be ignored as mocks") - serveCmd.Flags().Bool("enableTele", true, "Switch for telemetry") - serveCmd.Flags().MarkHidden("enableTele") - - serveCmd.Flags().StringP("language", "l", "", "application programming language") - serveCmd.Flags().StringP("command", "c", "", "Command to start the user application") - serveCmd.MarkFlagRequired("command") - - serveCmd.Hidden = true - - return serveCmd -} diff --git a/cmd/test.go b/cmd/test.go index 14a611ddb..189d36f03 100755 --- a/cmd/test.go +++ b/cmd/test.go @@ -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 @@ -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, @@ -294,9 +294,7 @@ func (t *Test) GetCmd() *cobra.Command { TestsetNoise: testsetNoise, WithCoverage: withCoverage, CoverageReportPath: coverageReportPath, - }, enableTele) { - os.Exit(1) - } + }, enableTele) return nil }, @@ -336,4 +334,4 @@ func (t *Test) GetCmd() *cobra.Command { testCmd.SilenceErrors = true return testCmd -} +} \ No newline at end of file diff --git a/go.mod b/go.mod index 7942a603a..dc46f500e 100755 --- a/go.mod +++ b/go.mod @@ -74,9 +74,8 @@ require ( github.com/99designs/gqlgen v0.17.36 github.com/TheZeroSlave/zapsentry v1.18.0 github.com/agnivade/levenshtein v1.1.1 + github.com/emirpasic/gods v1.18.1 github.com/getsentry/sentry-go v0.17.0 - github.com/google/uuid v1.5.0 - github.com/hashicorp/go-memdb v1.3.4 github.com/jackc/pgproto3/v2 v2.3.2 github.com/vektah/gqlparser/v2 v2.5.8 github.com/xdg-go/pbkdf2 v1.0.0 @@ -86,10 +85,7 @@ require ( require ( github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect - github.com/emirpasic/gods v1.18.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect - github.com/hashicorp/go-immutable-radix v1.3.0 // indirect - github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/hashicorp/golang-lru/v2 v2.0.3 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect diff --git a/go.sum b/go.sum index 4cff5e10b..dced455fb 100755 --- a/go.sum +++ b/go.sum @@ -70,19 +70,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= -github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/hashicorp/go-immutable-radix v1.3.0 h1:8exGP7ego3OmkfksihtSouGMZ+hQrhxx+FVELeXpVPE= -github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-memdb v1.3.4 h1:XSL3NR682X/cVk2IeV0d70N4DZ9ljI885xAEU8IoK3c= -github.com/hashicorp/go-memdb v1.3.4/go.mod h1:uBTr1oQbtuMgd1SSGoR8YV27eT3sBHbYiNm53bMpgSg= -github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM= -github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= -github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/golang-lru/v2 v2.0.3 h1:kmRrRLlInXvng0SmLxmQpQkpbYAvcXm7NPDrgxJa9mE= github.com/hashicorp/golang-lru/v2 v2.0.3/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= diff --git a/pkg/util.go b/pkg/util.go index 300b31640..8b86df91d 100755 --- a/pkg/util.go +++ b/pkg/util.go @@ -215,4 +215,4 @@ func GetNextTestReportDir(testReportPath, subDirPrefix string) (string, error) { newTestReportPath := filepath.Join(testReportPath, fmt.Sprintf("%s%d", subDirPrefix, latestReportNumber)) return newTestReportPath, nil -} +} \ No newline at end of file