Skip to content

fix: Keploy installation method in readme #16

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

Merged
merged 4 commits into from
Mar 7, 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
20 changes: 3 additions & 17 deletions django-postgres/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,11 @@ git clone https://github.com/keploy/samples-python.git && cd samples-python/djan

Keploy can be installed on Linux directly and on Windows with the help of WSL. Based on your system architecture, install the keploy latest binary release

**1. AMD Architecture**

```shell
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp

sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy
```

<details>
<summary> 2. ARM Architecture </summary>

```shell
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_arm64.tar.gz" | tar xz -C /tmp

sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy
```bash
curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh
keploy
```

</details>

### Starting the PostgreSQL Instance

```bash
Expand Down
26 changes: 7 additions & 19 deletions fastapi-postgres/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,26 @@ pip3 install -r requirements.txt

Keploy can be installed on Linux directly and on Windows with the help of WSL. Based on your system architecture, install the keploy latest binary release

**1. AMD Architecture**

```shell
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp

sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy
```

<details>
<summary> 2. ARM Architecture </summary>

```shell
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_arm64.tar.gz" | tar xz -C /tmp

sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy
```bash
curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh
keploy
```

</details>

### Starting the PostgreSQL Instance

```bash
# Start the application
docker-compose up -d
```

> Note: Update the `SQLALCHEMY_DATABASE_URL` in the `database.py` file if you want to use a keploy with docker.

### Capture the Testcases

This command will start the recording of API calls using ebpf:-

```shell
sudo -E keploy record -c "uvicorn application.main:app --reload"
sudo -E PATH=$PATH keploy record -c "uvicorn application.main:app --reload"
```

Make API Calls using Hoppscotch, Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.
Expand Down Expand Up @@ -118,7 +106,7 @@ Now all these API calls were captured as **editable** testcases and written to `
Now let's run the application in test mode.

```shell
sudo -E keploy test -c "uvicorn application.main:app --reload" --delay 10
sudo -E PATH=$PATH keploy test -c "uvicorn application.main:app --reload" --delay 10
```

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 😄**
2 changes: 1 addition & 1 deletion fastapi-postgres/application/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy.orm import sessionmaker


SQLALCHEMY_DATABASE_URL = "postgresql://postgres:postgres@0.0.0.0:5432/studentdb"
SQLALCHEMY_DATABASE_URL = "postgresql://postgres:postgres@postgres:5432/studentdb"

engine = create_engine(SQLALCHEMY_DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Expand Down
16 changes: 16 additions & 0 deletions fastapi-postgres/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@ services:
- "5432:5432" # Map the PostgreSQL port to the host machine
volumes:
- ./sql/init.sql:/docker-entrypoint-initdb.d/init.sql
networks:
- keploy-network

app:
container_name: fastapi-app
image: fastapi
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
ports:
- 8000:8000
depends_on:
- postgres
networks:
- keploy-network
Loading