Mac Unit Test part 1: Testing servers and ports
11 Jun 2006 10:32 - (0) comments
I've been thinking about unit testing my Mac after finding out some things didn't work as I thought they should. For example my rsync scripts didn't sync aliased directories.
I also had a problem with local web applications. On the mac there is a Personal Websharing option in the firewall. Turning it on/off also starts/stops the default Apache server. I didn't know it also worked the other way round: stopping/starting Apache turns the Personal Firewall off/on. So I had web applications running on my Mac that I were open to anyone on my local network.
So now I'm using unit tests to check things. Let's start with checking open ports and seeing if all expected servers are running. I have the following Twill script running in the crontab of another machine (my backup server). It checks open ports and some critical URL's.
#!/opt/local/bin/python
from twill.commands import *
from twill.errors import *
import twill, xml.dom.minidom, sys, string, datetime
import loggingserver = "http://petrik.local"
#main methods
def eval_test(url, test, msg):
go(url)
try:
eval(test)
except TwillAssertionError, errstr:
print (eval(msg) + " at " + url)def test_find(url, test):
eval_test(url, "find('" + test + "')", "Could not find " + test)def test_notfind(url, test):
eval_test(url, "notfind('" + test + "')", "Found " + test)def test_statuscode(url, test):
eval_test(url, "code(" + str(test) + ")", "str(errstr)")#Application
test_find(server + "/", "morecrap")
test_statuscode(server + "/~petrik/", 403)
test_statuscode(server + ":8080/", 200)
To install Twill: run the Twill setup.py install after installing setup tools.
Mac Unit Test part 2: Checking disk space
Comments
No comments allowed.