mirror of
https://github.com/thegeeklab/wait-for.git
synced 2024-11-28 15:20:35 +00:00
Add testing using bats
This commit is contained in:
parent
1168f11eab
commit
bcaf84ed35
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# OSX
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Node
|
||||||
|
node_modules
|
11
Dockerfile
Normal file
11
Dockerfile
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
FROM node:alpine
|
||||||
|
|
||||||
|
RUN apk add --no-cache bash
|
||||||
|
|
||||||
|
RUN mkdir -p /app
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY . /app
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
CMD ./node_modules/.bin/bats wait-for.bats
|
@ -40,3 +40,10 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
Ironically testing is done using [bats](https://github.com/sstephenson/bats), which on the other hand is depending on [bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)).
|
||||||
|
|
||||||
|
docker build -t wait-for .
|
||||||
|
docker run -t wait-for
|
5
package.json
Normal file
5
package.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"bats": "^0.4.2"
|
||||||
|
}
|
||||||
|
}
|
3
wait-for
3
wait-for
@ -22,7 +22,8 @@ USAGE
|
|||||||
wait_for() {
|
wait_for() {
|
||||||
command="$*"
|
command="$*"
|
||||||
for i in `seq $TIMEOUT` ; do
|
for i in `seq $TIMEOUT` ; do
|
||||||
nc -z "$HOST" "$PORT"
|
nc -z "$HOST" "$PORT" > /dev/null 2>&1
|
||||||
|
|
||||||
result=$?
|
result=$?
|
||||||
if [ $result -eq 0 ] ; then
|
if [ $result -eq 0 ] ; then
|
||||||
if [ -n "$command" ] ; then
|
if [ -n "$command" ] ; then
|
||||||
|
14
wait-for.bats
Normal file
14
wait-for.bats
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
@test "google should be immediately found" {
|
||||||
|
run ./wait-for google.com:80 -- echo 'success'
|
||||||
|
|
||||||
|
[ "$output" = "success" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "nonexistent server should not start command" {
|
||||||
|
run ./wait-for -t 1 noserver:9999 -- echo 'success'
|
||||||
|
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[ "$output" != "success" ]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user