Skip to content

Commit

Permalink
Fixed tests and bugs found by tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisjbell committed Dec 1, 2023
1 parent f95b16b commit c01bdfc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/Genesis/Commands.pm
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,14 @@ sub set_top_path { # {{{
$requested_cwd
) unless $cwd;

if ( -f $cwd ) {
if ( -f $cwd || -f "${cwd}.yml" ) {
bail(
"#B{%s %s} cannot be called with a -C option pointing to a file",
"#B{%s %s} cannot be called specifying a file as an argument",
__FILE__, $COMMAND
) unless has_scope('env');
unshift(@COMMAND_ARGS, basename($cwd));
$cwd = dirname($cwd);
} elsif ($COMMAND eq 'create' && $cwd =~ /\.yml$/) {
} elsif ($COMMAND eq 'create' && ! -d $cwd) {
unshift(@COMMAND_ARGS, basename($cwd));
$cwd = dirname($cwd);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/Genesis/Env.pm
Original file line number Diff line number Diff line change
Expand Up @@ -698,13 +698,16 @@ sub vault_paths {
},
'spruce vaultinfo "$1" | spruce json', $unevaled_manifest
));
popd;

bail(
"Expecting spruce vaultinfo to return an array of secrets, got this instead:\n\n".
Dumper($json)
) unless ref($json) eq 'HASH' && ref($json->{secrets}) eq 'ARRAY' ;

my %secrets_map = map {($_->{key}, $_->{references})} @{$json->{secrets}};
my %secrets_map = map {
(($_->{key} =~ /^\// ? '':'/').$_->{key}, $_->{references})
} @{$json->{secrets}};
return \%secrets_map;
});
return $ref;
Expand Down
2 changes: 1 addition & 1 deletion t/00-utils.t
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ subtest 'output utilities' => sub {
trace("this is from 'trace'");
};
matches $out, "this is from first 'output'\nthis is from last 'output'\n", "output()s go to standard output in the right order";
matches $err, "[FATAL] this is from 'fatal'\n[ERROR] this is from 'error'\n[WARNING] this is from 'warning'\nthis is from 'info'\n[DEBUG] this is from 'debug'\n[TRACE] this is from 'trace'\n ^- t/00-utils.t:L154 (in main::__ANON__)\n", "with GENESIS_TRACE, you get trace to standard error";
matches $err, "[FATAL] this is from 'fatal'\n[ERROR] this is from 'error'\n[WARNING] this is from 'warning'\nthis is from 'info'\n[DEBUG] this is from 'debug'\n[TRACE] this is from 'trace'\n ^- t/00-utils.t:L154 (in main::__ANON__)\n\n", "with GENESIS_TRACE, you get trace to standard error";
}
$Genesis::Log::Logger = undef;
};
Expand Down
1 change: 1 addition & 0 deletions t/04-compiling.t
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ EOF
again();
system("rm -rf $kitdir");
$out = combined_from {
local $ENV{GENESIS_OUTPUT_COLUMNS} = 999; # tmpdir may be VERY long and cause wrapping
ok(!$cc->validate('test','1.2.3'), "validation should fail when the root directory is missing");
};
$out =~ s/$tmp/<tempdir>/;
Expand Down
20 changes: 18 additions & 2 deletions t/30-env.t
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,12 @@ subtest 'multidoc env files' => sub {
Genesis::Vault->clear_all();
my $top = Genesis::Top->create(workdir, 'thing', vault=>$VAULT_URL);
$top->link_dev_kit('t/src/fancy');
put_file $top->path(".cloud.yml"), <<EOF;
---
networks:
- name: dummy
EOF
put_file $top->path('standalone.yml'), <<'EOF';
---
kit:
Expand All @@ -426,7 +432,7 @@ params:
env: standalone
secret: (( vault $GENESIS_SECRETS_BASE "test:secret" ))
network: (( grab networks[0].name ))
junk: (( vault "secret/passcode" ))
junk: (( vault "secret/passcode:key" ))
---
genesis:
Expand All @@ -447,6 +453,7 @@ kit:
EOF

my $env = $top->load_env('standalone');
$env->use_config($top->path(".cloud.yml"));
cmp_deeply([$env->params], [{
kit => {
features => [ "oscar", "kilo" ],
Expand All @@ -457,7 +464,7 @@ EOF
env => "standalone"
},
params => {
junk => '(( vault "secret/passcode" ))',
junk => '(( vault "secret/passcode:key" ))',
network => '(( grab networks.0.name ))',
secret => '(( vault $GENESIS_SECRETS_BASE "test:secret" ))',
}
Expand All @@ -473,6 +480,14 @@ EOF
cmp_deeply([$env->actual_environment_files], [qw[
./standalone.yml
]], "env detects correct actual environment files to merge");
cmp_deeply($env->vault_paths, {
"/secret/standalone/thing/test:secret" => [
"params.secret"
],
"/secret/passcode:key" => [
"params.junk"
]
}, "env detects correct vault paths used");

put_file $top->path('standalone.yml'), <<'EOF';
---
Expand Down Expand Up @@ -522,6 +537,7 @@ EOF
meta => ignore,
params => ignore,
exodus => ignore,
networks => ignore,
genesis=> superhashof({
env => "standalone",
}),
Expand Down

0 comments on commit c01bdfc

Please sign in to comment.