Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ed8f3ab02e |
@@ -434,8 +434,8 @@ Function Invoke-GiteaFileDownload {
|
|||||||
return [PSCustomObject]@{
|
return [PSCustomObject]@{
|
||||||
SourceURL = $downloadURL
|
SourceURL = $downloadURL
|
||||||
Type = $type
|
Type = $type
|
||||||
Result = 'Success'
|
Result = 'Skipped'
|
||||||
Error = "Skipped - item is a directory"
|
Error = $null
|
||||||
Timestamp = Get-Date
|
Timestamp = Get-Date
|
||||||
FileSize = $null
|
FileSize = $null
|
||||||
}
|
}
|
||||||
@@ -521,7 +521,7 @@ Function Invoke-GiteaFileDownload {
|
|||||||
Path = $fileOutputPath
|
Path = $fileOutputPath
|
||||||
SourceURL = $downloadURL
|
SourceURL = $downloadURL
|
||||||
Type = "file"
|
Type = "file"
|
||||||
Result = 'Failure'
|
Result = $null
|
||||||
Error = $null
|
Error = $null
|
||||||
Timestamp = Get-Date
|
Timestamp = Get-Date
|
||||||
FileSize = $null
|
FileSize = $null
|
||||||
@@ -545,6 +545,7 @@ Function Invoke-GiteaFileDownload {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
$result.Result = 'Skipped'
|
||||||
$errorMsg = "The file '$fileOutputPath' already exists. Use the -Force switch to overwrite the file."
|
$errorMsg = "The file '$fileOutputPath' already exists. Use the -Force switch to overwrite the file."
|
||||||
Write-Error $errorMsg
|
Write-Error $errorMsg
|
||||||
$result.Error = $errorMsg
|
$result.Error = $errorMsg
|
||||||
@@ -578,6 +579,7 @@ Function Invoke-GiteaFileDownload {
|
|||||||
return $result
|
return $result
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
$result.Result = 'Failure'
|
||||||
$errorMsg = "Failed to download file from Gitea: $_"
|
$errorMsg = "Failed to download file from Gitea: $_"
|
||||||
Write-Error $errorMsg
|
Write-Error $errorMsg
|
||||||
$result.Error = $errorMsg
|
$result.Error = $errorMsg
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/raw/path/to/file.txt' -token 'abc123'
|
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/raw/path/to/file.txt' -token 'abc123'
|
||||||
|
|
||||||
$result | Should -Not -BeNullOrEmpty
|
$result | Should -Not -BeNullOrEmpty
|
||||||
$result.Success | Should -Be $true
|
$result.Result | Should -Be 'Success'
|
||||||
$result.Path | Should -Match 'file\.txt$'
|
$result.Path | Should -Match 'file\.txt$'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
-outputPath 'docs/manual/' -token 'abc123'
|
-outputPath 'docs/manual/' -token 'abc123'
|
||||||
|
|
||||||
$result.Path | Should -Match 'docs[\\/]+manual[\\/]+file\.txt$'
|
$result.Path | Should -Match 'docs[\\/]+manual[\\/]+file\.txt$'
|
||||||
$result.Success | Should -Be $true
|
$result.Result | Should -Be 'Success'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
-outputName 'newfile.txt' -token 'abc123'
|
-outputName 'newfile.txt' -token 'abc123'
|
||||||
|
|
||||||
$result.Path | Should -Match 'newfile\.txt$'
|
$result.Path | Should -Match 'newfile\.txt$'
|
||||||
$result.Success | Should -Be $true
|
$result.Result | Should -Be 'Success'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
-outputPath 'docs/manual/' -outputName 'newfile.txt' -token 'abc123'
|
-outputPath 'docs/manual/' -outputName 'newfile.txt' -token 'abc123'
|
||||||
|
|
||||||
$result.Path | Should -Match 'docs[\\/]+manual[\\/]+newfile\.txt$'
|
$result.Path | Should -Match 'docs[\\/]+manual[\\/]+newfile\.txt$'
|
||||||
$result.Success | Should -Be $true
|
$result.Result | Should -Be 'Success'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
-PreserveRelativePath -token 'abc123'
|
-PreserveRelativePath -token 'abc123'
|
||||||
|
|
||||||
$result.Path | Should -Match 'path[\\/]+to[\\/]+file\.txt$'
|
$result.Path | Should -Match 'path[\\/]+to[\\/]+file\.txt$'
|
||||||
$result.Success | Should -Be $true
|
$result.Result | Should -Be 'Success'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,8 +98,7 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
It 'Should skip items with type = dir' {
|
It 'Should skip items with type = dir' {
|
||||||
$result = Invoke-GiteaFileDownload -outputPath 'docs/' -type 'dir' -token 'abc123'
|
$result = Invoke-GiteaFileDownload -outputPath 'docs/' -type 'dir' -token 'abc123'
|
||||||
|
|
||||||
$result.Success | Should -Be $true
|
$result.Result | Should -Be 'Skipped'
|
||||||
$result.Error | Should -Match 'Skipped'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,8 +115,7 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
It 'Should not overwrite existing file without Force' {
|
It 'Should not overwrite existing file without Force' {
|
||||||
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/raw/path/to/existingfile.txt' -token 'abc123'
|
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/raw/path/to/existingfile.txt' -token 'abc123'
|
||||||
|
|
||||||
$result.Success | Should -Be $false
|
$result.Result | Should -Be 'Skipped'
|
||||||
$result.Error | Should -Match 'already exists'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +143,7 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
It 'Should capture error and mark download as failed' {
|
It 'Should capture error and mark download as failed' {
|
||||||
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/raw/path/to/badfile.txt' -token 'abc123'
|
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/raw/path/to/badfile.txt' -token 'abc123'
|
||||||
|
|
||||||
$result.Success | Should -Be $false
|
$result.Result | Should -Be 'Failure'
|
||||||
$result.Error | Should -Match 'Failed to download'
|
$result.Error | Should -Match 'Failed to download'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user