Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc changes sample apps - Add 3 apps and change installation.md flow #447

Merged
merged 11 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"docusaurus": "docusaurus",
"start": "docusaurus start",
"clean": "rimraf build",
"build": "docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
Expand All @@ -25,10 +26,10 @@
"@mdx-js/react": "^3.0.0",
"clsx": "^2.0.0",
"lint": "^0.8.19",
"prism-react-renderer": "^2.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-player": "^2.6.0",
"prism-react-renderer": "^2.1.0",
"remark-typescript-tools": "1.0.9",
"typescript": "5",
"uuid": "^8.3.2",
Expand Down Expand Up @@ -61,9 +62,10 @@
"postcss-preset-env": "^7.4.1",
"prettier": "^2.5.1",
"prettier-plugin-tailwindcss": "^0.1.4",
"rimraf": "^6.0.1",
"tailwindcss": "^3.0.1"
},
"engines": {
"node":">=18.0"
"node": ">=18.0"
}
}
Binary file added static/img/Flask-redis-Captured test cases.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/Pet-clinic-record.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/Pet-clinic-test1.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/Pet-clinic-test2.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/Sanic-Mongo-Test.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/Sanic-mongo-record.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/wsl-record-ts.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/wsl-test-summary-ts.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/wsl-test-ts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
119 changes: 118 additions & 1 deletion versioned_docs/version-2.0.0/concepts/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import PlatformRequirements from '../concepts/platform-requirements.md'

<PlatformRequirements/>

## Quick Installation
# Keploy Installation

## Quick Installation Using CLI


Let's get started by setting up the Keploy alias with this command:

Expand Down Expand Up @@ -64,12 +67,20 @@ Use "keploy [command] --help" for more information about a command.

🎉 Wohoo! You are all set to use Keploy.



## Other Installation Methods

<details>
<summary>Install using Docker</summary>


### Downloading and running Keploy in Docker

#### On macOS

Note : Keploy is not supported natively on MacOS, so you can follow the below method to run with docker

1. Open up a terminal window.

