NAME

Test::Clustericious::Config - Test Clustericious::Config

VERSION

version 0.9940_01

SYNOPSIS

use Test::Clustericious::Config;
use Clustericious::Config;
use Test::More tets => 2;

create_config_ok 'Foo', { url => 'http://localhost:1234' };
my $config = Clustericious::Config->new('Foo');
is $config->url, "http://localhost:1234";

To test against a Clustericious application MyApp:

use Test::Clustericious::Config;
use Test::Clustericious;
use Test::More tests => 3;

create_config_ok 'MyApp', { x => 1, y => 2 }; 
my $t = Test::Clustericious->new('MyApp');

$t->get_ok('/');

is $t->app->config->x, 1;

To test against multiple Clustericious applications MyApp1, MyApp2 (can also be the same app with different config):

use Test::Clustericious::Config;
use Test::Clustericious;
use Test::More tests => 4;

create_config_ok 'MyApp1', {};
my $t1 = Test::Clustericious->new('MyApp1');

$t1->get_ok('/');

create_config_ok 'MyApp2', { my_app1_url => $t1->app_url };
my $t2 = Test::Clustericious->new('MyApp2');

$t2->get_ok('/');

DESCRIPTION

This module provides an interface for testing Clustericious configurations, or Clustericious applications which use a Clustericious configuration.

It uses File::HomeDir::Test to isolate your test environment from any configurations you may have in your ~/etc. Keep in mind that this means that $HOME and friends will be in a temporary directory and removed after the test runs. It also means that the caveats for File::HomeDir::Test apply when using this module as well (ie. this should be the first module that you use in your test after use strict and use warnings).

FUNCTIONS

create_config_ok $name, $config, [$test_name]

Create a Clustericious config with the given $name. If $config is a reference then it will create the configuration file with YAML::XS::DumpFile, if it is a scalar, it will will write the scalar out to the config file. Thus these three examples should create a config with the same values (though in different formats):

hash reference:

create_config_ok 'Foo', { url => 'http://localhost:1234' }];

YAML:

create_config_ok 'Foo', <<EOF;
---
url: http://localhost:1234
EOF

JSON:

create_config_ok 'Foo', <<EOF;
{"url":"http://localhost:1234"}
EOF

In addition to being a test that will produce a ok/not ok result as output, this function will return the full path to the configuration file created.

create_directory_ok $path, [$test_name]

Creates a directory in your test environment home directory. This directory will be recursively removed when your test terminates. This function returns the full path of the directory created.

home_directory_ok [$test_name]

Tests that the temp home directory has been created okay. Returns the full path of the home directory.

create_config_helper_ok $helper_name, $helper_coderef, [ $test_name ]

Install a helper which can be called from within a configuration template. Example:

my $counter;
create_config_helper_ok 'counter', sub { $counter++ };
create_config_ok 'MyApp', <<EOF;
---
one: <%= counter %>
two: <%= counter %>
three: <% counter %>
EOF

EXAMPLES

Here is an (abbreviated) example from Yars that show how to test against an app where you need to know the port/url of the app in the configuration file:

use Test::Mojo;
use Test::More tests => 1;
use Test::Clustericious::Config;
use Mojo::UserAgent;
use Yars;

my $t = Test::Mojo->new;
$t->ua(do {
  my $ua = Mojo::UserAgent->new;
  create_config_ok 'Yars', {
    url => $ua->app_url,
    servers => [ {
      url => $ua->app_url,
    } ]
  };
  $ua->app(Yars->new);
  $ua
};

$t->get_ok('/status');

To see the full tests see t/073_tempdir.t in the Yars distribution.

AUTHOR

original author: Brian Duggan

current maintainer: Graham Ollis <plicease@cpan.org>

contributors:

Curt Tilmes

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by NASA GSFC.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.