diff --git a/t/Config/include.t b/t/Config/include.t new file mode 100644 index 00000000..3e57b3d4 --- /dev/null +++ b/t/Config/include.t @@ -0,0 +1,26 @@ +use strict; +use Setup; + +my %ctx = test_init( + use_external_destination_store => 0, + hydra_config => "include foo.conf" +); + +write_file($ctx{'tmpdir'} . "/foo.conf", q| + + include bar.conf + +|); + +write_file($ctx{'tmpdir'} . "/bar.conf", q| + bar = baz +|); + +require Hydra::Helper::Nix; +use Test2::V0; + +is(Hydra::Helper::Nix::getHydraConfig(), { + foo => { bar => "baz" } +}, "Nested includes work."); + +done_testing; diff --git a/t/lib/Setup.pm b/t/lib/Setup.pm index 151e3d61..800c90eb 100644 --- a/t/lib/Setup.pm +++ b/t/lib/Setup.pm @@ -9,7 +9,7 @@ use File::Basename; use Cwd qw(abs_path getcwd); our @ISA = qw(Exporter); -our @EXPORT = qw(test_init hydra_setup nrBuildsForJobset queuedBuildsForJobset +our @EXPORT = qw(test_init hydra_setup write_file nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild sendNotifications updateRepository captureStdoutStderr); @@ -49,19 +49,16 @@ sub test_init { $ENV{'NIX_CONF_DIR'} = "$dir/nix/etc/nix"; make_path($ENV{'NIX_CONF_DIR'}); my $nixconf = "$ENV{'NIX_CONF_DIR'}/nix.conf"; - open(my $fh, '>', $nixconf) or die "Could not open file '$nixconf' $!"; - print $fh "sandbox = false\n"; - print $fh $opts{'nix_config'} || ""; - close $fh; - + my $nix_config = "sandbox = false\n" . $opts{'nix_config'}; + write_file($nixconf, $nix_config); $ENV{'HYDRA_CONFIG'} = "$dir/hydra.conf"; - open(my $fh, '>', $ENV{'HYDRA_CONFIG'}) or die "Could not open file '" . $ENV{'HYDRA_CONFIG'}. " $!"; + my $hydra_config = $opts{'hydra_config'} || ""; if ($opts{'use_external_destination_store'} // 1) { - print $fh "store_uri = file:$dir/nix/dest-store\n" + $hydra_config = "store_uri = file:$dir/nix/dest-store\n" . $hydra_config; } - print $fh $opts{'hydra_config'} || ""; - close $fh; + + write_file($ENV{'HYDRA_CONFIG'}, $hydra_config); $ENV{'NIX_LOG_DIR'} = "$dir/nix/var/log/nix"; $ENV{'NIX_REMOTE_SYSTEMS'} = ''; @@ -82,6 +79,13 @@ sub test_init { ); } +sub write_file { + my ($path, $text) = @_; + open(my $fh, '>', $path) or die "Could not open file '$path' $!"; + print $fh $text || ""; + close $fh; +} + sub captureStdoutStderr { # "Lazy"-load Hydra::Helper::Nix to avoid the compile-time # import of Hydra::Model::DB. Early loading of the DB class