2024-01-26 02:03:08 +00:00
use feature 'unicode_strings' ;
use strict ;
use warnings ;
use Setup ;
my % ctx = test_init (
nix_config = > qq |
experimental - features = ca - derivations
| ,
) ;
require Hydra::Schema ;
require Hydra::Model::DB ;
use JSON::MaybeXS ;
use HTTP::Request::Common ;
use Test2::V0 ;
require Catalyst::Test ;
Catalyst::Test - > import ( 'Hydra' ) ;
my $ db = Hydra::Model::DB - > new ;
hydra_setup ( $ db ) ;
my $ project = $ db - > resultset ( 'Projects' ) - > create ( { name = > "tests" , displayname = > "" , owner = > "root" } ) ;
my $ jobset = createBaseJobset ( "content-addressed" , "content-addressed.nix" , $ ctx { jobsdir } ) ;
ok ( evalSucceeds ( $ jobset ) , "Evaluating jobs/content-addressed.nix should exit with return code 0" ) ;
2024-04-03 20:45:53 +00:00
is ( nrQueuedBuildsForJobset ( $ jobset ) , 6 , "Evaluating jobs/content-addressed.nix should result in 6 builds" ) ;
2024-01-26 02:03:08 +00:00
for my $ build ( queuedBuildsForJobset ( $ jobset ) ) {
ok ( runBuild ( $ build ) , "Build '" . $ build - > job . "' from jobs/content-addressed.nix should exit with code 0" ) ;
my $ newbuild = $ db - > resultset ( 'Builds' ) - > find ( $ build - > id ) ;
is ( $ newbuild - > finished , 1 , "Build '" . $ build - > job . "' from jobs/content-addressed.nix should be finished." ) ;
2024-04-03 20:45:53 +00:00
my $ expected = $ build - > job eq "fails" ? 1 : $ build - > job =~ /with_failed/ ? 6 : $ build - > job =~ /FailingCA/ ? 2 : 0 ;
2024-01-26 02:03:08 +00:00
is ( $ newbuild - > buildstatus , $ expected , "Build '" . $ build - > job . "' from jobs/content-addressed.nix should have buildstatus $expected." ) ;
my $ response = request ( "/build/" . $ build - > id ) ;
ok ( $ response - > is_success , "The 'build' page for build '" . $ build - > job . "' should load properly" ) ;
if ( $ newbuild - > buildstatus == 0 ) {
my $ buildOutputs = $ newbuild - > buildoutputs ;
for my $ output ( $ newbuild - > buildoutputs ) {
# XXX: This hardcodes /nix/store/.
# It's fine because in practice the nix store for the tests will be of
# the form `/some/thing/nix/store/`, but it would be cleaner if there
# was a way to query Nix for its store dir?
like (
$ output - > path , qr|/nix/store/| ,
"Output '" . $ output - > name . "' of build '" . $ build - > job . "' should be a valid store path"
) ;
}
}
}
2024-04-03 20:55:00 +00:00
# XXX: deststoredir is undefined: Use of uninitialized value $ctx{"deststoredir"} in concatenation (.) or string at t/content-addressed/basic.t line 58.
# XXX: This test seems to not do what it seems to be doing. See documentation: https://metacpan.org/pod/Test2::V0#isnt($got,-$do_not_want,-$name)
2024-01-26 02:03:08 +00:00
isnt ( <$ctx{deststoredir}/realisations/*> , "" , "The destination store should have the realisations of the built derivations registered" ) ;
done_testing ;