Skip to content

Commit 3da0a9a

Browse files
authored
added test (#43)
* added test * separe to finction and add to update * documentation
1 parent 4d4559f commit 3da0a9a

File tree

6 files changed

+88
-24
lines changed

6 files changed

+88
-24
lines changed

Docs/Get-GitModule.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Accept wildcard characters: False
9898
9999
### -Name
100100
You can query already installed modules for their online version if ProjectUri is specified in the module info.
101-
To do this, just specify module name(s) with parameter -Names.
101+
To do this, just specify module name(s) with parameter -Name.
102102
103103
```yaml
104104
Type: String[]

Docs/Update-GitModule.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ This cmdlet updates previously installed PowerShell module specified by its git
1212

1313
## SYNTAX
1414

15+
### ByUri
1516
```
1617
Update-GitModule [-ProjectUri] <String[]> [-Branch <String>] [-DestinationPath <String>] [-Force]
1718
[<CommonParameters>]
1819
```
1920

21+
### ByName
22+
```
23+
Update-GitModule -Name <String[]> [-Branch <String>] [-DestinationPath <String>] [-Force] [<CommonParameters>]
24+
```
25+
2026
## DESCRIPTION
2127

2228
This cmdlet updates previously installed PowerShell module specified by its git repository URL if repository contains newer version than installed one.
@@ -92,6 +98,22 @@ Accept pipeline input: False
9298
Accept wildcard characters: False
9399
```
94100
101+
### -Name
102+
You can update already installed modules with their git online version if ProjectUri is specified in the module info.
103+
To do this, just specify module name(s) with parameter -Name.
104+
105+
```yaml
106+
Type: String[]
107+
Parameter Sets: ByName
108+
Aliases:
109+
110+
Required: True
111+
Position: Named
112+
Default value: None
113+
Accept pipeline input: False
114+
Accept wildcard characters: False
115+
```
116+
95117
### -ProjectUri
96118
Mandatory parameter specifying URL or the repository.
97119
Multiple values are supported.
@@ -102,7 +124,7 @@ You can pass this parameter also via pipeline, for example via \`Find-Module\` b
102124
103125
```yaml
104126
Type: String[]
105-
Parameter Sets: (All)
127+
Parameter Sets: ByUri
106128
Aliases:
107129

108130
Required: True

Private/ConvertTo-Uri.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function ConvertTo-Uri {
2+
# converts array of module names to uris based on projectUri field
3+
4+
param (
5+
[Parameter(Mandatory)]
6+
[string[]]$Name
7+
)
8+
9+
Write-Verbose -Message "$(Get-Date -f T) searching module URIs from their names"
10+
foreach ($N1 in $Name) {
11+
$Module = Get-InstalledModule $N1 -ea 0
12+
if (!$Module) {$Module = Get-Module $N1 -ListAvailable -ea 0}
13+
14+
if (!$Module) {
15+
Write-Error "$FunctionName found no module $N1"
16+
continue
17+
}
18+
19+
if (!($Module | ? ProjectUri)) {
20+
Write-Warning "$FunctionName found module $N1, but it has no ProjectUri information"
21+
continue
22+
}
23+
24+
# return information to $ProjectUri variable
25+
$Module | Sort-Object Version | Select-Object -Last 1 -ExpandProperty ProjectUri
26+
}
27+
}

Public/Get-GitModule.ps1

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,7 @@ function Get-GitModule {
3333
$tmpRoot = [System.IO.Path]::GetTempPath()
3434
}
3535

36-
if ($Name) {
37-
Write-Verbose -Message "$(Get-Date -f T) searching module URIs from their names"
38-
$ProjectUri = foreach ($N1 in $Name) {
39-
$Module = Get-InstalledModule $N1 -ea 0
40-
if (!$Module) {$Module = Get-Module $N1 -ListAvailable -ea 0}
41-
42-
if (!$Module) {
43-
Write-Error "$FunctionName found no module $N1"
44-
continue
45-
}
46-
47-
if (!($Module | ? ProjectUri)) {
48-
Write-Warning "$FunctionName found module $N1, but it has no ProjectUri information"
49-
continue
50-
}
51-
52-
# return information to $ProjectUri variable
53-
$Module | Sort-Object Version | Select-Object -Last 1 -ExpandProperty ProjectUri
54-
55-
}
56-
}
36+
if ($Name) {$ProjectUri = ConvertTo-Uri -Name $Name}
5737

5838
}
5939

Public/Update-GitModule.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ function Update-GitModule {
55
param (
66

77

8-
[Parameter(Mandatory,ValueFromPipelineByPropertyName,Position=0)]
8+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,Position=0,ParameterSetName='ByUri')]
99
[string[]]$ProjectUri,
1010
# https://github.com/dfinke/InstallModuleFromGitHub
1111
# https://github.com/iricigor/FIFA2018
1212

13+
[Parameter(Mandatory,ParameterSetName='ByName')]
14+
[string[]]$Name,
15+
1316
[string]$Branch = "master",
1417
[string]$DestinationPath = (Get-InstallPath),
1518
[switch]$Force
@@ -31,6 +34,8 @@ function Update-GitModule {
3134
$tmpRoot = [System.IO.Path]::GetTempPath()
3235
}
3336

37+
if ($Name) {$ProjectUri = ConvertTo-Uri -Name $Name}
38+
3439
}
3540

3641
PROCESS {

Tests/functions/Update-GitModule.Tests.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,36 @@ Describe "$CommandName basic testing" -Tag 'Functionality' {
3636

3737
}
3838

39+
Describe "$CommandName byName testing" -Tag 'Functionality' {
40+
41+
42+
$moduleName = 'FIFA2018'
43+
$moduleURL = 'https://github.com/iricigor/' + $moduleName
44+
45+
$ExistingModule = Get-InstalledModule $moduleName -ea 0
46+
It 'Should uninstall again module if installed' -Skip:($ExistingModule -eq $null) {
47+
{Uninstall-Module $moduleName} | Should -Not -Throw
48+
}
49+
50+
# its not so easy to remove PowerShell module
51+
$ExistingModule = Get-Module $moduleName -ListAvailable
52+
It 'Should delete again module if still found' -Skip:($ExistingModule -eq $null) {
53+
{Split-Path ($ExistingModule.Path) -Parent | Remove-Item -Force -Recurse} | Should -Not -Throw
54+
}
55+
56+
It 'Should install again module from PSGallery' {
57+
$OldProgressPreference = $ProgressPreference
58+
$ProgressPreference = 'SilentlyContinue'
59+
{Install-Module $moduleName -Repository PSGallery -Scope CurrentUser -Force} | Should -Not -Throw
60+
$ProgressPreference = $OldProgressPreference
61+
}
62+
63+
It 'Should update module byName to newer version' {
64+
Update-GitModule -Name $moduleName -Force | Should -Not -Be $null
65+
}
66+
67+
}
68+
3969

4070
Describe "$CommandName error handling" -Tag 'Functionality' {
4171

0 commit comments

Comments
 (0)