Skip to content

Commit 14ef061

Browse files
Merge pull request #20 from steviecoaster/develop
Prep for release
2 parents 96d6cf3 + d6c9b53 commit 14ef061

File tree

6 files changed

+227
-10
lines changed

6 files changed

+227
-10
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ jobs:
4545
- name: Upload Test Results
4646
uses: EnricoMi/publish-unit-test-result-action/composite@v1
4747
if: always()
48+
with:
49+
files: TestResults.xml
4850

4951
- name: Create Release
5052
if: ${{ github.ref == 'refs/heads/main' }}

build.ps1

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,27 @@ process {
4848
Import-Module NexuShell
4949
}
5050

51-
$TestArguments = @{
52-
Path = "$root\tests"
53-
54-
OutputFile = "$root\TestResults.xml"
55-
OutputFormat = "JUnitXml"
56-
57-
CodeCoverage = (Get-ChildItem $root\Output\NexuShell -Recurse -Filter '*.ps*1').FullName
58-
CodeCoverageOutputFile = "$root\Coverage.xml"
51+
$TestConfiguration = New-PesterConfiguration @{
52+
Run = @{
53+
Path = "$root\tests"
54+
}
55+
TestResult = @{
56+
Enabled = $true
57+
OutputPath = "$root\TestResults.xml"
58+
OutputFormat = "JUnitXml"
59+
}
60+
Output = @{
61+
Verbosity = "Detailed"
62+
}
63+
CodeCoverage = @{
64+
Enabled = $true
65+
Path = (Get-ChildItem $root\Output\NexuShell -Recurse -Filter '*.ps*1').FullName
66+
OutputPath = "$root\Coverage.xml"
67+
}
5968
}
6069

61-
if (Test-Path $TestArguments.Path) {
62-
Invoke-Pester @TestArguments
70+
if (Test-Path $TestConfiguration.Run.Path.Value) {
71+
Invoke-Pester -Configuration $TestConfiguration
6372
}
6473
}
6574

docs/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# NexuShell Changelog
2+
3+
## 1.0
4+
5+
Initial release
6+
7+
## 1.0.1 (21 July 2021)
8+
9+
### Bug Fixes
10+
11+
- #9 Set-NexusUserPassword reports "Unsupported Media Type"
12+
- #8 Set-NexusUser requires parameters (some of which can't be supplied)
13+
- #7 Get-NexusNuGetApiKey does not work with a user not authenticated through Connect-NexusServer
14+
- Fixes parameter typo in ChocolateyInstall.ps1
15+
- Switches to `Join-Path` for building zip archive path in ChocolateyInstall.ps1
16+
17+
### Maintenance
18+
19+
- Added a `-Force` Parameter to `Compress-Archive` in the build script to allow the choco package to be created locally without having to manually delete files.
20+
- Adds logo to Project README
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function Convert-ObjectToHashtable {
2+
<#
3+
.SYNOPSIS
4+
Converts a PSObject to a Hashtable
5+
6+
.DESCRIPTION
7+
Invoke-Nexus outputs PSObjects, due to the underlying use of Invoke-RestMethod.
8+
Invoke-Nexus takes a Hashtable as body. This allows some pass-between.
9+
10+
.PARAMETER InputObject
11+
The object to convert.
12+
13+
.EXAMPLE
14+
Get-NexusBlobStorage -Name default -Type File | Convert-ObjectToHashtable
15+
#>
16+
param(
17+
[Parameter(Mandatory, ValueFromPipeline)]
18+
$InputObject
19+
)
20+
process {
21+
$Hashtable = @{}
22+
$InputObject.PSObject.Properties.ForEach{
23+
$Hashtable[$_.Name] = $_.Value
24+
}
25+
26+
$Hashtable
27+
}
28+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
function Update-NexusFileBlobStore {
2+
<#
3+
.SYNOPSIS
4+
Updates some properties of a given file blobstore
5+
6+
.PARAMETER Name
7+
The Name of the file blobstore to update
8+
9+
.PARAMETER Path
10+
The path for the blob store to use
11+
12+
.PARAMETER SoftQuotaType
13+
The type of soft quota limit to enforce
14+
15+
.PARAMETER SoftQuotaLimit
16+
The size of the soft quota limit, in MB
17+
18+
.NOTES
19+
This does not automatically migrate blobs from the previous location.
20+
There may be some time where the store is inaccessible.
21+
22+
.EXAMPLE
23+
Update-NexusFileBlobStore -Name default -Path D:\NexusStore
24+
25+
# Sets the default blobstore to the location listed
26+
#>
27+
[CmdletBinding(HelpUri = 'https://steviecoaster.dev/NexuShell/Update-NexusFileBlobStore/', SupportsShouldProcess, ConfirmImpact = 'High')]
28+
param(
29+
[Parameter(Mandatory)]
30+
[string]
31+
$Name,
32+
33+
[string]
34+
$Path,
35+
36+
[ValidateSet("Remaining", "Used")]
37+
[string]
38+
$SoftQuotaType,
39+
40+
[ValidateRange(1, [int]::MaxValue)]
41+
[int]
42+
$SoftQuotaLimit
43+
)
44+
begin {
45+
if (-not $header) {
46+
throw "Not connected to Nexus server! Run Connect-NexusServer first."
47+
}
48+
}
49+
end {
50+
$urislug = "/service/rest/v1/blobstores/file/$Name"
51+
52+
$Body = Get-NexusBlobStore -Name $Name -Type File | Convert-ObjectToHashtable
53+
54+
$Modified = $false
55+
switch -Wildcard ($PSBoundParameters.Keys) {
56+
"Path" {
57+
if ($Body.path -ne $Path) {
58+
$Body.path = $Path
59+
$Modified = $true
60+
}
61+
}
62+
"SoftQuota*" {
63+
if (-not $Body.softQuota) {
64+
$Body.softQuota = @{}
65+
}
66+
}
67+
"SoftQuotaType" {
68+
if ($Body.softQuota.type -ne "space$($SoftQuotaType)Quota") {
69+
$Body.softQuota.type = "space$($SoftQuotaType)Quota"
70+
$Modified = $true
71+
}
72+
}
73+
"SoftQuotaLimit" {
74+
if ($Body.softQuota.limit -ne $SoftQuotaLimit) {
75+
$Body.softQuota.limit = $SoftQuotaLimit * 1MB
76+
$Modified = $true
77+
}
78+
}
79+
}
80+
81+
if ($Modified) {
82+
if ($PSCmdlet.ShouldProcess($Name, "Update File Blob Store")) {
83+
Invoke-Nexus -UriSlug $urislug -Method Put -Body $Body
84+
}
85+
} else {
86+
Write-Verbose "No change to '$($Name)' was required."
87+
}
88+
}
89+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#requires -Modules NexuShell
2+
3+
Describe "Update-NexusFileBlobStore" {
4+
BeforeAll {
5+
$InModule = @{
6+
ModuleName = "NexuShell"
7+
}
8+
9+
InModuleScope @InModule {
10+
$script:header = @{
11+
Authentication = "fake auth"
12+
}
13+
}
14+
15+
Mock Invoke-Nexus @InModule
16+
Mock Get-NexusBlobStore @InModule -MockWith {
17+
if ($script:BlobStoreObject) {
18+
$script:BlobStoreObject
19+
} else {
20+
[PSCustomObject]@{
21+
path = "default"
22+
softQuota = @{
23+
type = ""
24+
limit = ""
25+
}
26+
}
27+
}
28+
}
29+
}
30+
31+
Context "Updating a BlobStore Path from 'default'" {
32+
BeforeAll {
33+
Update-NexusFileBlobStore -Name "Test" -Path "D:\Repository\" -Confirm:$false
34+
}
35+
36+
It "Sets the specified path for the specified BlobStore" {
37+
Assert-MockCalled Invoke-Nexus @InModule -ParameterFilter {
38+
$UriSlug -eq "/service/rest/v1/blobstores/file/Test" -and
39+
$Method -eq "Put" -and
40+
$Body.path -eq "D:\Repository\"
41+
} -Scope Context
42+
}
43+
}
44+
45+
Context "Updating a BlobStore Path that is already correct" {
46+
BeforeAll {
47+
Update-NexusFileBlobStore -Name "Test" -Path "default" -Confirm:$false
48+
}
49+
50+
It "Does not attempt to modify the BlobStore" {
51+
Assert-MockCalled Invoke-Nexus @InModule -Times 0 -Scope Context
52+
}
53+
}
54+
55+
Context "Updating a BlobStore Quota" {
56+
BeforeAll {
57+
Update-NexusFileBlobStore -Name "QuotaTest" -SoftQuotaType Remaining -SoftQuotaLimit 203 -Confirm:$false
58+
}
59+
60+
It "Sets the specified quota limit for the specified BlobStore" {
61+
Assert-MockCalled Invoke-Nexus @InModule -ParameterFilter {
62+
$UriSlug -eq "/service/rest/v1/blobstores/file/QuotaTest" -and
63+
$Method -eq "Put" -and
64+
$Body.softQuota.type -eq "spaceRemainingQuota" -and
65+
$Body.softQuota.limit -eq 203MB
66+
} -Scope Context
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)