config.t 3.04 KB
Newer Older
1 2
#!/usr/bin/env perl

3
# Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
nwillhoft's avatar
nwillhoft committed
4
# Copyright [2016-2021] EMBL-European Bioinformatics Institute
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#      http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


use strict;
use warnings;

use Cwd;
use File::Basename;
use Test::More;
use Data::Dumper;

BEGIN {
    use_ok( 'Bio::EnsEMBL::Hive::Utils::Config' );
    
}
#########################

# Need EHIVE_ROOT_DIR to access the default config file
$ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( File::Basename::dirname( Cwd::realpath($0) ) ) );

my @config_files = Bio::EnsEMBL::Hive::Utils::Config->default_config_files();
# diag "@config_files"; 

cmp_ok(@config_files, '>', 0, 'at least one got returned');
cmp_ok(@config_files, '<', 3, '1 or 2');

my $config = bless {_config_hash => {}}, 'Bio::EnsEMBL::Hive::Utils::Config';

my $json = $ENV{EHIVE_ROOT_DIR}.'/t/test_config.json';

my $simple = $config->load_from_json($json);
isa_ok($simple, 'HASH');
ok(exists($simple->{'Meadow'}), 'exists');

my $simpler = $config->load_from_json($json . '.notexist');
is($simpler, undef, 'undef, but no death');

$config->merge($simple);
my $merged = $config->config_hash;
ok($merged, 'merged hash');


$config = Bio::EnsEMBL::Hive::Utils::Config->new();
ok($config, 'new instance');


my $content = $config->config_hash;

isa_ok($content, 'HASH');
ok(exists($content->{'Meadow'}), 'Ok you are in a forest. Forest? With Heather...');

isa_ok($content->{'Meadow'}, 'HASH');

ok(exists($content->{'Valley'}), 'alpine valley?');

isa_ok($content->{'Valley'}, 'HASH');

ok(exists($content->{'Graph'}), 'lets plot that');

isa_ok($content->{'Graph'}, 'HASH');

ok(exists($content->{'VERSION'}), 'party on');

$config->merge($simple);
my $merged_hash = $config->config_hash;
isa_ok($merged_hash, 'HASH');
ok(exists($merged_hash->{'Meadow'}{'OPENLAVA'}),                               'first level merge');
ok(exists($merged_hash->{'Meadow'}{'OPENLAVA'}{'omics'}),                      'second level merge');
ok(exists($merged_hash->{'Meadow'}{'OPENLAVA'}{'omics'}{'SubmissionOptions'}), 'third level merge');
is($merged_hash->{'Meadow'}{'OPENLAVA'}{'TotalRunningWorkersMax'}, 1000,       'data check');

my $ol_submission_opts = $config->get(qw{Meadow OPENLAVA omics SubmissionOptions});
is($ol_submission_opts, '-q special-branch', 'get() functions');

$config->set(qw{Meadow OPENLAVA TotalRunningWorkersMax}, 20);
my $ol_total = $config->get(qw{Meadow OPENLAVA TotalRunningWorkersMax});
is($ol_total, 20, 'roundtrip set() and get() function');

done_testing();