Developer-Dashboard
view release on metacpan or search on metacpan
t/12-legacy-helper-coverage.t view on Meta::CPAN
);
is( $cd_result, $project, 'Folder cd yields the target directory to the callback' );
my @folder_listing = Developer::Dashboard::Folder->ls('alias_demo');
ok( @folder_listing >= 0, 'Folder ls returns entries for a real directory' );
{
my $blocked = File::Spec->catdir( $home, 'permission-blocked-folder' );
mkdir $blocked or die "Unable to create $blocked: $!";
chmod 0000, $blocked or die "Unable to restrict $blocked: $!";
if ( opendir my $probe, $blocked ) {
closedir $probe or die "Unable to close permission probe for $blocked: $!";
chmod 0700, $blocked or die "Unable to restore $blocked: $!";
pass('Folder permission failure paths are not asserted when this runtime can still read a mode-0000 directory');
pass('Folder permission failure paths are not asserted when this runtime can still read a mode-0000 directory');
}
else {
ok( !defined Developer::Dashboard::Folder->cd( $blocked, sub { return 1 } ), 'Folder cd returns undef when chdir is denied' );
is_deeply( [ Developer::Dashboard::Folder->ls($blocked) ], [], 'Folder ls returns an empty list when opendir is denied' );
}
chmod 0700, $blocked or die "Unable to restore $blocked: $!";
}
ok( grep( { $_ eq $project } Developer::Dashboard::Folder->locate('demo') ), 'Folder locate finds matching workspace directories' );
is( Developer::Dashboard::Folder->alias_demo, $project, 'Folder AUTOLOAD resolves configured aliases' );
{
my $repo = File::Spec->catdir( $workspace, 'folder-config-repo' );
make_path( File::Spec->catdir( $repo, '.git' ) );
make_path( File::Spec->catdir( $repo, '.developer-dashboard', 'config' ) );
open my $fh, '>', File::Spec->catfile( $repo, '.developer-dashboard', 'config', 'config.json' ) or die $!;
print {$fh} <<'JSON';
{
"path_aliases": {
"docker": "~/docker-alias"
}
}
JSON
close $fh;
my $docker_alias = File::Spec->catdir( $home, 'docker-alias' );
make_path($docker_alias);
local $Developer::Dashboard::Folder::PATHS = undef;
local %Developer::Dashboard::Folder::ALIASES = ();
local %Developer::Dashboard::Folder::CONFIG_ALIASES = ();
local $Developer::Dashboard::Folder::CONFIG_ALIASES_KEY = '';
my $cwd = Cwd::cwd();
chdir $repo or die "Unable to chdir to $repo: $!";
is( Developer::Dashboard::Folder->docker, $docker_alias, 'Folder AUTOLOAD lazily resolves config-backed path aliases in a plain Perl process' );
chdir $cwd or die "Unable to chdir to $cwd: $!";
}
my $zipped = zip('print qq{ok};');
ok( $zipped->{raw}, 'zip returns a raw token' );
is( unzip( $zipped->{raw} ), 'print qq{ok};', 'unzip reverses raw tokens' );
like( __cmdx( perl => 'print 1;' ), qr/base64 -d \| gunzip/, '__cmdx builds a shell decode pipeline' );
my @cmdx = _cmdx( perl => 'print 1;' );
is_deeply( [ @cmdx[ 0, 1 ] ], [ 'perl', '-e' ], '_cmdx returns shell tuple metadata' );
my @cmdp = _cmdp( perl => 'print 1;' );
is( $cmdp[1], 'perl', '_cmdp returns pipeline metadata' );
my $ajax_url = acmdx( type => 'json', code => 'print qq{{}};' );
like( $ajax_url->{url}{tokenised}, qr{^/ajax\?token=}, 'acmdx builds a tokenised ajax url' );
my $ajax_singleton_url = acmdx( type => 'text', code => 'print qq{ok};', singleton => 'TRANSIENT' );
like( $ajax_singleton_url->{url}{tokenised}, qr/[?&]singleton=TRANSIENT/, 'acmdx carries the optional singleton value into transient ajax urls' );
my ( $ajax_stdout, undef, $ajax_result ) = capture {
return Ajax( jvar => 'configs.coverage.endpoint', code => 'print qq{{}};' );
};
like( $ajax_stdout, qr/set_chain_value/, 'Ajax prints the legacy config-binding script' );
is( $ajax_result, 'HIDE-THIS', 'Ajax returns the legacy hide marker' );
my ( $templated_ajax_stdout, undef, $templated_ajax_result ) = capture {
return Ajax(
jvar => 'configs.coverage.template',
data => { args => 123 },
code => 'my $foobar = [% args %];',
);
};
my ($templated_ajax_token) = $templated_ajax_stdout =~ /[?&]token=([^&']+)/;
ok( defined $templated_ajax_token, 'templated Ajax emits a transient payload token' );
is(
unzip( uri_unescape($templated_ajax_token) ),
'my $foobar = 123;',
'Ajax templates its Perl code using data before encoding the transient URL payload',
);
is( $templated_ajax_result, 'HIDE-THIS', 'templated Ajax code still returns the legacy hide marker' );
my ( $ajax_singleton_stdout, undef, $ajax_singleton_result ) = capture {
return Ajax( jvar => 'configs.coverage.endpoint', code => 'print qq{{}};', singleton => 'TRANSIENT' );
};
like( $ajax_singleton_stdout, qr/[?&]singleton=TRANSIENT/, 'Ajax carries the optional singleton value into transient ajax bindings' );
is( $ajax_singleton_result, 'HIDE-THIS', 'Ajax still returns the hide marker when a transient singleton is supplied' );
{
local $Developer::Dashboard::Zipper::AJAX_CONTEXT = {
source => 'saved',
page_id => 'coverage-page',
runtime_root => $paths->runtime_root,
allow_transient_urls => 0,
};
my ( $saved_ajax_stdout, undef, $saved_ajax_result ) = capture {
return Ajax(
jvar => 'configs.coverage.saved',
file => 'coverage.json',
singleton => 'coverage-stream',
code => 'print qq{{"ok":1}};',
);
};
like( $saved_ajax_stdout, qr{/ajax/coverage\.json\?type=text&singleton=coverage-stream}, 'Ajax prints a saved bookmark ajax url with the default text type and singleton when a file name is supplied' );
is( $saved_ajax_result, 'HIDE-THIS', 'saved bookmark Ajax still returns the hide marker' );
ok( -f Developer::Dashboard::Zipper::saved_ajax_file_path( runtime_root => $paths->runtime_root, file => 'coverage.json' ), 'saved bookmark Ajax stores the named ajax code file under the dashboards ajax tree' );
ok( -x Developer::Dashboard::Zipper::saved_ajax_file_path( runtime_root => $paths->runtime_root, file => 'coverage.json' ), 'saved bookmark Ajax marks the stored dashboards ajax tree file executable' );
is( Developer::Dashboard::Zipper::load_saved_ajax_code( runtime_root => $paths->runtime_root, file => 'coverage.json' ), 'print qq{{"ok":1}};', 'saved bookmark Ajax stored code can be loaded back from the dashboards ajax tree' );
my $saved_ajax_error = eval {
Ajax(
jvar => 'configs.coverage.saved',
code => 'print qq{{"ok":1}};',
);
'';
} || $@;
like( $saved_ajax_error, qr/file is required/, 'saved bookmark Ajax requires a file name when transient token urls are disabled' );
}
{
my $existing_path = Developer::Dashboard::Zipper::saved_ajax_file_path(
runtime_root => $paths->runtime_root,
file => 'existing.sh',
);
my $existing_dir = dirname($existing_path);
make_path($existing_dir);
open my $fh, '>', $existing_path or die $!;
print {$fh} "#!/bin/sh\nprintf 'existing coverage\\n'\n";
close $fh;
chmod 0700, $existing_path or die $!;
local $Developer::Dashboard::Zipper::AJAX_CONTEXT = {
source => 'saved',
page_id => 'coverage-existing',
runtime_root => $paths->runtime_root,
allow_transient_urls => 0,
};
my ( $stdout, undef, $result ) = capture {
return Ajax(
jvar => 'configs.coverage.existing',
file => 'existing.sh',
type => 'text',
);
};
like( $stdout, qr{/ajax/existing\.sh\?type=text}, 'Ajax prints a saved bookmark ajax url when only an existing file name is supplied' );
is( $result, 'HIDE-THIS', 'saved bookmark Ajax with only a file still returns the hide marker' );
is( Developer::Dashboard::Zipper::load_saved_ajax_code( runtime_root => $paths->runtime_root, file => 'existing.sh' ), "#!/bin/sh\nprintf 'existing coverage\\n'\n", 'saved bookmark Ajax with only a file leaves the existing executable content unch...
( run in 1.120 second using v1.01-cache-2.11-cpan-16aabcbfbcb )