diff --git a/src/components/QuickStartList.js b/src/components/QuickStartList.js index dd6e04bf5..32d748a26 100644 --- a/src/components/QuickStartList.js +++ b/src/components/QuickStartList.js @@ -149,6 +149,8 @@ const quickstarts = [ "A sample URL Shortener app to demonstrate Keploy integration capabilities using Mux and MySQL.", link: "/docs/quickstart/samples-mysql/#running-app-locally-on-linuxwsl-", }, + + /* { title: "FastHttp + Postgres", language: "Go", @@ -157,6 +159,7 @@ const quickstarts = [ "A sample CRUD application to demonstrate how seamlessly Keploy integrates with FastHttp and Postgres.", link: "/docs/quickstart/samples-fasthttp/#using-docker-compose-", }, + */ { title: "FastHttp + Postgres", diff --git a/versioned_docs/version-3.0.0/quickstart/go-fasthttp-postgres.md b/versioned_docs/version-3.0.0/quickstart/go-fasthttp-postgres.md index c16ec7238..1d6e09012 100644 --- a/versioned_docs/version-3.0.0/quickstart/go-fasthttp-postgres.md +++ b/versioned_docs/version-3.0.0/quickstart/go-fasthttp-postgres.md @@ -22,180 +22,9 @@ keyword: import InstallReminder from '@site/src/components/InstallReminder'; import SectionDivider from '@site/src/components/SectionDivider'; -# Using Docker Compose 🐳 - -This guide walks you through generating tests and DB mocks for a sample CRUD app built with [FastHttp](https://github.com/valyala/fasthttp) and [Postgres](https://www.postgresql.org) using Keploy. - - - -### Clone a sample CRUD application πŸ§ͺ - -```bash -git clone https://github.com/keploy/samples-go.git && cd samples-go/fasthttp-postgres -go mod download -``` - -We will be using Docker Compose to run both the application and Postgres inside Docker containers. - -### Lights, Camera, Record! πŸŽ₯ - -Fire up the application and Postgres instance with Keploy. Keep an eye on the two key flags: -`-c`: Command to run the app (e.g., `docker compose up`). - -`--container-name`: The container name in the `docker-compose.yml` for traffic interception. - -```bash -keploy record -c "docker compose up" --container-name "fasthttpPostgresApp" -``` - -> Keploy waits for the container to be up before intercepting. If your compose services need extra time to build or initialize, you can add `--build-delay ` to the command. - -Getting logs like this? Perfect! πŸ‘Œ -![Testcase](/img/fasthttp-postgress-test.png) - -πŸ”₯ Challenge time! Generate some test cases. How? Just **make some API calls**. Postman, Hoppscotch or even curl - take your pick! - -Let's create some users and books: - -#### Post Requests - -```bash -curl -X POST -H "Content-Type: application/json" -d '{"name":"Author Name"}' http://localhost:8080/authors -curl -X POST -H "Content-Type: application/json" -d '{"title":"Book Title","author_id":1}' http://localhost:8080/books -``` - -#### Get Request - -```bash -curl -i http://localhost:8080/books -``` - -πŸŽ‰ Woohoo! With simple API calls, you've crafted test cases with mocks! Dive into the Keploy directory and feast your eyes on the newly minted `test-1.yml` and `mocks.yml`. - -Here's a peek of what you get: - -```yaml -version: api.keploy.io/v1beta1 -kind: Http -name: test-1 -spec: - metadata: {} - req: - method: POST - proto_major: 1 - proto_minor: 1 - url: http://localhost:8080/authors - header: - Accept: "*/*" - Content-Length: "22" - Content-Type: application/json - Host: localhost:8080 - User-Agent: curl/7.88.1 - body: '{"name":"Author Name"}' - timestamp: 2024-06-24T13:05:47.732915734+05:30 - resp: - status_code: 201 - header: - Content-Length: "0" - Date: Mon, 24 Jun 2024 07:35:47 GMT - Server: Server - body: "" - status_message: Created - proto_major: 0 - proto_minor: 0 - timestamp: 2024-06-24T13:05:49.810554677+05:30 - objects: [] - assertions: - noise: - header.Date: [] - created: 1719214549 -curl: |- - curl --request POST \ - --url http://localhost:8080/authors \ - --header 'Host: localhost:8080' \ - --header 'User-Agent: curl/7.88.1' \ - --header 'Accept: */*' \ - --header 'Content-Type: application/json' \ - --data '{"name":"Author Name"}' -``` - -This is how the generated **mock.yml** will look like: - -```yaml -version: api.keploy.io/v1beta1 -kind: Postgres -name: mock-0 -spec: - metadata: - type: config - postgresrequests: - - identifier: StartupRequest - length: 96 - payload: AAAAYAADAAB1c2VyAHBvc3RncmVzAGNsaWVudF9lbmNvZGluZwBVVEY4AGV4dHJhX2Zsb2F0X2RpZ2l0cwAyAGRhdGFiYXNlAGRiAGRhdGVzdHlsZQBJU08sIE1EWQAA - startup_message: - protocolversion: 196608 - parameters: - client_encoding: UTF8 - database: db - datestyle: ISO, MDY - extra_float_digits: "2" - user: postgres - auth_type: 0 - postgresresponses: - - header: [R] - identifier: ServerResponse - length: 96 - authentication_md5_password: - salt: [200, 42, 157, 175] - msg_type: 82 - auth_type: 5 - reqtimestampmock: 2024-06-24T13:05:47.736932812+05:30 - restimestampmock: 2024-06-24T13:05:47.74668502+05:30 -connectionId: "0" -``` - -_Time to perform more API magic!_ - -#### Get All Books - -```bash -curl -i http://localhost:8080/books -``` - -Or just type `http://localhost:8080/books` in your browser. Your choice! - -Spotted the new test and mock files in your project? High five! πŸ™Œ - -### Run Tests πŸƒβ€β™€οΈ - -Time to put things to the test πŸ§ͺ - -```bash -keploy test -c "docker compose up" --container-name "fasthttpPostgresApp" --delay 10 -``` - -> The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking. - -Your results should be looking like this: - -![Testrun](/img/go-fasthttp-testrun.png) -Did you spot that the ts (timestamp) is showing some differences? Yep, time has a way of doing that! πŸ•°οΈ - -Final thoughts? Dive deeper! Try different API calls, tweak the DB response in the `mocks.yml`, or fiddle with the request or response in `test-x.yml`. Run the tests again and see the magic unfold! βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨ - -### Wrapping it up πŸŽ‰ - -Congrats on the journey so far! You've seen Keploy's power, flexed your coding muscles, and had a bit of fun too! Now, go out there and keep exploring, innovating, and creating! Remember, with the right tools and a sprinkle of fun, anything's possible. πŸ˜ŠπŸš€ - -Happy coding! βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨ - - - ---- - # Running App Locally on Linux/WSL 🐧 -This guide walks you through generating tests and DB mocks for a sample CRUD app built with [FastHttp](https://github.com/valyala/fasthttp) and [Postgres](https://www.postgresql.org) using Keploy. +This guide walks you through generating tests and DB mocks for a sample CRUD app built with FastHttp and Postgres using Keploy. @@ -208,32 +37,34 @@ go mod download We'll be running our sample application right on Linux, but just to make things a tad more thrilling, we'll have the database (Postgres) chill on Docker. Ready? Let's get the party started! πŸŽ‰ -If you’re using WSL on Windows, start in your home directory: +#### Point the app to local Postgres -```bash -wsl ~ -``` +Update the Postgres URL to `localhost:5432` in `app.go` (mentioned at line 21 in the sample). -### Point the app to local Postgres +#### Start Postgres -Update the Postgres URL to `localhost:5432` in `main.go` (mentioned at line 21 in the sample). +```bash +docker compose up postgres +``` -### Start Postgres +#### Record with Keploy while running the app ```bash -docker compose up postgres +go build -o app ``` -### Record with Keploy while running the app +### Lights, Camera, Record! πŸŽ₯ ```bash -go build -cover keploy record -c "./app" ``` Keep an eye out for the `-c` flag! It's the command charm to run the app. Whether you're using `go run main.go` or the binary path like `./app`, it's your call. + If you're seeing logs that resemble the ones below, you're on the right track: +Sample Keploy Record + Alright! With the app alive and kicking, let's weave some test cases. Making some API calls! Postman, Hoppscotch, or even the classic curl - take your pick! @@ -246,6 +77,10 @@ Time to create some users and books: ```bash curl -X POST -H "Content-Type: application/json" -d '{"name":"Author Name"}' http://localhost:8080/authors + +``` + +```bash curl -X POST -H "Content-Type: application/json" -d '{"title":"Book Title","author_id":1}' http://localhost:8080/books ``` @@ -255,7 +90,7 @@ curl -X POST -H "Content-Type: application/json" -d '{"title":"Book Title","auth curl -i http://localhost:8080/books ``` -πŸŽ‰ Look at you go! With a few simple API calls, you've crafted test cases with mocks! Peek into the Keploy directory and behold the freshly minted `test-1.yml` and `mocks.yml`. +Look at you go! With a few simple API calls, you've crafted test cases with mocks! Peek into the Keploy directory and behold the freshly minted `test-1.yml` and `mocks.yml`. ### πŸƒβ€β™€οΈ Run the Tests! @@ -269,14 +104,12 @@ keploy test -c "./app" --delay 5 When all is said and done, your test results should look a little something like this: -![Testrun](/img/go-fasthttp-testrun.png) +Sample Keploy Replay -Final thoughts? Dive deeper! Try different API calls, tweak the DB response in the `mocks.yml`, or fiddle with the request or response in `test-x.yml`. Run the tests again and see the magic unfold! βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨ +Final thoughts? Dive deeper! Try different API calls, tweak the DB response in the `mocks.yml`, or fiddle with the request or response in `test-x.yml`. Run the tests again and see the magic unfold! ### Wrapping it up πŸŽ‰ -Congrats on the journey so far! You've seen Keploy's power, flexed your coding muscles, and had a bit of fun too! Now, go out there and keep exploring, innovating, and creating! Remember, with the right tools and a sprinkle of fun, anything's possible. πŸ˜ŠπŸš€ +Congrats on the journey so far! You've seen Keploy's power, flexed your coding muscles, and had a bit of fun too! Now, go out there and keep exploring, innovating, and creating! Remember, with the right tools and a sprinkle of fun, anything's possible Happy coding! βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨ - -Hope this helps you out, if you still have any questions, reach out to us . diff --git a/versioned_docs/version-3.0.0/quickstart/go-mux-mysql.md b/versioned_docs/version-3.0.0/quickstart/go-mux-mysql.md index 36df54146..fbbb5dd8e 100644 --- a/versioned_docs/version-3.0.0/quickstart/go-mux-mysql.md +++ b/versioned_docs/version-3.0.0/quickstart/go-mux-mysql.md @@ -23,7 +23,7 @@ keyword: import InstallReminder from '@site/src/components/InstallReminder'; import SectionDivider from '@site/src/components/SectionDivider'; -# Using Docker Compose 🐳 +# Using Docker 🐳 A sample url shortener app to test Keploy integration capabilities using Mux and MySQL. @@ -44,12 +44,6 @@ We will be using Docker compose to run the application as well as MySQL on Docke docker run -p 3306:3306 --rm --name mysql --network keploy-network -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest ``` -#### Create Docker volume (optional) - -```bash -docker volume create --driver local --opt type=debugfs --opt device=debugfs debugfs -``` - ### Capture the Testcases Build the Docker image of our application: @@ -94,7 +88,7 @@ this will return the shortened url. The ts would automatically be ignored during #### Access all shortened URLs ```bash -curl --request GET --url http://localhost:8080/all +curl http://localhost:8080/all ``` Now both these API calls were captured as **editable** testcases and written to `keploy/tests` folder. The keploy directory would also have `mocks` file that contains all the outputs of MySQL operations. Here's what the folder structure look like: @@ -140,10 +134,7 @@ git clone https://github.com/keploy/samples-go.git && cd samples-go/mux-mysql go mod download ``` -We'll be running our sample application right on Linux, but just to make things a tad more thrilling, we'll have the database (MySQL) chill on Docker. Ready? Let's get the party started!πŸŽ‰ - -> To establish a network for your application using Keploy on Docker, follow these steps. -> If you're using a docker-compose network, replace keploy-network with your app's `docker_compose_network_name` below. +We’ll run our sample application locally, with the database running inside a Docker container. Ready? Let’s get the party started! πŸŽ‰ ### Start the MySQL instance @@ -165,7 +156,7 @@ go build -o main sudo -E PATH=$PATH keploy record -c "./main" ``` -![Testrun](/img/mux-mysql-testcase.png) +Sample Keploy record header ### Generate testcases @@ -195,7 +186,9 @@ this will return the shortened url. #### Redirect to original url from shortened url ```zsh -curl -request GET localhost:8080/links/1 + +curl http://localhost:8080/links/1 + ``` Now, let's see the magic! πŸͺ„πŸ’« Both these API calls were captured as a test case and should be visible on the Keploy CLI. You should see a `keploy` folder with the test cases and data mocks created. @@ -211,10 +204,10 @@ sudo -E PATH=$PATH keploy test -c "./main" --delay 10 No need to set up dependencies like MySQL or write mocks for your testing. The application thinks it's talking to MySQL. πŸ˜„ We will get output something like this: -![Testrun](/img/go-mux-mysql-test-cases.png) + +Sample Keploy test header ### Wrapping it up πŸŽ‰ Congrats on the journey so far! You've seen Keploy's power, flexed your coding muscles, and had a bit of fun too! Now, go out there and keep exploring, innovating, and creating! Remember, with the right tools and a sprinkle of fun, anything's possible.πŸ˜ŠπŸš€ - -Hope this helps you out, if you still have any questions, reach out to us . diff --git a/versioned_docs/version-3.0.0/quickstart/samples-echo.md b/versioned_docs/version-3.0.0/quickstart/samples-echo.md index 1001ec860..5884ee4e0 100644 --- a/versioned_docs/version-3.0.0/quickstart/samples-echo.md +++ b/versioned_docs/version-3.0.0/quickstart/samples-echo.md @@ -35,34 +35,19 @@ git clone https://github.com/keploy/samples-go.git && cd samples-go/echo-sql go mod download ``` -We will be using Docker compose to run the application as well as Postgres on Docker container. +#### First things first, update the postgres host on line 41 in main.go to postgres from localhost. -#### Start Postgres Instance - -Using the docker-compose file we will start our postgres instance:- - -```bash -# Start Postgres -docker compose up -``` - -### Capture the Testcases - -Now, we will create the binary of our application:- - -```zsh -docker build -t echo-app:1.0 . -``` - -Once we have our binary file ready,this command will start the recording of API calls using ebpf:- +We will be using Docker compose to run the application as well as Postgres #### Lights, Camera, Record! πŸŽ₯ ```shell -keploy record -c "docker run -p 8082:8082 --name echoSqlApp --network keploy-network echo-app:1.0" +keploy record -c "docker compose up" --container-name "echoApp" --build-delay 50 ``` -Make API Calls using Hoppscotch, Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks. +> `--build-delay` adds a buffer (in seconds) to allow images to build/pull and services to start before Keploy begins interception. If your services are already up, you can omit it. + +Make API Calls using cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks. ### Generate testcases @@ -91,15 +76,14 @@ this will return the shortened url. The ts would automatically be ignored during ##### 1. By using Curl Command ```bash -curl --request GET \ - --url http://localhost:8082/GuwHCgoQ +curl http://localhost:8082/GuwHCgoQ ``` 2. Or by querying through the browser `http://localhost:8082/GuwHCgoQ` Now both these API calls were captured as **editable** testcases and written to `keploy/tests` folder. The keploy directory would also have `mocks` file that contains all the outputs of postgres operations. Here's what the folder structure look like: -![Testcase](/img/echo-postgress-run-testcase.png?raw=true) +Sample Keploy Record Now, let's see the magic! βœ¨πŸ’« @@ -107,19 +91,15 @@ Want to see if everything works as expected? ### Run the Testcases -Now that we have our testcase captured, we will add `ts` to noise field in `test-*.yaml` files. - -**1. On line 32 we will add "`- body.ts`" under the "`header.data`".** - -Now let's run the test mode (in the echo-sql directory, not the Keploy directory). +Time to put things to the test πŸ§ͺ ```shell -keploy test -c "docker run -p 8082:8082 --name echoSqlApp --network keploy-network echo-app:1.0" --delay 10 +keploy test -c "docker compose up" --container-name "echoApp" --build-delay 50 --delay 10 ``` output should look like -![Testrun](/img/testrun-echo.png?raw=true) +Sample Keploy Test So no need to setup fake database/apis like Postgres or write mocks for them. Keploy automatically mocks them and, **The application thinks it's talking to Postgres πŸ˜„** @@ -150,15 +130,15 @@ We'll be running our sample application right on Linux, but just to make things Using the docker-compose file we will start our Postgres instance:- ```shell -docker-compose up -d +docker-compose up postgres ``` -> **Since we are using docker to run the application, we need to update the `postgres` host on line 40 in `main.go`, update the host to `localhost`.** +> **Since we are using docker to run the application, we need to update the `postgres` host on line 41 in `main.go`, update the host to `localhost`.** Now, we will create the binary of our application:- ```go -go build echo-psql-url-shortener +go build -o echo-psql-url-shortener ``` ### Capture the Testcases @@ -167,6 +147,8 @@ go build echo-psql-url-shortener sudo -E PATH=$PATH keploy record -c "./echo-psql-url-shortener" ``` +Sample Keploy Record + ### Generate testcases To genereate testcases we just need to make some API calls. You can use Postman, Hoppscotch, or simply curl @@ -192,7 +174,7 @@ this will return the shortened url. #### Redirect to original url from shoΜ€rtened url ```zsh -curl --request GET \ --url http://localhost:8082/Lhr4BWAi +curl http://localhost:8082/Lhr4BWAi ``` or by querying through the browser `http://localhost:8082/Lhr4BWAi` @@ -209,12 +191,13 @@ Now that we have our testcase captured, run the test file. sudo -E PATH=$PATH keploy test -c "./echo-psql-url-shortener" ``` -So no need to setup dependencies like mongoDB, web-go locally or write mocks for your testing. +So no need to setup dependencies like postgres, web-go locally or write mocks for your testing. -The application thinks it's talking to mongoDB πŸ˜„ +The application thinks it's talking to postgres πŸ˜„ We will get output something like this: -![Testrun](/img/testrun-echo.png?raw=true) + +Sample Keploy Record ### Wrapping it up πŸŽ‰