Skip to content

Commit 25c0122

Browse files
authored
Merge pull request #136 from kapishupadhyay22/sqs-sample
feat: SQS sample application for API testing
2 parents aabe0a9 + e30a8c4 commit 25c0122

5 files changed

Lines changed: 657 additions & 0 deletions

File tree

sqs-samples/README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# SQS LocalStack Setup
2+
3+
This guide will walk you through setting up **LocalStack** with **SQS**, **MongoDB**, and interacting with the services using `awslocal`. We'll also walk through building the repository, sending test messages to SQS, and using Keploy to record and test the application.
4+
5+
## Prerequisites
6+
7+
Before proceeding, ensure you have the following installed:
8+
9+
- **Docker** (for running MongoDB)
10+
- **Python 3** (for installing LocalStack using `pipx`)
11+
- **Go** (for building the Go application)
12+
- **Keploy** (for recording and testing)
13+
14+
---
15+
16+
## Step 1: Set up LocalStack
17+
18+
### 1.1 Install LocalStack via `pipx`
19+
20+
First, install **`pipx`** (if not already installed):
21+
22+
```bash
23+
python3 -m pip install --upgrade pipx
24+
python3 -m pipx ensurepath
25+
```
26+
Now, install LocalStack using pipx:
27+
```
28+
pipx install --include-deps localstack
29+
```
30+
31+
32+
After installing LocalStack, install the AWS CLI Local tool (awslocal):
33+
```
34+
pipx inject localstack awscli-local
35+
pipx ensurepath
36+
```
37+
38+
This will allow you to interact with LocalStack using awslocal.
39+
1.2 **Start LocalStack**
40+
41+
Start LocalStack in the background:
42+
43+
```
44+
localstack start -d
45+
```
46+
Wait for LocalStack to initialize. It may take a few seconds to be fully ready.
47+
48+
## Step 2: **Set up MongoDB with Docker**
49+
50+
51+
### 2.1 Run MongoDB
52+
We will now run MongoDB using Docker. Use the following command to start MongoDB in a Docker container:
53+
```
54+
docker run -p 27017:27017 --rm --network keploy-network --name mongoDb mongo
55+
```
56+
57+
## Step 3: Set up SQS Queue in LocalStack
58+
### 3.1 Create SQS Queue
59+
You can create an SQS queue in LocalStack using awslocal. First, create the SQS queue with the following command:
60+
61+
```
62+
awslocal sqs create-queue --queue-name localstack-queue
63+
```
64+
This will create a queue named localstack-queue.
65+
66+
### 3.2 Populate the SQS Queue
67+
To populate the SQS queue with some test messages, use the following commands:
68+
69+
```
70+
awslocal sqs send-message --queue-url http://localhost:4566/000000000000/localstack-queue --message-body "Test message 1"
71+
72+
awslocal sqs send-message --queue-url http://localhost:4566/000000000000/localstack-queue --message-body "Test message 2"
73+
```
74+
This sends two test messages to the localstack-queue in LocalStack.
75+
76+
## Step 4: Build the Repository
77+
## 4.1 Build the Go Application
78+
After setting up LocalStack and MongoDB, it's time to build your Go application. Navigate to your repository directory and run the following:
79+
80+
```
81+
go mod tidy
82+
go build -o ginApp .
83+
```
84+
This will build the Go application and output the executable ginApp.
85+
86+
## Step 5: Run the Application
87+
Start the application (assuming it's a Gin application) using:
88+
89+
```
90+
./ginApp
91+
```
92+
Ensure the application is running before proceeding with the next steps.
93+
94+
## Step 6: Send Requests Using curl
95+
## 6.1 Send POST Request to Shorten URL
96+
Use curl to send a POST request to your application (adjust the URL accordingly if your app runs on a different port):
97+
98+
```
99+
curl --request POST --url http://localhost:8080/url --header 'Content-Type: application/json' --data '{"url": "https://google.com"}'
100+
```
101+
This will send a URL to your application to be shortened.
102+
103+
## 6.2 Send GET Request to Retrieve the URL
104+
After the URL is shortened, you can use curl to send a GET request to retrieve the shortened URL:
105+
106+
```
107+
curl --request GET http://localhost:8080/Lhr4BWAi
108+
```
109+
Make sure to replace Lhr4BWAi with the actual shortened URL ID returned from the POST request.
110+
111+
## Step 7: Keploy - Record and Test
112+
### 7.1 Run Keploy Record
113+
Start Keploy in record mode to capture the interactions between your application and the services (LocalStack, MongoDB):
114+
115+
```
116+
sudo -E env PATH=$PATH <path to your keploy binary> record -c "./ginApp"
117+
```
118+
Hit the curl commands and populate sqs queue to mimic the working behaiviour
119+
120+
This will run your application in record mode and capture all interactions with LocalStack and MongoDB.
121+
122+
### 7.2 Run Keploy Test
123+
Once the interactions are captured, you can run Keploy in test mode to validate the captured requests:
124+
125+
```
126+
sudo -E env PATH=$PATH <path to your keploy binary> test -c "go run main.go" --delay 30 &> logs.txt
127+
```
128+
This will execute the recorded tests and output the results to test_logs.txt.

sqs-samples/go.mod

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
module allen-sqs
2+
3+
go 1.22.1
4+
5+
require (
6+
github.com/aws/aws-sdk-go-v2 v1.36.3
7+
github.com/aws/aws-sdk-go-v2/config v1.29.9
8+
github.com/aws/aws-sdk-go-v2/credentials v1.17.62
9+
github.com/aws/aws-sdk-go-v2/service/appconfigdata v1.19.1
10+
github.com/aws/aws-sdk-go-v2/service/sqs v1.38.1
11+
github.com/gin-gonic/gin v1.10.0
12+
github.com/itchyny/base58-go v0.2.2
13+
github.com/joho/godotenv v1.5.1
14+
go.mongodb.org/mongo-driver v1.17.3
15+
go.uber.org/zap v1.27.0
16+
)
17+
18+
require (
19+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 // indirect
20+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect
21+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34 // indirect
22+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
23+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3 // indirect
24+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15 // indirect
25+
github.com/aws/aws-sdk-go-v2/service/sso v1.25.1 // indirect
26+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.29.1 // indirect
27+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.17 // indirect
28+
github.com/aws/smithy-go v1.22.2 // indirect
29+
github.com/bytedance/sonic v1.11.6 // indirect
30+
github.com/bytedance/sonic/loader v0.1.1 // indirect
31+
github.com/cloudwego/base64x v0.1.4 // indirect
32+
github.com/cloudwego/iasm v0.2.0 // indirect
33+
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
34+
github.com/gin-contrib/sse v0.1.0 // indirect
35+
github.com/go-playground/locales v0.14.1 // indirect
36+
github.com/go-playground/universal-translator v0.18.1 // indirect
37+
github.com/go-playground/validator/v10 v10.20.0 // indirect
38+
github.com/goccy/go-json v0.10.2 // indirect
39+
github.com/golang/snappy v0.0.4 // indirect
40+
github.com/json-iterator/go v1.1.12 // indirect
41+
github.com/klauspost/compress v1.16.7 // indirect
42+
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
43+
github.com/leodido/go-urn v1.4.0 // indirect
44+
github.com/mattn/go-isatty v0.0.20 // indirect
45+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
46+
github.com/modern-go/reflect2 v1.0.2 // indirect
47+
github.com/montanaflynn/stats v0.7.1 // indirect
48+
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
49+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
50+
github.com/ugorji/go/codec v1.2.12 // indirect
51+
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
52+
github.com/xdg-go/scram v1.1.2 // indirect
53+
github.com/xdg-go/stringprep v1.0.4 // indirect
54+
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
55+
go.uber.org/multierr v1.10.0 // indirect
56+
golang.org/x/arch v0.8.0 // indirect
57+
golang.org/x/crypto v0.26.0 // indirect
58+
golang.org/x/net v0.25.0 // indirect
59+
golang.org/x/sync v0.8.0 // indirect
60+
golang.org/x/sys v0.23.0 // indirect
61+
golang.org/x/text v0.17.0 // indirect
62+
google.golang.org/protobuf v1.34.1 // indirect
63+
gopkg.in/yaml.v3 v3.0.1 // indirect
64+
)

0 commit comments

Comments
 (0)