Testing Ntp and tzdata with Behat
Aug 13, 2011
2 minutes read

This is a followup of my previous Post about Behavior Driven Infrastructure.

Using Behat to Test a Server

Here’s an example for a Test for tzdata

Feature: tzdata Configuration
    As a Server
    I want to have a tzdata installation
    So that my calculations for various timezones are always correct

Scenario: The tzdata data Installation and Configuration

    Given i have the "tzdata" Package installed
    Then the directory "/usr/share/zoneinfo" should exist
    And the "tzdata" Package Version should match "2011(d|e)"
    And the file "/usr/share/zoneinfo/localtime" should exist
    And the file "/etc/localtime" should exist

Scenario: The tzdata checks for correct times

    When i execute "date"
    Then the output should match "CEST|CET"

    When i execute "date  --utc -d '2006-08-07 12:34:56-06:00'"
    Then the output should match "UTC"
    And the output should match "18:34:56"

    When i execute "TZ=Europe/London date -d '2006-08-07 12:34:56-06:00'"
    Then the output should match "BST|GMT"
    And the output should match "19:34:56"

Writing the Unit Tests

I’ve put up 2 examples, one for ntp and one for tzdata, on my Github here. The Code is very Quick’n’Dirty, just as a “see what is possible” quality.

Advantages

Now when a random Dictator somewhere decides that his Country should change the timezones again, you can setup a quick test, rollout the tests, then rollout a new tzdata and be assured that the Timezone changes reliably hit every Server.

This is a very Simple Test, but it is just here as an example and to explore the viability. For an Apache installation for example you could proceed to check Various configuration settings, check for helper services that need to be there, check your logfile collection is setup properly, check your logrotation, check if all PHP packages are installed and correctly configured.


Back to posts