microsoft/hve-core

Public

mirrored fromhttps://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/update-workflow-file-and-script

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

.github/skills/shared/pr-reference/tests/shared.Tests.ps1

47lines · modecode

1#Requires -Modules Pester
2# Copyright (c) Microsoft Corporation.
3# SPDX-License-Identifier: MIT
4
5BeforeAll {
6 Import-Module (Join-Path $PSScriptRoot '../scripts/shared.psm1') -Force
7}
8
9Describe 'Get-RepositoryRoot' {
10 Context 'Default (fallback) mode' {
11 It 'Returns a valid directory when in a git repository' {
12 $result = Get-RepositoryRoot
13 $result | Should -Not -BeNullOrEmpty
14 Test-Path -Path $result -PathType Container | Should -BeTrue
15 }
16
17 It 'Returns path containing .git directory' {
18 $result = Get-RepositoryRoot
19 Test-Path -Path (Join-Path $result '.git') | Should -BeTrue
20 }
21
22 It 'Falls back to current directory when git fails' {
23 Mock git { $global:LASTEXITCODE = 128; return $null } -ModuleName shared
24 $result = Get-RepositoryRoot
25 $result | Should -Be $PWD.Path
26 }
27
28 It 'Falls back to current directory when git returns empty' {
29 Mock git { $global:LASTEXITCODE = 0; return '' } -ModuleName shared
30 $result = Get-RepositoryRoot
31 $result | Should -Be $PWD.Path
32 }
33 }
34
35 Context 'Strict mode' {
36 It 'Returns a valid directory when in a git repository' {
37 $result = Get-RepositoryRoot -Strict
38 $result | Should -Not -BeNullOrEmpty
39 Test-Path -Path $result -PathType Container | Should -BeTrue
40 }
41
42 It 'Throws when repository root cannot be determined' {
43 Mock git { $global:LASTEXITCODE = 0; return '' } -ModuleName shared
44 { Get-RepositoryRoot -Strict } | Should -Throw '*Unable to determine repository root*'
45 }
46 }
47}
48