<commit_before>$here = Split-Path -Parent $MyInvocation.MyCommand.Path
if(get-module Boxstarter.Chocolatey){Remove-Module boxstarter.Chocolatey}
Resolve-Path $here\..\..\Boxstarter.Common\*.ps1 | 
    % { . $_.ProviderPath }
Resolve-Path $here\..\..\Boxstarter.Bootstrapper\*.ps1 | 
    % { . $_.ProviderPath }

$Boxstarter.BaseDir=(split-path -parent (split-path -parent $here))
$Boxstarter.SuppressLogging=$true
Resolve-Path $here\..\..\Boxstarter.Chocolatey\*.ps1 | 
    % { . $_.ProviderPath }

function DISM { return; }

Describe "Getting-Chocolatey" {
    Mock Call-Chocolatey {$global:LASTEXITCODE=0}
    Mock Invoke-Reboot
    Mock Test-PendingReboot {return $false}
    $pkgDir = "$env:ChocolateyInstall\lib\pkg"
    Mock Test-Path  { $true } -ParameterFilter {$path -eq $pkgDir}

    Context "When a reboot is pending and reboots are OK" {
        Mock Test-PendingReboot {$true}
        $boxstarter.RebootOk=$true
        
        Chocolatey Install pkg

        it "will Invoke-Reboot" {
            Assert-MockCalled Invoke-Reboot -times 1
        }
        it "will not get Chocolatey" {
            Assert-MockCalled Call-Chocolatey -times 0
        }        
    }

    Context "When Boxstarter is restarting from a nested package" {
        $Boxstarter.IsRebooting=$true
        $boxstarter.RebootOk=$true
        
        Chocolatey Install pkg

        it "will Invoke-Reboot" {
            Assert-MockCalled Invoke-Reboot -times 1
        }
        it "will not get Chocolatey" {
            Assert-MockCalled Call-Chocolatey -times 0
        }
        $Boxstarter.IsRebooting=$false
    }

    Context "When a reboot is pending but reboots are not OK" {
        Mock Test-PendingReboot {$true}
        $boxstarter.RebootOk=$false
        
        Chocolatey Install pkg

        it "will not Invoke-Reboot" {
            Assert-MockCalled Invoke-Reboot -times 0
        }
        it "will get Chocolatey" {
            Assert-MockCalled Call-Chocolatey -times 1
        }        
    }

    Context "When chocolatry strips the machine module path" {
        Mock Call-Chocolatey {
            $env:PSModulePath = [System.Environment]::GetEnvironmentVariable("PSModulePath","User")
            $global:LASTEXITCODE=0
        }

        Chocolatey Install pkg

        it "will append machine module path" {
            $env:PSModulePath.EndsWith([System.Environment]::GetEnvironmentVariable("PSModulePath","Machine")) | should be $true
        }        
    }

    Context "When Installing multiple packages" {
        $packages=@("package1","package2")
        
        Chocolatey Install $packages

        it "will get chocolatey for package1" {
            Assert-MockCalled Call-Chocolatey -ParameterFilter {$packageNames -eq "package1"} -times 1
        }        
        it "will get chocolatey for package2" {
            Assert-MockCalled Call-Chocolatey -ParameterFilter {$packageNames -eq "package2"} -times 1
        }        
    }

    Context "When chocolatey throws a reboot error and reboots are OK" {
        $boxstarter.RebootOk=$true
        Mock Remove-Item
        Mock Call-Chocolatey {throw "[ERROR] Exit code was '3010'."}
<commit_msg>fix test when test maching has no user psmodulepath<commit_after>$here = Split-Path -Parent $MyInvocation.MyCommand.Path
if(get-module Boxstarter.Chocolatey){Remove-Module boxstarter.Chocolatey}
Resolve-Path $here\..\..\Boxstarter.Common\*.ps1 | 
    % { . $_.ProviderPath }
Resolve-Path $here\..\..\Boxstarter.Bootstrapper\*.ps1 | 
    % { . $_.ProviderPath }

$Boxstarter.BaseDir=(split-path -parent (split-path -parent $here))
$Boxstarter.SuppressLogging=$true
Resolve-Path $here\..\..\Boxstarter.Chocolatey\*.ps1 | 
    % { . $_.ProviderPath }

function DISM { return; }

Describe "Getting-Chocolatey" {
    Mock Call-Chocolatey {$global:LASTEXITCODE=0}
    Mock Invoke-Reboot
    Mock Test-PendingReboot {return $false}
    $pkgDir = "$env:ChocolateyInstall\lib\pkg"
    Mock Test-Path  { $true } -ParameterFilter {$path -eq $pkgDir}

    Context "When a reboot is pending and reboots are OK" {
        Mock Test-PendingReboot {$true}
        $boxstarter.RebootOk=$true
        
        Chocolatey Install pkg

        it "will Invoke-Reboot" {
            Assert-MockCalled Invoke-Reboot -times 1
        }
        it "will not get Chocolatey" {
            Assert-MockCalled Call-Chocolatey -times 0
        }        
    }

    Context "When Boxstarter is restarting from a nested package" {
        $Boxstarter.IsRebooting=$true
        $boxstarter.RebootOk=$true
        
        Chocolatey Install pkg

        it "will Invoke-Reboot" {
            Assert-MockCalled Invoke-Reboot -times 1
        }
        it "will not get Chocolatey" {
            Assert-MockCalled Call-Chocolatey -times 0
        }
        $Boxstarter.IsRebooting=$false
    }

    Context "When a reboot is pending but reboots are not OK" {
        Mock Test-PendingReboot {$true}
        $boxstarter.RebootOk=$false
        
        Chocolatey Install pkg

        it "will not Invoke-Reboot" {
            Assert-MockCalled Invoke-Reboot -times 0
        }
        it "will get Chocolatey" {
            Assert-MockCalled Call-Chocolatey -times 1
        }        
    }

    Context "When chocolatry strips the machine module path" {
        Mock Call-Chocolatey {
            $env:PSModulePath = "C:\Program Files\WindowsPowerShell\Modules"
            $global:LASTEXITCODE=0
        }

        Chocolatey Install pkg

        it "will append machine module path" {
            $env:PSModulePath.EndsWith([System.Environment]::GetEnvironmentVariable("PSModulePath","Machine")) | should be $true
        }        
    }

    Context "When Installing multiple packages" {
        $packages=@("package1","package2")
        
        Chocolatey Install $packages

        it "will get chocolatey for package1" {
            Assert-MockCalled Call-Chocolatey -ParameterFilter {$packageNames -eq "package1"} -times 1
        }        
        it "will get chocolatey for package2" {
            Assert-MockCalled Call-Chocolatey -ParameterFilter {$packageNames -eq "package2"} -times 1
        }        
    }

    Context "When chocolatey throws a reboot error and reboots are OK" {
        $boxstarter.RebootOk=$true
        Mock Remove-Item
        Mock Call-Chocolatey {throw "[ERROR] Exit code was '3010'."}

{'fraction_non_alphanumeric': 0.10070588235294117, 'fraction_numerical': 0.007215686274509804, 'mean_word_length': 2.2267206477732793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7304745', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1846, 'n_words': 465}