diff --git a/src/components/QuickStartFilter.js b/src/components/QuickStartFilter.js index 8e86dfe54..67458de75 100644 --- a/src/components/QuickStartFilter.js +++ b/src/components/QuickStartFilter.js @@ -1,14 +1,14 @@ -import React, {useState} from "react"; +import React, { useState } from "react"; import quickstarts from "./QuickStartList"; import Link from "@docusaurus/Link"; -import {FaGolang} from "react-icons/fa6"; -import {FaJava, FaLaptopCode, FaDocker, FaPython, FaCheck, FaArrowRight, FaArrowLeft} from "react-icons/fa"; -import {TbBrandCSharp} from "react-icons/tb"; -import {IoLogoJavascript} from "react-icons/io5"; -import {useColorMode} from "@docusaurus/theme-common"; +import { FaGolang, FaRust } from "react-icons/fa6"; +import { FaJava, FaLaptopCode, FaDocker, FaPython, FaCheck, FaArrowRight, FaArrowLeft } from "react-icons/fa"; +import { TbBrandCSharp } from "react-icons/tb"; +import { IoLogoJavascript } from "react-icons/io5"; +import { useColorMode } from "@docusaurus/theme-common"; -export default function QuickstartFilter({defaultLanguage = null}) { - const {colorMode} = useColorMode(); +export default function QuickstartFilter({ defaultLanguage = null }) { + const { colorMode } = useColorMode(); const isDark = colorMode === "dark"; const [currentStep, setCurrentStep] = useState(defaultLanguage ? 2 : 1); @@ -23,22 +23,23 @@ export default function QuickstartFilter({defaultLanguage = null}) { }); const languages = [ - {name: "Go", icon: , color: "#00ADD8"}, - {name: "Python", icon: , color: "#3776AB"}, - {name: "Java", icon: , color: "#007396"}, - {name: "JS/TS", icon: , color: "#F7DF1E"}, - {name: "C#", icon: , color: "#512BD4"}, + { name: "Go", icon: , color: "#00ADD8" }, + { name: "Python", icon: , color: "#3776AB" }, + { name: "Java", icon: , color: "#007396" }, + { name: "JS/TS", icon: , color: "#F7DF1E" }, + { name: "C#", icon: , color: "#512BD4" }, + { name: "Rust", icon: , color: "#DEA584" }, ]; const servers = [ - {name: "Local", icon: , description: "Run directly on your machine"}, - {name: "Docker", icon: , description: "Run in a Docker container"}, + { name: "Local", icon: , description: "Run directly on your machine" }, + { name: "Docker", icon: , description: "Run in a Docker container" }, ]; const steps = [ - {id: 1, label: "Language", icon: languages.find(l => l.name === language)?.icon || null}, - {id: 2, label: "Environment", icon: server === "Docker" ? : server === "Local" ? : null}, - {id: 3, label: "Quickstart", icon: null}, + { id: 1, label: "Language", icon: languages.find(l => l.name === language)?.icon || null }, + { id: 2, label: "Environment", icon: server === "Docker" ? : server === "Local" ? : null }, + { id: 3, label: "Quickstart", icon: null }, ]; const handleLanguageSelect = (lang) => { @@ -372,10 +373,10 @@ export default function QuickstartFilter({defaultLanguage = null}) { {step.label} {currentStep > step.id && step.id === 1 && language && ( - ({language}) + ({language}) )} {currentStep > step.id && step.id === 2 && server && ( - ({server}) + ({server}) )} {idx < steps.length - 1 && ( @@ -402,7 +403,7 @@ export default function QuickstartFilter({defaultLanguage = null}) {
{language === lang.name && }
-
+
{lang.icon}
{lang.name} @@ -417,15 +418,15 @@ export default function QuickstartFilter({defaultLanguage = null}) { <>

Select your environment

Choose where you want to run the application server

-
+
{servers.map((srv) => ( ))}
diff --git a/src/components/QuickStartList.js b/src/components/QuickStartList.js index 17f9e6e03..6b601009b 100644 --- a/src/components/QuickStartList.js +++ b/src/components/QuickStartList.js @@ -395,6 +395,23 @@ const quickstarts = [ "A sample app to demonstrate Keploy integration capabilities using TypeScript and Nhost.", link: "/docs/quickstart/samples-typescript/#running-the-app-using-docker", }, + // Rust list + { + title: "Actix + Postgres", + language: "Rust", + server: "Docker", + description: + "A sample Actix-web app to demonstrate how seamlessly Keploy integrates with Rust and PostgreSQL.", + link: "/docs/quickstart/rust-actix-postgres/#option-1-using-docker-compose-", + }, + { + title: "Actix + Postgres", + language: "Rust", + server: "Local", + description: + "A sample Actix-web app to demonstrate how seamlessly Keploy integrates with Rust and PostgreSQL.", + link: "/docs/quickstart/rust-actix-postgres/#option-2-running-locally-", + }, ]; export default quickstarts; diff --git a/static/img/rust-curl-traffic-local.png b/static/img/rust-curl-traffic-local.png new file mode 100644 index 000000000..8511bd7a2 Binary files /dev/null and b/static/img/rust-curl-traffic-local.png differ diff --git a/static/img/rust-curl-traffic.png b/static/img/rust-curl-traffic.png new file mode 100644 index 000000000..04fb0d032 Binary files /dev/null and b/static/img/rust-curl-traffic.png differ diff --git a/static/img/rust-docker-up.png b/static/img/rust-docker-up.png new file mode 100644 index 000000000..906cb5d72 Binary files /dev/null and b/static/img/rust-docker-up.png differ diff --git a/static/img/rust-local-app-starting.png b/static/img/rust-local-app-starting.png new file mode 100644 index 000000000..7dbf5b016 Binary files /dev/null and b/static/img/rust-local-app-starting.png differ diff --git a/static/img/rust-local-curl.png b/static/img/rust-local-curl.png new file mode 100644 index 000000000..998939465 Binary files /dev/null and b/static/img/rust-local-curl.png differ diff --git a/static/img/rust-local-db-up.png b/static/img/rust-local-db-up.png new file mode 100644 index 000000000..947f59b1b Binary files /dev/null and b/static/img/rust-local-db-up.png differ diff --git a/static/img/rust-local-db.png b/static/img/rust-local-db.png new file mode 100644 index 000000000..8b508d240 Binary files /dev/null and b/static/img/rust-local-db.png differ diff --git a/static/img/rust-local-record-running.png b/static/img/rust-local-record-running.png new file mode 100644 index 000000000..7dbf5b016 Binary files /dev/null and b/static/img/rust-local-record-running.png differ diff --git a/static/img/rust-local-record-start.png b/static/img/rust-local-record-start.png new file mode 100644 index 000000000..a393cfbfd Binary files /dev/null and b/static/img/rust-local-record-start.png differ diff --git a/static/img/rust-local-record.png b/static/img/rust-local-record.png new file mode 100644 index 000000000..ee09c31d8 Binary files /dev/null and b/static/img/rust-local-record.png differ diff --git a/static/img/rust-local-test-run.png b/static/img/rust-local-test-run.png new file mode 100644 index 000000000..1b9f61365 Binary files /dev/null and b/static/img/rust-local-test-run.png differ diff --git a/static/img/rust-local-test.png b/static/img/rust-local-test.png new file mode 100644 index 000000000..1e94e0e8f Binary files /dev/null and b/static/img/rust-local-test.png differ diff --git a/static/img/rust-record-captured.png b/static/img/rust-record-captured.png new file mode 100644 index 000000000..5208e04d5 Binary files /dev/null and b/static/img/rust-record-captured.png differ diff --git a/static/img/rust-record-start.png b/static/img/rust-record-start.png new file mode 100644 index 000000000..9be783aa3 Binary files /dev/null and b/static/img/rust-record-start.png differ diff --git a/static/img/rust-test-run.png b/static/img/rust-test-run.png new file mode 100644 index 000000000..83efc4977 Binary files /dev/null and b/static/img/rust-test-run.png differ diff --git a/versioned_docs/version-4.0.0/quickstart/rust-actix-postgres.md b/versioned_docs/version-4.0.0/quickstart/rust-actix-postgres.md new file mode 100644 index 000000000..95d51688d --- /dev/null +++ b/versioned_docs/version-4.0.0/quickstart/rust-actix-postgres.md @@ -0,0 +1,169 @@ +--- +id: rust-actix-postgres +title: Application with Postgres +sidebar_label: Actix + Postgres +description: A sample Actix-web application to demonstrate Keploy integration capabilities using Rust and Postgres. +tags: + - Rust + - Actix + - Postgres + - Quickstart +keyword: + - Rust + - Actix + - Postgres + - API Test generator + - Auto Testcase generation +--- + +import InstallReminder from '@site/src/components/InstallReminder'; + + + +## Introduction + +This guide will walk you through setting up a simple **Rust** application using **Actix-web** and **Postgres** (via **SQLx**) and integrating it with **Keploy** for automated testing. + +We will cover two methods: +1. **Docker Compose** (Recommended) +2. **Local Binary** + +## Application Setup + +### Clone the Repository + +```bash +git clone https://github.com/keploy/samples-rust.git +cd samples-rust/rust-actix-postgres +``` + +## Option 1: Using Docker Compose + +This is the easiest way to get started as it sets up both the application and the Postgres database for you. + +### 1. Start the Application + +```bash +docker compose up -d +``` + +![Start Application](/img/rust-docker-up.png) + +The application will be running at `http://localhost:8080`. + +### 2. Record Test Cases + +To record test cases, we use the `keploy record` command. This will start your application (via Docker) and proxy the traffic to record interactions. + +```bash +keploy record -c "docker compose up" --container-name rust-app +``` + +![Start Recording](/img/rust-record-start.png) + +Now, generate some traffic using `curl` or Postman: + +**Create an Item:** + +```bash +curl -X POST http://localhost:8080/items \ + -H "Content-Type: application/json" \ + -d '{"name": "Keploy Guide", "description": "Writing tests made easy"}' +``` + +**Get Items:** + +```bash +curl http://localhost:8080/items +``` + +![Make API Calls](/img/rust-curl-traffic.png) + +Stop the recording by pressing `Ctrl+C`. You should see a `keploy/` directory created with your test cases. + +![Captured Test Cases](/img/rust-record-captured.png) + +### 3. Replay Test Cases + +Now, let's verify the recorded test cases. + +```bash +keploy test -c "docker compose up" --container-name rust-app --delay 10 +``` + +![Test Replay](/img/rust-test-run.png) + +Keploy will compare the current responses with the recorded ones. + +--- + +## Option 2: Running Locally + +If you prefer to run the Rust binary directly, follow these steps. + +### 1. Start the Database + +We'll use Docker to spin up the Postgres database only. + +```bash +docker compose up db -d +``` + +![Start Database](/img/rust-local-db.png) + +### 2. Configure Environment + +To connect to the database, you need to set the connection string. You can either create a `.env` file or export the variable. + +```bash +export DATABASE_URL=postgres://postgres:password@localhost:5432/keploy +``` + +### 3. Record Test Cases + +Now, run the application with Keploy to record traffic. + +```bash +keploy record -c "cargo run" +``` + +![Start Recording](/img/rust-local-record.png) + +Once the application matches `Server running at http://0.0.0.0:8080`, generate some traffic. + +**Create an Item:** + +```bash +curl -X POST http://localhost:8080/items \ + -H "Content-Type: application/json" \ + -d '{"name": "Keploy Guide", "description": "Writing tests made easy"}' +``` + +**Get Items:** + +```bash +curl http://localhost:8080/items +``` + +![Generate Traffic](/img/rust-local-curl.png) + +Stop the recording by pressing `Ctrl+C`. + +### 4. Replay Test Cases + +Now, let's verify the recorded test cases. + +```bash +keploy test -c "cargo run" --delay 10 +``` + +![Test Replay](/img/rust-local-test.png) + +Keploy will run the tests and show the results in the terminal. + +## Summary + +You have successfully: +1. Set up a Rust Actix-web application. +2. Recorded API interactions using Keploy. +3. Replayed and validated the interactions. diff --git a/versioned_sidebars/version-4.0.0-sidebars.json b/versioned_sidebars/version-4.0.0-sidebars.json index 6399724df..5dfae67f6 100644 --- a/versioned_sidebars/version-4.0.0-sidebars.json +++ b/versioned_sidebars/version-4.0.0-sidebars.json @@ -118,6 +118,15 @@ "items": [ "quickstart/samples-csharp" ] + }, + { + "type": "category", + "label": "Rust", + "collapsible": true, + "collapsed": true, + "items": [ + "quickstart/rust-actix-postgres" + ] } ] },