Skip to content

Commit 8d8c5a0

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
Update registry test and add more debug traces so works for elevated
1 parent d29518a commit 8d8c5a0

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

registry/src/main.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ use registry_helper::RegistryHelper;
1212
use schemars::schema_for;
1313
use std::process::exit;
1414
use tracing::{debug, error};
15-
use tracing_subscriber::{EnvFilter, Layer, prelude::__tracing_subscriber_SubscriberExt};
16-
15+
use tracing_subscriber::{filter::LevelFilter, prelude::__tracing_subscriber_SubscriberExt, EnvFilter, Layer};
1716
use crate::config::Registry;
1817

1918
mod args;
@@ -49,6 +48,7 @@ fn main() {
4948
args::SubCommand::Config { subcommand } => {
5049
match subcommand {
5150
args::ConfigSubCommand::Get{input} => {
51+
debug!("Get input: {input}");
5252
let reg_helper = match RegistryHelper::new(&input) {
5353
Ok(reg_helper) => reg_helper,
5454
Err(err) => {
@@ -68,6 +68,7 @@ fn main() {
6868
}
6969
},
7070
args::ConfigSubCommand::Set{input, what_if} => {
71+
debug!("Set input: {input}, what_if: {what_if}");
7172
let mut reg_helper = match RegistryHelper::new(&input) {
7273
Ok(reg_helper) => reg_helper,
7374
Err(err) => {
@@ -92,6 +93,7 @@ fn main() {
9293
}
9394
},
9495
args::ConfigSubCommand::Delete{input} => {
96+
debug!("Delete input: {input}");
9597
let reg_helper = match RegistryHelper::new(&input) {
9698
Ok(reg_helper) => reg_helper,
9799
Err(err) => {
@@ -120,9 +122,8 @@ fn main() {
120122
}
121123

122124
pub fn enable_tracing() {
123-
let filter = EnvFilter::try_from_default_env()
124-
.or_else(|_| EnvFilter::try_new("trace"))
125-
.unwrap_or_default();
125+
// default filter to trace level
126+
let filter = EnvFilter::builder().with_default_directive(LevelFilter::TRACE.into()).parse("").unwrap();
126127
let layer = tracing_subscriber::fmt::Layer::default().with_writer(std::io::stderr);
127128
let fmt = layer
128129
.with_ansi(false)

registry/tests/registry.config.get.tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ Describe 'Registry config get tests' {
3535
# keyPath should return Access Denied
3636
$json = @'
3737
{
38-
"keyPath": "HKLM\\SYSTEM\\CurrentControlSet\\Control\\SecurePipeServers\\Winreg"
38+
"keyPath": "HKLM\\SYSTEM\\CurrentControlSet\\Control"
3939
}
4040
'@
4141
$out = registry config get --input $json 2>&1
42-
$LASTEXITCODE | Should -Be 3
42+
$LASTEXITCODE | Should -Be 0
4343
$result = $out | ConvertFrom-Json
44-
$result.level | Should -BeExactly 'ERROR'
45-
$result.fields.message | Should -BeLike '*Permission denied*'
44+
$result[0].level | Should -BeExactly 'DEBUG'
45+
$result[0].fields.message | Should -BeLike 'Get Input:*'
4646
}
4747
}

0 commit comments

Comments
 (0)