Skip to content

Commit

Permalink
verify pester tests work before replacing with testsource
Browse files Browse the repository at this point in the history
  • Loading branch information
ryfu-msft committed Nov 30, 2023
1 parent e79a2d1 commit d4165c9
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 93 deletions.
58 changes: 23 additions & 35 deletions src/PowerShell/Microsoft.WinGet.DSC/Microsoft.WinGet.DSC.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,11 @@ class WinGetSources
foreach ($packageCatalogReference in $packageCatalogReferences)
{
$source = @{
Arg = $packageCatalogReference.Info.Argument
Identifier = $packageCatalogReference.Info.Id
Name = $packageCatalogReference.Info.Name
Type = $packageCatalogReference.Info.Type
$packageCatalogReference.Name = @{
Identifier = $packageCatalogReference.Id
Arg = $packageCatalogReference.Argument
Type = $packageCatalogReference.Type
}
}
$wingetSources.Add($source)
}
Expand All @@ -240,46 +241,39 @@ class WinGetSources
[bool] Test()
{
$currentSources = $this.Get().Sources
$currentState = [Ensure]::Present

# If this is a full match and the counts are different give up.
if (($this.Action -eq [WinGetAction]::Full) -and ($this.Sources.Count -ne $currentSources.Count))
{
return $false
return $currentState = [Ensure]::Absent
}

# There's no need to differentiate between Partial and Full anymore.
foreach ($source in $this.Sources)
foreach ($sourceName in $this.Sources.Keys)
{
# Require Name and Arg.
if ((-not $source.ContainsKey("Name")) -or [string]::IsNullOrWhiteSpace($source.Name))
{
# TODO: Localize.
throw "Invalid source input. Name is required."
}

if ((-not $source.ContainsKey("Arg")) -or [string]::IsNullOrWhiteSpace($source.Arg))
#Check if the source name exists, if it doesn't, then return false.
$result = $currentSources.Keys | Where-Object { $_ -eq $sourceName }
if ($null -eq $result)
{
# TODO: Localize.
throw "Invalid source input. Arg is required."
$currentState = [Ensure]::Absent
}

# Type has a default value.
$sourceType = "Microsoft.PreIndexed.Package"
$source = $this.Sources.$($sourceName)
$sourceType = "Microsoft.PreIndexed.Package" # default source type
if ($source.ContainsKey("Type") -and (-not([string]::IsNullOrWhiteSpace($source.Type))))
{
$sourceType = $source.Type
}

$result = $currentSources | Where-Object { $_.Name -eq $source.Name -and $_.Arg -eq $source.Arg -and $_.Type -eq $sourceType }

# Source not found.
if ($null -eq $result)
$existingSource = $currentSources.$($sourceName)
if ($source.Arg -ne $existingSource.Arg -or $sourceType -ne $existingSource.Type)
{
return $false
$currentState = [Ensure]::Absent
}
}

return $true
return $currentState -eq $this.Ensure
}

# Sets the desired properties.
Expand All @@ -290,16 +284,10 @@ class WinGetSources
Assert-WinGetCommand "Reset-WinGetSource"
Assert-WinGetCommand "Remove-WinGetSource"

foreach ($source in $this.Sources)
foreach ($sourceName in $this.Sources.Keys)
{
$sourceType = "Microsoft.PreIndexed.Package"

# Require Name and Arg.
if ((-not $source.ContainsKey("Name")) -or [string]::IsNullOrWhiteSpace($source.Name))
{
# TODO: Localize.
throw "Invalid source input. Name is required."
}
$source = $this.Sources.$($sourceName)

if ((-not $source.ContainsKey("Arg")) -or [string]::IsNullOrWhiteSpace($source.Arg))
{
Expand All @@ -314,16 +302,16 @@ class WinGetSources

if ($this.Ensure -eq [Ensure]::Present)
{
Add-WinGetSource -Name $source.Name -Argument $source.Argument -Type $sourceType
Add-WinGetSource -Name $sourceName -Argument $source.Arg -Type $sourceType

if ($this.Reset)
{
Reset-WinGetSource -Name $source.Name
Reset-WinGetSource -Name $sourceName
}
}
else
{
Remove-WinGetSource -Name $source.Name
Remove-WinGetSource -Name $sourceName
}
}
}
Expand Down
Loading

1 comment on commit d4165c9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log for details.

Unrecognized words (1)

notcontains

Previously acknowledged words that are now absent Mta :arrow_right:
To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands

... in a clone of the [email protected]:ryfu-msft/winget-cli.git repository
on the wingetDscE2ETests branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.21/apply.pl' |
perl - 'https://github.com/ryfu-msft/winget-cli/actions/runs/7044431132/attempts/1'
Available 📚 dictionaries could cover words not in the 📘 dictionary

This includes both expected items (504) from .github/actions/spelling/expect.txt and unrecognized words (1)

Dictionary Entries Covers
cspell:win32/src/win32.txt 53509 20
cspell:python/src/python/python-lib.txt 3873 3
cspell:python/src/common/extra.txt 741 3
cspell:python/src/python/python.txt 453 2
cspell:php/php.txt 2597 2
cspell:npm/npm.txt 288 2
cspell:java/java.txt 7642 2
cspell:django/django.txt 859 2
cspell:csharp/csharp.txt 19 2
cspell:sql/src/tsql.txt 455 1

Consider adding them using (in .github/workflows/spelling3.yml):

      with:
        extra_dictionaries:
          cspell:win32/src/win32.txt
          cspell:python/src/python/python-lib.txt
          cspell:python/src/common/extra.txt
          cspell:python/src/python/python.txt
          cspell:php/php.txt
          cspell:npm/npm.txt
          cspell:java/java.txt
          cspell:django/django.txt
          cspell:csharp/csharp.txt
          cspell:sql/src/tsql.txt

To stop checking additional dictionaries, add:

      with:
        check_extra_dictionaries: ''
If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.