From 7cdb43f17470432623ef76beac504528fefb5218 Mon Sep 17 00:00:00 2001 From: DeveloperDurp Date: Sun, 23 Oct 2022 18:28:55 +0000 Subject: [PATCH] Feature/pester (#321) * Update Branch in script * pester for configs * Update Branch in script * update describe * github action * test pipeline * test pipeline * test pipeline * test pipeline * test pipeline * test windows container * gui tests * Updated applications.json to stop failing test * test pipeline * test pipeline * test pipeline * add test for original values if tweak is configured * test pipeline * test pipeline * remove merge request * added test to ensure main script functions Co-authored-by: ChrisTitusTech Co-authored-by: DeveloperDurp --- .github/workflows/test.yaml | 24 +++++ .gitignore | 3 +- config/applications.json | 38 ++++++- pester/winutil.Tests.ps1 | 203 ++++++++++++++++++++++++++++++++++++ runspace.ps1 | 52 ++++----- 5 files changed, 289 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/test.yaml create mode 100644 pester/winutil.Tests.ps1 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000..f31be666 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,24 @@ +name: Pester + +on: [push] + +jobs: + test: + runs-on: windows-latest + steps: + - name: Check out repository code + uses: actions/checkout@v3 + with: + ref: ${{ github.head_ref }} + - name: pester_tests + id: pester_tests + uses: zyborg/pester-tests-report@v1 + with: + include_paths: pester + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: dump test results + shell: pwsh + run: | + Write-Host 'Total Tests Executed...: ${{ steps.pester_tests.outputs.total_count }}' + Write-Host 'Total Tests PASSED.....: ${{ steps.pester_tests.outputs.passed_count }}' + Write-Host 'Total Tests FAILED.....: ${{ steps.pester_tests.outputs.failed_count }}' \ No newline at end of file diff --git a/.gitignore b/.gitignore index e7a817c7..2b8b1668 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ winutil.exe.config winutil.pdb *.zip .vs/ -*.psd* \ No newline at end of file +*.psd* +pester.ps1 \ No newline at end of file diff --git a/config/applications.json b/config/applications.json index 269a072e..720b5d66 100644 --- a/config/applications.json +++ b/config/applications.json @@ -168,9 +168,6 @@ "Installslack": { "winget": "SlackTechnologies.Slack" }, - "Installspotify": { - "winget": "Spotify.Spotify" - }, "Installsteam": { "winget": "Valve.Steam" }, @@ -287,6 +284,39 @@ }, "Installjdownloader": { "winget": "AppWork.JDownloader" - } + }, + "Installsimplewall": { + "Winget": "Henry++.simplewall" + }, + "Installrustlang": { + "Winget": "Rustlang.Rust.MSVC" + }, + "Installalacritty": { + "Winget": "Alacritty.Alacritty" + }, + "Installkdenlive": { + "Winget": "KDE.Kdenlive" + }, + "Installglaryutilities": { + "Winget": "Glarysoft.GlaryUtilities" + }, + "Installtwinkletray": { + "Winget": "xanderfrangos.twinkletray" + }, + "Installidm": { + "Winget": "Tonec.InternetDownloadManager" + }, + "Installviber": { + "Winget": "Viber.Viber" + }, + "Installgit": { + "Winget": "Git.Git" + }, + "Installwiztree": { + "Winget": "AntibodySoftware.WizTree" + }, + "Installtor": { + "Winget": "TorProject.TorBrowser" + } } } diff --git a/pester/winutil.Tests.ps1 b/pester/winutil.Tests.ps1 new file mode 100644 index 00000000..15d70546 --- /dev/null +++ b/pester/winutil.Tests.ps1 @@ -0,0 +1,203 @@ +#region Configurable Variables + + <# + .NOTES + Use this section to configure testing variables. IE if the number of tabs change in the GUI update that variable here. + All variables need to be global to be passed between contexts + + #> + + $global:FormName = "Chris Titus Tech's Windows Utility" + +#endregion Configurable Variables + +#region Load Variables needed for testing + + #Config Files + $global:application = get-content ./config/applications.json | ConvertFrom-Json + $global:preset = get-content ./config/preset.json | ConvertFrom-Json + $global:feature = get-content ./config/feature.json | ConvertFrom-Json + $global:tweaks = get-content ./config/tweaks.json | ConvertFrom-Json + + #GUI + $global:sync = [Hashtable]::Synchronized(@{}) + $global:inputXML = get-content MainWindow.xaml + $global:inputXML = $global:inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^ - Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed." -} + try{$sync["Form"]=[Windows.Markup.XamlReader]::Load( $reader )} + catch [System.Management.Automation.MethodInvocationException] { + Write-Warning "We ran into a problem with the XAML code. Check the syntax for this control..." + write-host $error[0].Exception.Message -ForegroundColor Red + if ($error[0].Exception.Message -like "*button*"){ + write-warning "Ensure your <button in the `$inputXML does NOT have a Click=ButtonClick property. PS can't handle this`n`n`n`n"} + } + catch{#if it broke some other way 😀 + Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed." + } -# Store Form Objects In PowerShell -$xaml.SelectNodes("//*[@Name]") | ForEach-Object {$sync["$("$($psitem.Name)")"] = $sync["Form"].FindName($psitem.Name)} + # Store Form Objects In PowerShell + $xaml.SelectNodes("//*[@Name]") | ForEach-Object {$sync["$("$($psitem.Name)")"] = $sync["Form"].FindName($psitem.Name)} -#Gives every button the invoke-button function -$sync.keys | ForEach-Object { - if($sync.$psitem){ - if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "Button"){ - $sync["$psitem"].Add_Click({ - [System.Object]$Sender = $args[0] - Invoke-Button $Sender.name - }) + #Gives every button the invoke-button function + $sync.keys | ForEach-Object { + if($sync.$psitem){ + if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "Button"){ + $sync["$psitem"].Add_Click({ + [System.Object]$Sender = $args[0] + Invoke-Button $Sender.name + }) + } } } -} -$sync["Form"].ShowDialog() | out-null + $sync["Form"].ShowDialog() | out-null } <#