Skip to content

Config::Model: How to test configuration models

October 30, 2011

Hello

With Config::Model, configuration models are created to validate configuration data.

But, before that, how can we validate a model ? This has long been a sore spot of Config::Model. During its development, I’ve progressively enhanced a test script to tests the various models (and their corner cases) shipped with Config::Model. This script is able to test several models with several subtests. Currently, more that 400 unit tests are done on 5 models and about 50 configuration files.

Which is great, but usable only inside Config::Model distribution. Which is not so great …

So I’ve bitten the bullet and created a new Config::Model::Tester class from this test script. This new class is shipped with Config::Model 1.260 (also available on Debian/sid).

For instance, let’s see how this tester is used to test Xorg model (shipped in Config::Model::Xorg).

Xorg features a small test file (t/model_test.t):

use warnings;
use strict;
use Config::Model::Tester ;
use ExtUtils::testlib;

my $arg = shift || '';
my $test_only_model = shift || '';
my $do = shift ;

run_tests($arg, $test_only_model, $do) ;

The xorg files to test are specified by t/model_tests.d/xorg-test-conf.pl:

$conf_file_name = "xorg.conf" ;
$conf_dir = "etc/X11" ;
$model_to_test = "Xorg" ;

@tests = (
    { name => 'fglrx', },
    { name => 'modern', },
    { name => 'vesa', },
    { name => 'xorg', },
    { name => 'xorg-ati', },
);

1;

And the xorg.conf files are there:

$ ls t/model_tests.d/xorg-examples/
fglrx  modern  vesa  xorg  xorg-ati

Here’s the output of the xorg-ati subtest:

$ perl -Ilib t/model_tests.t x xorg xorg-ati
ok 1 - compiled
# Beginning xorg test (t/model_tests.d/xorg-test-conf.pl)
# xorg uses Xorg model on file xorg.conf
# Beginning subtest xorg xorg-ati
ok 2 - Copied xorg example xorg-ati
ok 3 - Read wr_root/test-xorg-ati/etc/X11/xorg.conf and created instance with init() method with warning check 
ok 4 - Ran dump_tree
ok 5 - Dumped xorg config tree in full mode
ok 6 - Dumped xorg config tree in custom mode
ok 7 - xorg write back done
ok 8 - Created instance xorg-test-xorg-ati-w
ok 9 - Dumped xorg 2nd config tree in custom mode
ok 10 - compare original xorg custom data with 2nd instance custom data
ok 11 - check that original xorg file was not clobbered
# End of subtest xorg xorg-ati
# End of xorg test
1..11

Now, it’s quite easy to create non regression tests for bug triggered by err, unexpected, configuration files: Just drop the file in the example directory and edit the *-test-conf.pl file. This saves a lot of typing.

All the best

Advertisements

From → Config::Model, Perl

2 Comments
  1. Cool!
    I see this on Model::Xorg page:

    Config::Model::Backend::Xorg Read and write config from fstab file

    Should the description be fixed?
    And, what models/backend are planned to be made in near future?

  2. Ahem, yes, the description should be fixed. I’ve cut’n’pasted doc from fstab backend, edited the body … and forgot to update the description.

    In the near future, I will probably go on enhancing model for Debian package format and work with upstream lcdproc to find ways to re-use (or factorize) upstream configuration doc and examples. See my previous blog on generating model from lcdproc template configuration.

    That said, I’d welcome help on other models like Kerberos, fstab, Xorg… I’d also welcome people to create models to scratch their own itch.

    All the best

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: