mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-14 06:35:51 -06:00
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 <ChrisTitusTech@users.noreply.github.com> Co-authored-by: DeveloperDurp <DeveloperDurp@users.noreply.github.com>
This commit is contained in:
parent
10b8df78db
commit
7cdb43f174
24
.github/workflows/test.yaml
vendored
Normal file
24
.github/workflows/test.yaml
vendored
Normal file
@ -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 }}'
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -8,4 +8,5 @@ winutil.exe.config
|
||||
winutil.pdb
|
||||
*.zip
|
||||
.vs/
|
||||
*.psd*
|
||||
*.psd*
|
||||
pester.ps1
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
203
pester/winutil.Tests.ps1
Normal file
203
pester/winutil.Tests.ps1
Normal file
@ -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 '^<Win.*', '<Window'
|
||||
[xml]$global:XAML = $global:inputXML
|
||||
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
|
||||
$global:reader = (New-Object System.Xml.XmlNodeReader $global:xaml)
|
||||
$global:sync["Form"] = [Windows.Markup.XamlReader]::Load( $global:reader )
|
||||
$global:xaml.SelectNodes("//*[@Name]") | ForEach-Object {$sync["$("$($psitem.Name)")"] = $sync["Form"].FindName($psitem.Name)}
|
||||
|
||||
#Variables to compare GUI to config files
|
||||
$Global:GUIFeatureCount = ($global:feature.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"}).count
|
||||
$Global:GUITabCount = ($global:sync["TabNav"].Items.name).count
|
||||
$Global:GUIApplicationCount = ($global:application.install.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"}).count
|
||||
$Global:GUITweaksCount = ($global:tweaks.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"}).count
|
||||
|
||||
#dotsource original script to pull in all variables and ensure no errors
|
||||
$script = Get-Content .\winutil.ps1
|
||||
$output = $script[0..($script.count - 2)] | Out-File .\pester.ps1
|
||||
|
||||
#endregion Load Variables needed for testing
|
||||
|
||||
#===========================================================================
|
||||
# Tests - Json
|
||||
#===========================================================================
|
||||
|
||||
Describe "Json Files" {
|
||||
Context "Application installs" {
|
||||
It "Imports with no errors" {
|
||||
$global:application | should -Not -BeNullOrEmpty
|
||||
}
|
||||
It "Json should be in correct format" {
|
||||
$winget = $global:application.install.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"} | Select-Object Name,Value
|
||||
$winget.name | should -BeLike "*Install*"
|
||||
$winget.winget | should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
|
||||
Context "Preset" {
|
||||
It "Imports with no errors" {
|
||||
$global:preset | should -Not -BeNullOrEmpty
|
||||
}
|
||||
It "Json should be in correct format" {
|
||||
$preset = $global:preset.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"} | Select-Object Name,Value
|
||||
$preset.name | should -Not -BeNullOrEmpty
|
||||
$preset.Value | should -BeLike "*Tweaks*"
|
||||
}
|
||||
}
|
||||
|
||||
Context "feature" {
|
||||
It "Imports with no errors" {
|
||||
$global:feature | should -Not -BeNullOrEmpty
|
||||
}
|
||||
It "Json should be in correct format" {
|
||||
$feature = $global:feature.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"} | Select-Object Name,Value
|
||||
$feature.name | should -BeLike "*Feature*"
|
||||
$feature.Value | should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
|
||||
Context "tweaks" {
|
||||
It "Imports with no errors" {
|
||||
$global:tweaks | should -Not -BeNullOrEmpty
|
||||
}
|
||||
It "Json should be in correct format" {
|
||||
$tweaks = $global:tweaks.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"} | Select-Object Name,Value
|
||||
$tweaks.name | should -BeLike "*Tweaks*"
|
||||
$tweaks.Value.registry | should -Not -BeNullOrEmpty
|
||||
$tweaks.Value.Service | should -Not -BeNullOrEmpty
|
||||
$tweaks.Value.ScheduledTask | should -Not -BeNullOrEmpty
|
||||
$tweaks.Value.Appx | should -Not -BeNullOrEmpty
|
||||
$tweaks.Value.InvokeScript | should -Not -BeNullOrEmpty
|
||||
}
|
||||
It "Original Values should be set" {
|
||||
$tweaks = $global:tweaks.psobject.members | Where-Object {$psitem.MemberType -eq "NoteProperty"} | Select-Object Name,Value
|
||||
|
||||
Foreach($tweak in $tweaks){
|
||||
if($tweak.value.registry){
|
||||
|
||||
$values = $tweak.value | Select-Object -ExpandProperty registry
|
||||
|
||||
Foreach ($value in $values){
|
||||
$value.OriginalValue | should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
if($tweak.value.Service){
|
||||
|
||||
$values = $tweak.value | Select-Object -ExpandProperty Service
|
||||
|
||||
Foreach ($value in $values){
|
||||
$value.OriginalType | should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
if($tweak.value.ScheduledTask){
|
||||
|
||||
$values = $tweak.value | Select-Object -ExpandProperty ScheduledTask
|
||||
|
||||
Foreach ($value in $values){
|
||||
$value.OriginalState | should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#===========================================================================
|
||||
# Tests - GUI
|
||||
#===========================================================================
|
||||
|
||||
Describe "GUI" {
|
||||
|
||||
Context "XML" {
|
||||
It "Imports with no errors" {
|
||||
$global:XAML | should -Not -BeNullOrEmpty
|
||||
}
|
||||
It "Title should be $global:FormName" {
|
||||
$global:XAML.window.Title | should -Be $global:FormName
|
||||
}
|
||||
}
|
||||
|
||||
Context "Form" {
|
||||
It "Imports with no errors" {
|
||||
$global:sync["Form"] | should -Not -BeNullOrEmpty
|
||||
}
|
||||
It "Title should match XML" {
|
||||
$global:sync["Form"].title | should -Be $global:XAML.window.Title
|
||||
}
|
||||
It "Tabs should be $Global:GUITabCount" {
|
||||
($global:sync.keys | Where-Object {$psitem -like "Tab?"}).count | should -Be $Global:GUITabCount
|
||||
}
|
||||
It "Features should be $Global:GUIFeatureCount" {
|
||||
($global:sync.keys | Where-Object {
|
||||
$psitem -like "*feature*" -and
|
||||
$psitem -notlike "FeatureInstall"
|
||||
}).count | should -Be $Global:GUIFeatureCount
|
||||
}
|
||||
It "Applications should be $Global:GUIApplicationCount" {
|
||||
($global:sync.keys | Where-Object {
|
||||
$psitem -like "*Install*" -and
|
||||
$psitem -notlike "Install" -and
|
||||
$psitem -notlike "InstallUpgrade" -and
|
||||
$psitem -notlike "featureInstall"
|
||||
}).count | should -Be $Global:GUIApplicationCount
|
||||
}
|
||||
It "Tweaks should be $Global:GUITweaksCount" {
|
||||
($global:sync.keys | Where-Object {
|
||||
$psitem -like "*tweaks*" -and
|
||||
$psitem -notlike "tweaksbutton"
|
||||
}).count | should -Be $Global:GUITweaksCount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#===========================================================================
|
||||
# Tests - GUI
|
||||
#===========================================================================
|
||||
|
||||
Describe "GUI Functions" {
|
||||
|
||||
It "GUI should load with no errors" {
|
||||
. .\pester.ps1
|
||||
$WPFTab1BT | should -Not -BeNullOrEmpty
|
||||
$WPFundoall | should -Not -BeNullOrEmpty
|
||||
$WPFPanelDISM | should -Not -BeNullOrEmpty
|
||||
$WPFPanelAutologin | should -Not -BeNullOrEmpty
|
||||
$WPFUpdatesdefault | should -Not -BeNullOrEmpty
|
||||
$WPFFixesUpdate | should -Not -BeNullOrEmpty
|
||||
$WPFUpdatesdisable | should -Not -BeNullOrEmpty
|
||||
$WPFUpdatessecurity | should -Not -BeNullOrEmpty
|
||||
$WPFFeatureInstall | should -Not -BeNullOrEmpty
|
||||
$WPFundoall | should -Not -BeNullOrEmpty
|
||||
$WPFDisableDarkMode | should -Not -BeNullOrEmpty
|
||||
$WPFEnableDarkMode | should -Not -BeNullOrEmpty
|
||||
$WPFtweaksbutton | should -Not -BeNullOrEmpty
|
||||
$WPFminimal | should -Not -BeNullOrEmpty
|
||||
$WPFlaptop | should -Not -BeNullOrEmpty
|
||||
$WPFdesktop | should -Not -BeNullOrEmpty
|
||||
$WPFInstallUpgrade | should -Not -BeNullOrEmpty
|
||||
$WPFinstall | should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
52
runspace.ps1
52
runspace.ps1
@ -1,5 +1,5 @@
|
||||
#for CI/CD
|
||||
$BranchToUse = 'main'
|
||||
$BranchToUse = 'feature/pester'
|
||||
|
||||
<#
|
||||
.NOTES
|
||||
@ -1344,37 +1344,37 @@ write-host "====Chris Titus Tech====="
|
||||
write-host "=====Windows Toolbox====="
|
||||
|
||||
if($gui -eq $true){
|
||||
$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
|
||||
[xml]$XAML = $inputXML
|
||||
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
|
||||
$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
|
||||
[xml]$XAML = $inputXML
|
||||
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
|
||||
|
||||
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 <img draggable="false" role="img" class="emoji" alt="😀" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f600.svg">
|
||||
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 <img draggable="false" role="img" class="emoji" alt="😀" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f600.svg">
|
||||
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
|
||||
}
|
||||
|
||||
<#
|
||||
|
Loading…
Reference in New Issue
Block a user