microsoft/hve-core

Public

mirrored from https://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2137-privacy-planner

Branches

Tags

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

Clone

HTTPS

Download ZIP

scripts/tests/devcontainer/Write-DevcontainerChangeLog.Tests.ps1

97lines · modeblame

d2996b76Katrien De Graeve1 months ago1#Requires -Modules Pester
2# Copyright (c) Microsoft Corporation.
3# SPDX-License-Identifier: MIT
4
5BeforeAll {
6. (Join-Path $PSScriptRoot '../../devcontainer/Write-DevcontainerChangeLog.ps1')
7Import-Module (Join-Path $PSScriptRoot '../../lib/Modules/CIHelpers.psm1') -Force
8
9Mock Write-Host {}
10Mock Write-CIAnnotation {}
11Mock Write-CIStepSummary {}
12}
13
14Describe 'Get-DevcontainerFileClassification' -Tag 'Unit' {
15It 'Classifies <Path> as <Category> with <Impact> impact' -ForEach @(
16@{ Path = '.devcontainer/scripts/on-create.sh'; Category = 'Lifecycle Scripts'; Impact = 'High' }
17@{ Path = '.devcontainer/scripts/post-create.sh'; Category = 'Lifecycle Scripts'; Impact = 'Low' }
18@{ Path = '.devcontainer/Dockerfile'; Category = 'Base Image'; Impact = 'High' }
19@{ Path = '.devcontainer/Dockerfile.custom'; Category = 'Base Image'; Impact = 'High' }
20@{ Path = '.devcontainer/base.dockerfile'; Category = 'Base Image'; Impact = 'High' }
21@{ Path = '.devcontainer/features/custom-feature'; Category = 'Features'; Impact = 'Medium' }
22@{ Path = '.devcontainer/devcontainer.json'; Category = 'Config'; Impact = 'High' }
23@{ Path = '.devcontainer/devcontainer-lock.json'; Category = 'Lockfile'; Impact = 'Medium' }
24@{ Path = '.github/workflows/copilot-setup-steps.yml'; Category = 'Setup Steps'; Impact = 'Medium' }
25@{ Path = '.devcontainer/something-else.txt'; Category = 'Config'; Impact = 'Medium' }
26@{ Path = 'unrelated/file.txt'; Category = 'Other'; Impact = 'Unknown' }
27) {
28$result = Get-DevcontainerFileClassification -FilePath $Path
29$result.Category | Should -Be $Category
30$result.Impact | Should -Be $Impact
31}
32}
33
34Describe 'New-DevcontainerChangeSummary' -Tag 'Unit' {
35Context 'when EventName is workflow_dispatch' {
36It 'Returns markdown with dispatch message' {
37$result = New-DevcontainerChangeSummary -CommitSha 'abc123' -BranchName 'main' -EventName 'workflow_dispatch'
38$result | Should -Match 'workflow_dispatch'
39$result | Should -Match 'No push range available'
40}
41}
42
43Context 'when BeforeSha is all zeros' {
44It 'Returns markdown with initial push message' {
45$result = New-DevcontainerChangeSummary -CommitSha 'abc123' -BranchName 'main' -EventName 'push' -BeforeSha '0000000000000000000000000000000000000000'
46$result | Should -Match 'Initial push'
47}
48}
49
50Context 'when git diff succeeds with changed files' {
51BeforeAll {
52Mock git {
53$global:LASTEXITCODE = 0
54return @(
55'.devcontainer/devcontainer.json'
56'.devcontainer/scripts/on-create.sh'
57)
58} -ParameterFilter { $args -contains 'diff' }
59}
60
61It 'Returns markdown with classified file table' {
62$result = New-DevcontainerChangeSummary -CommitSha 'abc123' -BranchName 'main' -EventName 'push' -BeforeSha 'def456' -RepoRoot '/fake'
63$result | Should -Match 'devcontainer\.json'
64$result | Should -Match 'on-create\.sh'
65$result | Should -Match 'Config'
66$result | Should -Match 'Lifecycle Scripts'
67}
68}
69
70Context 'when git diff fails (force push)' {
71BeforeAll {
72Mock git {
73$global:LASTEXITCODE = 128
74return 'fatal: bad object abc123'
75} -ParameterFilter { $args -contains 'diff' }
76}
77
78It 'Returns markdown with force push message' {
79$result = New-DevcontainerChangeSummary -CommitSha 'abc123' -BranchName 'main' -EventName 'push' -BeforeSha 'def456' -RepoRoot '/fake'
80$result | Should -Match 'not be reachable'
81}
82}
83
84Context 'when git diff returns empty' {
85BeforeAll {
86Mock git {
87$global:LASTEXITCODE = 0
88return ''
89} -ParameterFilter { $args -contains 'diff' }
90}
91
92It 'Returns markdown with no changes message' {
93$result = New-DevcontainerChangeSummary -CommitSha 'abc123' -BranchName 'main' -EventName 'push' -BeforeSha 'def456' -RepoRoot '/fake'
94$result | Should -Match 'No devcontainer infrastructure files changed'
95}
96}
97}