diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-10-04 15:56:05 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-10-10 17:44:35 +0100 |
commit | 328e1933d1ada8b99bc69c15c7cdb01f3ce04a1d (patch) | |
tree | f2a16fbff0e372fff8c57e5fc00364e9a2565881 | |
parent | 6f43693cfc58d5356fafd231f2a232eb2fd99ae5 (diff) |
Better testing for tests run on live site.
When the tests are run normally, using bin/run-tests, 00-check-config.t
is pointless as the config will have been newly set up from the example
file. To prevent running except through run-tests, check when test_mode
is set, dying if the live config file has been used.
-rw-r--r-- | perllib/FixMyStreet.pm | 3 | ||||
-rw-r--r-- | t/00-check-config.t | 51 |
2 files changed, 3 insertions, 51 deletions
diff --git a/perllib/FixMyStreet.pm b/perllib/FixMyStreet.pm index b3d963074..7ee497584 100644 --- a/perllib/FixMyStreet.pm +++ b/perllib/FixMyStreet.pm @@ -50,6 +50,9 @@ my $TEST_MODE = undef; sub test_mode { my $class = shift; $TEST_MODE = shift if scalar @_; + # Make sure we don't run on live config + # uncoverable branch true + die "Do not run tests except through run-tests\n" if $TEST_MODE && $CONF_FILE eq 'general.yml'; return $TEST_MODE; } diff --git a/t/00-check-config.t b/t/00-check-config.t deleted file mode 100644 index 00e782e74..000000000 --- a/t/00-check-config.t +++ /dev/null @@ -1,51 +0,0 @@ -use strict; -use warnings; - -use Test::More; -use YAML; - -use FixMyStreet; - -# check that all the fields listed in general.yml-example are also present in -# general.yml - helps prevent later test failures due to un-noticed additions to the -# config file. - -# This code will bail_out to prevent the test suite proceeding to save time if -# issues are found. - -# load the config file and store the contents in a readonly hash - -my $example_config = YAML::LoadFile( FixMyStreet->path_to("conf/general.yml-example") ); -my $CONF_FILE = $ENV{FMS_OVERRIDE_CONFIG} || 'general'; -my $local_config = YAML::LoadFile( FixMyStreet->path_to("conf/${CONF_FILE}.yml") ); - -# find all keys missing from each config -my @missing_from_example = find_missing( $example_config, $local_config ); -my @missing_from_local = find_missing( $local_config, $example_config ); - -if ( @missing_from_example || @missing_from_local ) { - - fail "Missing from 'general.yml': $_" for @missing_from_local; - fail "Missing from 'general.yml-example': $_" for @missing_from_example; - - # bail out to prevent other tests failing due to config issues - BAIL_OUT( "Config has changed" - . " - update your 'general.yml' and add/remove the keys listed above" ); -} -else { - pass "configs contain the same keys"; -} - -done_testing(); - -sub find_missing { - my $reference = shift; - my $config = shift; - my @missing = (); - - foreach my $key ( sort keys %$config ) { - push @missing, $key unless exists $reference->{$key}; - } - - return @missing; -} |