sstephenson / bats

Bash Automated Testing System
MIT License
7.12k stars 518 forks source link

Trying one-time setup and teardown #193

Open ggardella opened 7 years ago

ggardella commented 7 years ago

I'm trying to test connectivity to a docker ghost container. I want to start the container and then test that I can use wget to pull the index.html. I have tried multiple ways of doing this, with the startup outside setup, inside setup and inside a test. I redirected my stdout and stderr per the guide. Here is what I currently have:

setup() { docker run --name ghost-test -p 8080:2368 -d ghost >/dev/null 2>&1 }

@test "Checking connectivity" { run wget http://myhost.domain.com:8080 [ $status -eq 0 ] }

This gives me: ✗ Checking connectivity (in test file /net/tas/export/users/ggardell/panamax/tests/test_ghost.bats, line 7) `' failed

1 test, 1 failure

If I start my container outside the script and remove that line from the bats file, my test passes. If I keep the run line, but move it outside setup(), it fails silently (no output at all). Ideally, I would like to have the startup in a test as well. So, startup test, connectivity test, stop test.