Skip to content

Commit 0b5fdf6

Browse files
committed
Introduce shellcheck
* Enable shellcheck for broker-list.sh file, and fix up errors * Refactor tests to validate broker-list.sh changes
1 parent 404aabe commit 0b5fdf6

9 files changed

+92
-28
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ install:
99
- docker --version
1010
- docker-compose --version
1111
- docker build -t wurstmeister/kafka .
12+
- docker pull confluentinc/cp-kafkacat
1213

1314
before_script:
1415
- docker-compose -f test/docker-compose.yml up -d kafka zookeeper
1516
- docker-compose -f test/docker-compose.yml scale kafka=2
1617

1718
script:
19+
- shellcheck -s bash broker-list.sh
1820
- sleep 5 # Wait for containers to start
19-
- export BROKER_LIST=$(./test/internal-broker-list.sh)
20-
- docker-compose -f test/docker-compose.yml run tests
21+
- cd test && ./runAllTests.sh
2122

2223
after_script:
2324
- docker-compose stop

broker-list.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22

33
CONTAINERS=$(docker ps | grep 9092 | awk '{print $1}')
4-
BROKERS=$(for CONTAINER in $CONTAINERS; do docker port $CONTAINER 9092 | sed -e "s/0.0.0.0:/$HOST_IP:/g"; done)
5-
echo $BROKERS | sed -e 's/ /,/g'
4+
BROKERS=$(for CONTAINER in ${CONTAINERS}; do docker port "$CONTAINER" 9092 | sed -e "s/0.0.0.0:/$HOST_IP:/g"; done)
5+
echo "${BROKERS/$'\n'/,}"

test/test-001-read-write.sh renamed to test/001-read-write.kafkacat.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
testReadWrite() {
44
echo 'foo,bar' | kafkacat -b "$BROKER_LIST" -P -D, -t readwrite
55
kafkacat -b "$BROKER_LIST" -C -e -t readwrite
6-
return 0
76
}
87

98
testReadWrite

test/002-broker-list.kafka.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash -e
2+
3+
testBrokerList() {
4+
# Need to get the proxied ports for kafka
5+
PORT1=$(docker inspect -f '{{ index .NetworkSettings.Ports "9092/tcp" 0 "HostPort" }}' test_kafka_1)
6+
PORT2=$(docker inspect -f '{{ index .NetworkSettings.Ports "9092/tcp" 0 "HostPort" }}' test_kafka_2)
7+
8+
RESULT=$(HOST_IP=1.2.3.4 broker-list.sh)
9+
10+
echo "$RESULT"
11+
12+
if [[ "$RESULT" == "1.2.3.4$PORT1,1.2.3.4:$PORT2" || "$RESULT" == "1.2.3.4:$PORT2,1.2.3.4:$PORT1" ]]; then
13+
return 0
14+
else
15+
return 1
16+
fi
17+
}
18+
19+
testBrokerList

test/Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ To execute
99
```
1010
cd test
1111
docker-compose up -d zookeeper kafka
12-
docker-compose scale kafka=2 # or however many nodes you want
13-
BROKER_LIST=$(./internal-broker-list.sh) docker-compose run tests
12+
docker-compose scale kafka=2
13+
./runAllTests.sh
1414
```

test/docker-compose.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,24 @@ services:
1313
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
1414
volumes:
1515
- /var/run/docker.sock:/var/run/docker.sock
16-
tests:
16+
17+
kafkatest:
18+
image: wurstmeister/kafka
19+
volumes:
20+
- .:/tests
21+
- /var/run/docker.sock:/var/run/docker.sock
22+
working_dir: /tests
23+
entrypoint:
24+
- ./runTestPattern.sh
25+
- "*.kafka.sh"
26+
27+
kafkacattest:
1728
image: confluentinc/cp-kafkacat
1829
environment:
1930
BROKER_LIST: ${BROKER_LIST}
2031
volumes:
2132
- .:/tests
2233
working_dir: /tests
2334
entrypoint:
24-
- ./runTests.sh
35+
- ./runTestPattern.sh
36+
- "*.kafkacat.sh"

test/runAllTests.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash -e
2+
3+
BROKER_LIST=$(./internal-broker-list.sh)
4+
export BROKER_LIST
5+
6+
echo "BROKER_LIST=$BROKER_LIST"
7+
8+
runAll() {
9+
# Tests that require kafka
10+
docker-compose run --rm kafkatest
11+
12+
RESULT=$?
13+
if [[ $RESULT -eq 0 ]]; then
14+
# Tests that require kafkacat
15+
docker-compose run --rm kafkacattest
16+
RESULT=$?
17+
fi
18+
19+
return $RESULT
20+
}
21+
22+
runAll
23+
result=$?
24+
echo "exit status $result"
25+
exit $result

test/runTestPattern.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash -e
2+
3+
PATTERN=$1
4+
5+
echo ""
6+
echo ""
7+
echo "Running tests for pattern $PATTERN"
8+
9+
runPattern() {
10+
for t in $PATTERN; do
11+
echo
12+
echo "===================================="
13+
echo "testing '$t'"
14+
# shellcheck disable=SC1090
15+
( source "$t" )
16+
status=$?
17+
if [[ -z "$status" || ! "$status" -eq 0 ]]; then
18+
return $status
19+
fi
20+
done
21+
22+
return $?
23+
}
24+
25+
runPattern
26+
27+
exit $?

test/runTests.sh

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)