Skip to content

Commit

Permalink
doc: sample rust mongo rest app (#451)
Browse files Browse the repository at this point in the history
* doc: sample rust mongo rest app

Signed-off-by: Abhishek kushwaha <abhishekkushwaha1479@gmail.com>

* docs: sample rust mongo rest app

Signed-off-by: Abhishek kushwaha <abhishekkushwaha1479@gmail.com>

* chore: error guessing

Signed-off-by: Abhishek kushwaha <abhishekkushwaha1479@gmail.com>

* chore: logs

* Update sample-rust-crud-mongo.md

Signed-off-by: Animesh Pathak <53110238+Sonichigo@users.noreply.github.com>

---------

Signed-off-by: Abhishek kushwaha <abhishekkushwaha1479@gmail.com>
Signed-off-by: Animesh Pathak <53110238+Sonichigo@users.noreply.github.com>
Co-authored-by: Animesh Pathak <53110238+Sonichigo@users.noreply.github.com>
  • Loading branch information
Abbhiishek and Sonichigo authored Oct 8, 2024
1 parent a8f529c commit 22c2c7e
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 3 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/rust-mongo-rest-test-run-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/rust-mongo-rest-test-run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions versioned_docs/version-2.0.0/quickstart/sample-rust-crud-mongo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
id: sample-rust-crud-mongo
title: Rust CRUD REST API with MongoDB
sidebar_label: Rust + MongoDB (REST)
description: A sample CRUD REST API application to test Keploy integration capabilities using Rust and MongoDB.
tags:
- Rust
- MongoDB
- REST API
keyword:
- Rust
- MongoDB
- API Test generator
- Auto Testcase generation
- CRUD
- REST
---

## Introduction

This is a sample CRUD REST API application to showcase Keploy integration capabilities using Rust and MongoDB. Let's get started! 🚀

import InstallationGuide from '../concepts/installation.md'

<InstallationGuide/>

## Get Started! 🎬

### Setup app

Now that we have Keploy installed, let's set up our application.

```bash
git clone https://github.com/keploy/samples-rust
cd samples-rust/CRUD-rust-mongo
```

## Running App Locally on Linux/WSL 🐧

We will be using Docker compose to run Mongo on Docker container.

### Let's start the MongoDB Instance

Open the root directory path in your terminal and then execute the following command:

```bash
docker-compose up -d
```

### Run the app

```bash
cargo r -r
```
The app will be running on port 8000.


#### Capture testcase

On same terminal execute the following command:

```bash
keploy record -c 'cargo r -r'
```
The output will be as follows:
![RecordRun](/img/rust-mongo-rest-test-run.png?raw=true)

### Generate testcase

Open Postman or any other tool, or utilize the Postman VSCode extension. Click on the import icon (shown below):

![TestRun](/img/rust-mongo-postman-collection-import-button.png?raw=true)

Import the file named: `Note App.postman_collection.json`

After that, Postman will display a similar window:

![TestRun](/img/rust-mongo-rest-postman-collection.png?raw=true)

Hit the Create Note Request with the available data and you will get the following output in your terminal:

```bash
🐰 Keploy: 2024-08-27T21:06:57+05:30 t 8INFO
🟠 Keploy has captured test cases for the user's application. {"path": "/root/samples-rust/CRUD-rust-mongo/keploy/test-set-3/tests", "testcase name": "test-1"}
```
![TestRun](/img/rust-mongo-rest-postman-create-success.png?raw=true)
Afterward, create a GET all request, and you will get the following output in your terminal:
```bash
🐰 Keploy: 2024-08-27T21:13:41+05:30 INFO 🟠 Keploy has captured test cases for the user's application. {"path": "/root/samples-rust/CRUD-rust-mongo/keploy/test-set-3/tests", "testcase name": "test-3"}
```

![Test-case](/img/rust-mongo-rest-postman-get-all-success.png?raw=true)

We peformed two requests, one to create a note and one to get all notes. These requests are captured as testcases by Keploy.

### Run the testcases

Now, let's start keploy in test mode to run our test cases :
```bash
keploy test -c 'cargo r -r'
```

We get the following output in the terminal -

![TestRun](/img/rust-mongo-rest-test-run-2.png?raw=true)
*Voila!! Our testcases has passed 🌟*
6 changes: 4 additions & 2 deletions versioned_docs/version-2.0.0/quickstart/samples-rust.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
---
id: samples-rust
title: Rust Sample Application
sidebar_label: Rust + Mongo
sidebar_label: Rust + Mongo (GraphQL)
description: The following sample app to test Keploy integration capabilities using rust and MongoDb.
tags:
- Rust
- MongoDB
- GraphQL
keyword:
- Rust
- MongoDB
- GraphQL
- API Test generator
- Auto Testcase generation
---
Expand Down Expand Up @@ -49,7 +51,7 @@ sudo -E env PATH=$PATH keploy record -c 'cargo run'

#### Generate testcase

Go to the http://127.0.0.1:8080 and create some queries.
Go to the http://127.0.0.1:8000 and create some queries.

We will get the following output in our terminal

Expand Down
3 changes: 2 additions & 1 deletion versioned_sidebars/version-2.0.0-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
"collapsible": true,
"collapsed": true,
"items": [
"quickstart/samples-rust"
"quickstart/samples-rust",
"quickstart/sample-rust-crud-mongo"
]
},
{
Expand Down

0 comments on commit 22c2c7e

Please sign in to comment.