|
| 1 | +#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' } |
| 2 | + |
| 3 | +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
| 4 | + 'PSUseDeclaredVarsMoreThanAssignments', '', |
| 5 | + Justification = 'Pester grouping syntax: known issue.' |
| 6 | +)] |
| 7 | +[CmdletBinding()] |
| 8 | +param() |
| 9 | + |
| 10 | +# This test file validates size property standardization across GitHub classes |
| 11 | +# It focuses on unit conversion and formatting expectations rather than live API calls |
| 12 | + |
| 13 | +Describe 'Size Property Standardization Tests' { |
| 14 | + |
| 15 | + Context 'Unit Conversion Logic' { |
| 16 | + It 'Validates KB to Bytes conversion formula' { |
| 17 | + # Test the conversion used in GitHubRepository and GitHubOrganization |
| 18 | + $apiValueKB = 108 # API returns this in KB |
| 19 | + $expectedBytes = $apiValueKB * 1KB # 110,592 bytes |
| 20 | + $expectedBytes | Should -Be 110592 |
| 21 | + |
| 22 | + $apiValueKB = 10000 # API returns this in KB |
| 23 | + $expectedBytes = $apiValueKB * 1KB # 10,240,000 bytes |
| 24 | + $expectedBytes | Should -Be 10240000 |
| 25 | + } |
| 26 | + |
| 27 | + It 'Validates that size values are stored as expected types' { |
| 28 | + # Verify that our expected byte values fit within UInt32 range |
| 29 | + $maxReasonableSize = 4GB - 1 # Max reasonable repository size (just under 4GB) |
| 30 | + $maxReasonableSize | Should -BeLessOrEqual ([System.UInt32]::MaxValue) |
| 31 | + |
| 32 | + # Test boundary cases |
| 33 | + $zeroBytes = 0 * 1KB |
| 34 | + $zeroBytes | Should -Be 0 |
| 35 | + $zeroBytes | Should -BeOfType [System.Int32] |
| 36 | + |
| 37 | + $smallSize = 1 * 1KB |
| 38 | + $smallSize | Should -Be 1024 |
| 39 | + $smallSize | Should -BeOfType [System.Int32] |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + Context 'Expected Format Output Patterns' { |
| 44 | + It 'Validates expected format patterns for size display' { |
| 45 | + # These tests verify the expected output patterns without requiring the actual formatter |
| 46 | + # They document what the GitHubFormatter::FormatFileSize method should produce |
| 47 | + |
| 48 | + $testCases = @( |
| 49 | + @{ Bytes = 0; ExpectedPattern = '\d+\s+B' } # "0 B" |
| 50 | + @{ Bytes = 512; ExpectedPattern = '\d+\s+B' } # "512 B" |
| 51 | + @{ Bytes = 1024; ExpectedPattern = '\d+\.\d{2} KB' } # "1.00 KB" |
| 52 | + @{ Bytes = 1048576; ExpectedPattern = '\d+\.\d{2} MB' } # "1.00 MB" |
| 53 | + @{ Bytes = 1073741824; ExpectedPattern = '\d+\.\d{2} GB' } # "1.00 GB" |
| 54 | + @{ Bytes = 110592; ExpectedPattern = '\d+\.\d{2} KB' } # "108.00 KB" |
| 55 | + ) |
| 56 | + |
| 57 | + foreach ($case in $testCases) { |
| 58 | + # Document expected pattern - actual formatting tested in integration tests |
| 59 | + $case.ExpectedPattern | Should -Match '\w+' # Verify pattern is non-empty |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + Context 'Conversion Scenarios Documentation' { |
| 65 | + It 'Documents the standardization changes made' { |
| 66 | + # This test documents the before/after behavior for size properties |
| 67 | + |
| 68 | + # GitHubRepository: Before stored KB, now stores bytes |
| 69 | + $beforeValue = 108 # KB from API |
| 70 | + $afterValue = $beforeValue * 1KB # bytes (110,592) |
| 71 | + $afterValue | Should -Be 110592 |
| 72 | + $afterValue | Should -BeGreaterThan $beforeValue # Verify conversion increases value |
| 73 | + |
| 74 | + # GitHubOrganization: Before had DiskUsage in KB, now has Size in bytes with DiskUsage alias |
| 75 | + $orgBeforeValue = 10000 # KB from API |
| 76 | + $orgAfterValue = $orgBeforeValue * 1KB # bytes (10,240,000) |
| 77 | + $orgAfterValue | Should -Be 10240000 |
| 78 | + $orgAfterValue | Should -BeGreaterThan $orgBeforeValue |
| 79 | + |
| 80 | + # GitHubArtifact: Was already in bytes, now uses standardized formatter |
| 81 | + # No conversion needed, just formatting change |
| 82 | + $artifactSize = 2048576 # Already in bytes |
| 83 | + $artifactSize | Should -BeGreaterThan 1MB # Verify it's a reasonable size |
| 84 | + } |
| 85 | + |
| 86 | + It 'Verifies that byte storage allows for consistent formatting' { |
| 87 | + # All classes now store in bytes, enabling consistent formatting |
| 88 | + $sizes = @(110592, 10240000, 2048576) # Example sizes from Repository, Organization, Artifact |
| 89 | + |
| 90 | + foreach ($size in $sizes) { |
| 91 | + $size | Should -BeOfType [System.Int32] |
| 92 | + $size | Should -BeGreaterThan 0 |
| 93 | + # All can be formatted with the same GitHubFormatter::FormatFileSize method |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | +} |
0 commit comments