Skip to content

Commit 464cd68

Browse files
feat: update compare_batches.sh to ignore .batchTTL field
feat: update compare_batches.sh to ignore .batchTTL field
2 parents b282d6c + 7db8010 commit 464cd68

4 files changed

Lines changed: 56 additions & 8 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ go.work.sum
2424
# Folders
2525
dist/
2626
.vscode/
27+
28+
**/1.txt
29+
**/2.txt
30+
**/tmp1.json
31+
**/tmp2.json

scripts/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM alpine:3.20
2+
3+
RUN apk add --no-cache bash curl jq diffutils
4+
5+
COPY compare_batches.sh /compare_batches.sh
6+
RUN chmod +x /compare_batches.sh
7+
8+
ENTRYPOINT ["/compare_batches.sh"]

scripts/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ This directory contains the `compare_batches.sh` script for comparing batch data
77
To use the `compare_batches.sh` script:
88

99
1. Make the script executable:
10+
1011
```bash
1112
chmod +x compare_batches.sh
1213
```
1314

1415
2. Run it with two domain names:
16+
1517
```bash
1618
./compare_batches.sh localhost:1633 other_domain
1719
```
@@ -32,3 +34,12 @@ The `compare_batches.sh` script:
3234
## Output
3335

3436
The script will display differences between the two batch endpoints side by side, or report "No differences found" if the responses are identical.
37+
38+
## Build & Push
39+
40+
To build and push the Docker image for this script, you can use the following commands:
41+
42+
```bash
43+
docker build -t your_dockerhub_username/compare_batches.sh:latest .
44+
docker push your_dockerhub_username/compare_batches.sh:latest
45+
```

scripts/compare_batches.sh

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ DOMAIN1=$1
1010
DOMAIN2=$2
1111
FILE1="1.txt"
1212
FILE2="2.txt"
13+
TMP1="tmp1.json"
14+
TMP2="tmp2.json"
1315

14-
# Perform curl requests in parallel
15-
curl -s "http://${DOMAIN1}/batches" | jq > "$FILE1" &
16+
# Fetch both responses in parallel
17+
curl -s "http://${DOMAIN1}/batches" > "$TMP1" &
1618
PID1=$!
17-
curl -s "http://${DOMAIN2}/batches" | jq > "$FILE2" &
19+
curl -s "http://${DOMAIN2}/batches" > "$TMP2" &
1820
PID2=$!
1921

20-
# Wait for both curl commands to complete
22+
# Wait and check each curl
2123
wait $PID1
2224
if [ $? -ne 0 ]; then
2325
echo "Error fetching data from ${DOMAIN1}"
@@ -30,13 +32,35 @@ if [ $? -ne 0 ]; then
3032
exit 1
3133
fi
3234

35+
# Get batch counts
36+
COUNT1=$(jq '.batches | length' "$TMP1" 2>/dev/null)
37+
COUNT2=$(jq '.batches | length' "$TMP2" 2>/dev/null)
38+
39+
# Validate batch presence
40+
if [ -z "$COUNT1" ] || [ "$COUNT1" -eq 0 ]; then
41+
echo "No batches found in response from ${DOMAIN1}"
42+
exit 1
43+
fi
44+
45+
if [ -z "$COUNT2" ] || [ "$COUNT2" -eq 0 ]; then
46+
echo "No batches found in response from ${DOMAIN2}"
47+
exit 1
48+
fi
49+
50+
# Print batch counts
51+
echo "Batch count from ${DOMAIN1}: $COUNT1"
52+
echo "Batch count from ${DOMAIN2}: $COUNT2"
53+
54+
# Strip batchTTL and save for comparison
55+
jq '.batches | map(del(.batchTTL))' "$TMP1" > "$FILE1"
56+
jq '.batches | map(del(.batchTTL))' "$TMP2" > "$FILE2"
57+
3358
# Compare the files and show differences side by side
3459
echo "Differences between ${FILE1} and ${FILE2} (side by side):"
35-
diff --side-by-side --suppress-common-lines "$FILE1" "$FILE2"
36-
37-
# Check if there were any differences
38-
if [ $? -eq 0 ]; then
60+
if diff --side-by-side --suppress-common-lines "$FILE1" "$FILE2"; then
3961
echo "No differences found."
62+
rm -f "$TMP1" "$TMP2"
4063
else
4164
echo "Differences found (see above)."
65+
exit 1
4266
fi

0 commit comments

Comments
 (0)