2. Create a bridge network in Docker using the following docker network create command:
Expand All @@ -84,6 +95,103 @@ docker network create keploy-network
alias keploy="docker run --name keploy-v2 -p 16789:16789 --network keploy-network --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 ghcr.io/keploy/keploy"
```

</details>

<details>

<summary>Running Keploy Natively on MacOS by setting up a linux env</summary>

### Downloading and running Keploy in Native using Debian on MacOS

1. Open the terminal Session.
2. Run the following command

```bash
limactl show-ssh --format=config debian-12 & add it to its ssh config
```
3. Open a remote window on your code editor
4. Click on connect to host
5. Now select the configured SSH as "lima-debian"
6. Once you are in the terminal run the following commands to go into your directory

```bash
cd /Users
```

```bash
cd /{Username}
```
7. Run the following command to install Keploy

```bash
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_arm64.tar.gz" | tar xz --overwrite -C /tmp
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin/keploy
```
8. Run the following command to install Zsh

```bash
sudo apt-get -y install zsh
```
**Why?** : zsh (Z Shell) is an advanced shell that offers enhanced features compared to the default bash shell. It provides better autocompletion, advanced globbing, improved history management, and more customization options.

9. Install Git

```bash
sudo apt-get -y install git
```

10. Install 'Oh-my-zsh'

```bash
sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"
```
**Why?** : oh-my-zsh is a framework for managing your zsh configuration. It comes with a collection of plugins, themes, and helpful features that enhance the zsh experience.

11. Commands to Install docker

```bash
sudo apt-get -y update
```
```bash
sudo apt-get -y install ca-certificates curl
```
```bash
sudo install -m 0755 -d /etc/apt/keyrings
```
```bash
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
```
```bash
sudo chmod a+r /etc/apt/keyrings/docker.asc
```
```bash
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
```
```bash
sudo apt-get -y update
```
```bash
sudo apt-get -y update
```
```bash
sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```

12. Add docker to sudoers
```bash
sudo groupadd docker
```
```bash
sudo gpasswd -a $USER docker
```

</details>
<details>
<summary>Downloading and running Keploy in Native</summary>

### Downloading and running Keploy in Native

**Prequisites:**
Expand All @@ -92,6 +200,9 @@ alias keploy="docker run --name keploy-v2 -p 16789:16789 --network keploy-networ
- Run `uname -a` to verify the system architecture.
- In case of Windows, use WSL with Ubuntu 20.04 LTS or higher.

<summary>Downloading and running Keploy On WSL/Linux AMD</summary>


#### On WSL/Linux AMD

1. Open the terminal Session.
Expand Down Expand Up @@ -126,6 +237,11 @@ By default, Docker Desktop may not be configured to work with all WSL 2 distros
> This setup is essential for Keploy to function correctly in a WSL 2 environment, as it needs to interact with the Docker daemon to manage containers and networks effectively.
> For detailed instructions on how to configure `Docker Desktop` for WSL 2, please refer to the [official Docker documentation](https://docs.docker.com/desktop/wsl/).

</details>

<details>
<summary>With Arkade</summary>

### With Arkade

1. Installing Arkade
Expand All @@ -152,3 +268,4 @@ Or you can also download specific version of Keploy using the following command:
```bash
arkade get [email protected]
```
</details>
183 changes: 183 additions & 0 deletions versioned_docs/version-2.0.0/quickstart/flask-redis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
---
id: flask-redis
title: Sample Library App (Flask + Redis)
sidebar_label: Flask + Redis
description: This application is a simple Library API built using Flask and Redis for data storage. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on Movie records.

tags:
- flask
- quickstart
- samples
- examples
- tutorial
- python-framework
- redis
keyword:
- FastAPI Framework
- Flask
- Redis
- Python
- API Test generator
- Auto case generation
---

## Introduction

🪄 Dive into the world of Student CRUD Apps and see how seamlessly Keploy integrated with [Flask](https://flask.palletsprojects.com/en/3.0.x/) and [Redis](https://redis.io/). Buckle up, it's gonna be a fun ride! 🎢

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

<InstallationGuide/>

## Get Started! 🎬

## Clone the application 🧪

```bash
git clone https://github.com/keploy/samples-python.git && cd samples-python/flask-redis
```

## Installation Keploy

Depending on your OS, choose your adventure:

We are going to run the application the following way

- [Using Docker compose : running application as well as Mongo on Docker container](#using-docker-compose-)

## Using Docker Compose 🐳

We will be using Docker compose to run the application as well as Mongo on Docker container.

### Lights, Camera, Record! 🎥

Capture the test-cases-

```shell
keploy record -c "docker compose up" --container-name "flask-web" --buildDelay 50
```

🔥**Make some API calls**. Postman, Hoppscotch or even curl - take your pick!

Let's make URLs short and sweet:

### Generate testcases

To generate testcases we just need to **make some API calls.**

1. **Make a POST request:**

```bash
curl -X POST http://localhost:5000/books/ \
-H "Content-Type: application/json" \
-d '{"title": "1984", "author": "George Orwell"}'
```

2. **Make a GET request:**

```bash
curl -X GET "http://localhost:5000/books/?page=1&limit=10"
```

3. **Make a PUT request:**

```bash
curl -X PUT http://localhost:5000/books/1 \
-H "Content-Type: application/json" \
-d '{"title": "1984 - Updated", "author": "George Orwell"}'
```

4. **Make a DELETE request:**

```bash
curl -X DELETE http://localhost:5000/books/1
```
And once you are done, you can stop the recording and give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **keploy** directory and you'll discover your handiwork in `tests` directory and `mocks.yml`.

```yaml
version: api.keploy.io/v1beta1
kind: Redis
name: mock-0
spec:
metadata:
type: config
redisrequests:
- origin: client
message:
- type: string
data: "*4\r\n$6\r\nCLIENT\r\n$7\r\nSETINFO\r\n$8\r\nLIB-NAME\r\n$8\r\nredis-py\r\n"
redisresponses:
- origin: server
message:
- type: string
data: "+OK\r\n"
reqtimestampmock: 2024-08-02T22:15:10.6084523Z
restimestampmock: 2024-08-02T22:15:10.608930466Z
---
```

### **Time to run the testcases**

```bash
keploy test -c 'sudo docker compose up' --containerName "flask-web" --delay 10
```
You can also check the test summary from your cli

```bash
<=========================================>
COMPLETE TESTRUN SUMMARY.
Total tests: 11
Total test passed: 10
Total test failed: 1
Total time taken: "15.13 s"

Test Suite Name Total Test Passed Failed Time Taken

"test-set-0" 6 6 0 "5.06 s"
"test-set-1" 1 1 0 "5.02 s"
"test-set-2" 4 3 1 "5.04 s"
<=========================================>
```

## Some errors you may run into ?

1. While running the application you might have some ports up and running that you are trying to access again. This would throw a EBPF error

You can check the ports from the below command and

```bash
sudo lsof -p
```

If you want to check which process is using a specific port (e.g., port 5000), use:

```bash
sudo lsof -i :5000
```

Once you have identified the PID of the process using the port you need, you can terminate the process with the kill command:

```bash
sudo kill -9 <PID>
```

2. ERROR: for redis 'ContainerConfig'

The KeyError: 'ContainerConfig' issue you're encountering with Docker Compose is indicative of a problem with the Docker Compose file or its version compatibility.

Here’s how you can address and troubleshoot this error:

```bash
sudo apt-get update
sudo apt-get install docker-compose
```

Check your compose file's permissions

```bash
ls -l docker-compose.yml
```

Re-run the record or test command from above


Loading
Loading