Skip to content

Commit aad3342

Browse files
committed
feat: update Golang quickstart
Signed-off-by: Achanandhi-M <[email protected]>
1 parent 57ad5e8 commit aad3342

File tree

4 files changed

+55
-243
lines changed

4 files changed

+55
-243
lines changed

β€Žsrc/components/QuickStartList.jsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ const quickstarts = [
149149
"A sample URL Shortener app to demonstrate Keploy integration capabilities using Mux and MySQL.",
150150
link: "/docs/quickstart/samples-mysql/#running-app-locally-on-linuxwsl-",
151151
},
152+
153+
/*
152154
{
153155
title: "FastHttp + Postgres",
154156
language: "Go",
@@ -157,6 +159,7 @@ const quickstarts = [
157159
"A sample CRUD application to demonstrate how seamlessly Keploy integrates with FastHttp and Postgres.",
158160
link: "/docs/quickstart/samples-fasthttp/#using-docker-compose-",
159161
},
162+
*/
160163

161164
{
162165
title: "FastHttp + Postgres",

β€Žversioned_docs/version-3.0.0/quickstart/go-fasthttp-postgres.mdβ€Ž

Lines changed: 21 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -22,180 +22,9 @@ keyword:
2222
import InstallReminder from '@site/src/components/InstallReminder';
2323
import SectionDivider from '@site/src/components/SectionDivider';
2424

25-
# Using Docker Compose 🐳
26-
27-
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.
28-
29-
<InstallReminder />
30-
31-
### Clone a sample CRUD application πŸ§ͺ
32-
33-
```bash
34-
git clone https://github.com/keploy/samples-go.git && cd samples-go/fasthttp-postgres
35-
go mod download
36-
```
37-
38-
We will be using Docker Compose to run both the application and Postgres inside Docker containers.
39-
40-
### Lights, Camera, Record! πŸŽ₯
41-
42-
Fire up the application and Postgres instance with Keploy. Keep an eye on the two key flags:
43-
`-c`: Command to run the app (e.g., `docker compose up`).
44-
45-
`--container-name`: The container name in the `docker-compose.yml` for traffic interception.
46-
47-
```bash
48-
keploy record -c "docker compose up" --container-name "fasthttpPostgresApp"
49-
```
50-
51-
> 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 <seconds>` to the command.
52-
53-
Getting logs like this? Perfect! πŸ‘Œ
54-
![Testcase](/img/fasthttp-postgress-test.png)
55-
56-
πŸ”₯ Challenge time! Generate some test cases. How? Just **make some API calls**. Postman, Hoppscotch or even curl - take your pick!
57-
58-
Let's create some users and books:
59-
60-
#### Post Requests
61-
62-
```bash
63-
curl -X POST -H "Content-Type: application/json" -d '{"name":"Author Name"}' http://localhost:8080/authors
64-
curl -X POST -H "Content-Type: application/json" -d '{"title":"Book Title","author_id":1}' http://localhost:8080/books
65-
```
66-
67-
#### Get Request
68-
69-
```bash
70-
curl -i http://localhost:8080/books
71-
```
72-
73-
πŸŽ‰ 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`.
74-
75-
Here's a peek of what you get:
76-
77-
```yaml
78-
version: api.keploy.io/v1beta1
79-
kind: Http
80-
name: test-1
81-
spec:
82-
metadata: {}
83-
req:
84-
method: POST
85-
proto_major: 1
86-
proto_minor: 1
87-
url: http://localhost:8080/authors
88-
header:
89-
Accept: "*/*"
90-
Content-Length: "22"
91-
Content-Type: application/json
92-
Host: localhost:8080
93-
User-Agent: curl/7.88.1
94-
body: '{"name":"Author Name"}'
95-
timestamp: 2024-06-24T13:05:47.732915734+05:30
96-
resp:
97-
status_code: 201
98-
header:
99-
Content-Length: "0"
100-
Date: Mon, 24 Jun 2024 07:35:47 GMT
101-
Server: Server
102-
body: ""
103-
status_message: Created
104-
proto_major: 0
105-
proto_minor: 0
106-
timestamp: 2024-06-24T13:05:49.810554677+05:30
107-
objects: []
108-
assertions:
109-
noise:
110-
header.Date: []
111-
created: 1719214549
112-
curl: |-
113-
curl --request POST \
114-
--url http://localhost:8080/authors \
115-
--header 'Host: localhost:8080' \
116-
--header 'User-Agent: curl/7.88.1' \
117-
--header 'Accept: */*' \
118-
--header 'Content-Type: application/json' \
119-
--data '{"name":"Author Name"}'
120-
```
121-
122-
This is how the generated **mock.yml** will look like:
123-
124-
```yaml
125-
version: api.keploy.io/v1beta1
126-
kind: Postgres
127-
name: mock-0
128-
spec:
129-
metadata:
130-
type: config
131-
postgresrequests:
132-
- identifier: StartupRequest
133-
length: 96
134-
payload: AAAAYAADAAB1c2VyAHBvc3RncmVzAGNsaWVudF9lbmNvZGluZwBVVEY4AGV4dHJhX2Zsb2F0X2RpZ2l0cwAyAGRhdGFiYXNlAGRiAGRhdGVzdHlsZQBJU08sIE1EWQAA
135-
startup_message:
136-
protocolversion: 196608
137-
parameters:
138-
client_encoding: UTF8
139-
database: db
140-
datestyle: ISO, MDY
141-
extra_float_digits: "2"
142-
user: postgres
143-
auth_type: 0
144-
postgresresponses:
145-
- header: [R]
146-
identifier: ServerResponse
147-
length: 96
148-
authentication_md5_password:
149-
salt: [200, 42, 157, 175]
150-
msg_type: 82
151-
auth_type: 5
152-
reqtimestampmock: 2024-06-24T13:05:47.736932812+05:30
153-
restimestampmock: 2024-06-24T13:05:47.74668502+05:30
154-
connectionId: "0"
155-
```
156-
157-
_Time to perform more API magic!_
158-
159-
#### Get All Books
160-
161-
```bash
162-
curl -i http://localhost:8080/books
163-
```
164-
165-
Or just type `http://localhost:8080/books` in your browser. Your choice!
166-
167-
Spotted the new test and mock files in your project? High five! πŸ™Œ
168-
169-
### Run Tests πŸƒβ€β™€οΈ
170-
171-
Time to put things to the test πŸ§ͺ
172-
173-
```bash
174-
keploy test -c "docker compose up" --container-name "fasthttpPostgresApp" --delay 10
175-
```
176-
177-
> The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking.
178-
179-
Your results should be looking like this:
180-
181-
![Testrun](/img/go-fasthttp-testrun.png)
182-
Did you spot that the ts (timestamp) is showing some differences? Yep, time has a way of doing that! πŸ•°οΈ
183-
184-
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! βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨
185-
186-
### Wrapping it up πŸŽ‰
187-
188-
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. πŸ˜ŠπŸš€
189-
190-
Happy coding! βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨
191-
192-
<SectionDivider />
193-
194-
---
195-
19625
# Running App Locally on Linux/WSL 🐧
19726

198-
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.
27+
This guide walks you through generating tests and DB mocks for a sample CRUD app built with FastHttp and Postgres using Keploy.
19928

20029
<InstallReminder />
20130

@@ -208,32 +37,34 @@ go mod download
20837

20938
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! πŸŽ‰
21039

211-
If you’re using WSL on Windows, start in your home directory:
40+
#### Point the app to local Postgres
21241

213-
```bash
214-
wsl ~
215-
```
42+
Update the Postgres URL to `localhost:5432` in `app.go` (mentioned at line 21 in the sample).
21643

217-
### Point the app to local Postgres
44+
#### Start Postgres
21845

219-
Update the Postgres URL to `localhost:5432` in `main.go` (mentioned at line 21 in the sample).
46+
```bash
47+
docker compose up postgres
48+
```
22049

221-
### Start Postgres
50+
#### Record with Keploy while running the app
22251

22352
```bash
224-
docker compose up postgres
53+
go build -o app
22554
```
22655

227-
### Record with Keploy while running the app
56+
### Lights, Camera, Record! πŸŽ₯
22857

22958
```bash
230-
go build -cover
23159
keploy record -c "./app"
23260
```
23361

23462
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.
63+
23564
If you're seeing logs that resemble the ones below, you're on the right track:
23665

66+
<img src="https://keploy-devrel.s3.us-west-2.amazonaws.com/Keploy_record_fastapi_golang.png" alt="Sample Keploy Record" width="100%" style={{ borderRadius: '5px' }} />
67+
23768
Alright! With the app alive and kicking, let's weave some test cases. Making some API calls! Postman, Hoppscotch,
23869

23970
or even the classic curl - take your pick!
@@ -246,6 +77,10 @@ Time to create some users and books:
24677

24778
```bash
24879
curl -X POST -H "Content-Type: application/json" -d '{"name":"Author Name"}' http://localhost:8080/authors
80+
81+
```
82+
83+
```bash
24984
curl -X POST -H "Content-Type: application/json" -d '{"title":"Book Title","author_id":1}' http://localhost:8080/books
25085
```
25186

@@ -255,7 +90,7 @@ curl -X POST -H "Content-Type: application/json" -d '{"title":"Book Title","auth
25590
curl -i http://localhost:8080/books
25691
```
25792

258-
πŸŽ‰ 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`.
93+
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`.
25994

26095
### πŸƒβ€β™€οΈ Run the Tests!
26196

@@ -269,14 +104,12 @@ keploy test -c "./app" --delay 5
269104
270105
When all is said and done, your test results should look a little something like this:
271106

272-
![Testrun](/img/go-fasthttp-testrun.png)
107+
<img src="https://keploy-devrel.s3.us-west-2.amazonaws.com/keploy_replay_test_fastapi_golang.png" alt="Sample Keploy Replay" width="100%" style={{ borderRadius: '5px' }} />
273108

274-
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! βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨
109+
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!
275110

276111
### Wrapping it up πŸŽ‰
277112

278-
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. πŸ˜ŠπŸš€
113+
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
279114

280115
Happy coding! βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨
281-
282-
Hope this helps you out, if you still have any questions, reach out to us .

β€Žversioned_docs/version-3.0.0/quickstart/go-mux-mysql.mdβ€Ž

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ keyword:
2323
import InstallReminder from '@site/src/components/InstallReminder';
2424
import SectionDivider from '@site/src/components/SectionDivider';
2525

26-
# Using Docker Compose 🐳
26+
# Using Docker 🐳
2727

2828
A sample url shortener app to test Keploy integration capabilities using Mux and MySQL.
2929

@@ -44,12 +44,6 @@ We will be using Docker compose to run the application as well as MySQL on Docke
4444
docker run -p 3306:3306 --rm --name mysql --network keploy-network -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest
4545
```
4646

47-
#### Create Docker volume (optional)
48-
49-
```bash
50-
docker volume create --driver local --opt type=debugfs --opt device=debugfs debugfs
51-
```
52-
5347
### Capture the Testcases
5448

5549
Build the Docker image of our application:
@@ -94,7 +88,7 @@ this will return the shortened url. The ts would automatically be ignored during
9488
#### Access all shortened URLs
9589

9690
```bash
97-
curl --request GET --url http://localhost:8080/all
91+
curl http://localhost:8080/all
9892
```
9993

10094
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
140134
go mod download
141135
```
142136

143-
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!πŸŽ‰
144-
145-
> To establish a network for your application using Keploy on Docker, follow these steps.
146-
> If you're using a docker-compose network, replace keploy-network with your app's `docker_compose_network_name` below.
137+
We’ll run our sample application locally, with the database running inside a Docker container. Ready? Let’s get the party started! πŸŽ‰
147138

148139
### Start the MySQL instance
149140

@@ -165,7 +156,7 @@ go build -o main
165156
sudo -E PATH=$PATH keploy record -c "./main"
166157
```
167158

168-
![Testrun](/img/mux-mysql-testcase.png)
159+
<img src="https://keploy-devrel.s3.us-west-2.amazonaws.com/keploy_mux_mysql_record_docs.png" alt="Sample Keploy record header" width="100%" style={{ borderRadius: '5px' }} />
169160

170161
### Generate testcases
171162

@@ -195,7 +186,9 @@ this will return the shortened url.
195186
#### Redirect to original url from shortened url
196187

197188
```zsh
198-
curl -request GET localhost:8080/links/1
189+
190+
curl http://localhost:8080/links/1
191+
199192
```
200193

201194
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
211204
No need to set up dependencies like MySQL or write mocks for your testing. The application thinks it's talking to MySQL. πŸ˜„
212205

213206
We will get output something like this:
214-
![Testrun](/img/go-mux-mysql-test-cases.png)
207+
208+
<img src="https://keploy-devrel.s3.us-west-2.amazonaws.com/keploy_mux_mysql_replay_docs.png
209+
" alt="Sample Keploy test header" width="100%" style={{ borderRadius: '5px' }} />
215210

216211
### Wrapping it up πŸŽ‰
217212

218213
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.πŸ˜ŠπŸš€
219-
220-
Hope this helps you out, if you still have any questions, reach out to us .

0 commit comments

Comments
Β (0)