Skip to content

Commit bcb1756

Browse files
authored
AddGitRepository (#90)
1 parent 872f108 commit bcb1756

File tree

11 files changed

+286
-75
lines changed

11 files changed

+286
-75
lines changed

TestingHelperTest/private/Add-ModuleSections.Asserts.ps1

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,26 @@ function Assert-AddDevContainerJson{
2121
[string] $Path
2222
)
2323
process{
24+
$Path = $Path | Convert-Path
25+
2426
Assert-ItemExist -Path ($Path | Join-Path -ChildPath ".devcontainer" | Join-Path -ChildPath "devcontainer.json") -Comment "devcontainer.json"
2527
}
2628
}
2729

30+
# Git Repository
31+
function Assert-AddGitRepository{
32+
param(
33+
[Parameter(Mandatory,Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName)]
34+
[Alias("PSPath")][ValidateNotNullOrEmpty()]
35+
[string] $Path
36+
)
37+
process{
38+
$Path = $Path | Convert-Path
39+
40+
Assert-ItemExist -Path ($Path | Join-Path -ChildPath ".git") -Comment ".git"
41+
}
42+
}
43+
2844

2945
# License
3046
function Assert-AddLicense{
@@ -34,6 +50,8 @@ function Assert-AddLicense{
3450
[string] $Path
3551
)
3652
process{
53+
$Path = $Path | Convert-Path
54+
3755
Assert-ItemExist -Path ($Path | Join-Path -ChildPath "LICENSE") -Comment "LICENSE"
3856
}
3957
}
@@ -46,6 +64,8 @@ function Assert-AddReadMe{
4664
[string] $Path
4765
)
4866
process{
67+
$Path = $Path | Convert-Path
68+
4969
$name = $Path | Split-Path -LeafBase
5070
$readMePath = $Path | Join-Path -ChildPath "README.md"
5171
Assert-ItemExist -Path $readMePath -Comment "README.md"
@@ -69,6 +89,7 @@ function Assert-AddToModuleAbout{
6989
[string] $Path
7090
)
7191
process{
92+
$Path = $Path | Convert-Path
7293

7394
$name = $Path | Split-Path -LeafBase
7495
$aboutFilePath = $Path | Join-Path -ChildPath "en-US" -AdditionalChildPath "about_$name.help.txt"
@@ -96,6 +117,8 @@ function Assert-AddDeployScript{
96117
[string] $Path
97118
)
98119
process{
120+
$Path = $Path | Convert-Path
121+
99122
Assert-ItemExist -Path ($Path | Join-Path -ChildPath "deploy.ps1") -Comment "deploy.ps1"
100123
Assert-ItemExist -Path ($Path | Join-Path -ChildPath "deploy-helper.ps1") -Comment "deploy-helper.ps1"
101124
}
@@ -109,6 +132,8 @@ function Assert-AddReleaseScript{
109132
[string] $Path
110133
)
111134
process{
135+
$Path = $Path | Convert-Path
136+
112137
Assert-ItemExist -Path ($Path | Join-Path -ChildPath "release.ps1") -Comment "release.ps1"
113138
}
114139
}
@@ -121,6 +146,8 @@ function Assert-AddSyncScript{
121146
[string] $Path
122147
)
123148
process{
149+
$Path = $Path | Convert-Path
150+
124151
Assert-ItemExist -Path ($Path | Join-Path -ChildPath "sync.ps1") -Comment "sync.ps1"
125152
Assert-ItemExist -Path ($Path | Join-Path -ChildPath "sync-helper.ps1") -Comment "sync-helper.ps1"
126153
}
@@ -135,6 +162,8 @@ function Assert-AddPSScriptAnalyzerWorkflow{
135162
[string] $Path
136163
)
137164
process{
165+
$Path = $Path | Convert-Path
166+
138167
$destination = $Path | Join-Path -ChildPath ".github" -AdditionalChildPath "workflows"
139168
Assert-ItemExist -Path ($destination | Join-Path -ChildPath "powershell.yml") -Comment "powershell.yml"
140169
}
@@ -149,6 +178,8 @@ function Assert-AddTestWorkflow{
149178
[string] $Path
150179
)
151180
process{
181+
$Path = $Path | Convert-Path
182+
152183
$destination = $Path | Join-Path -ChildPath ".github" -AdditionalChildPath "workflows"
153184
Assert-ItemExist -Path ($destination | Join-Path -ChildPath "test_with_TestingHelper.yml") -Comment "test_with_TestingHelper.yml"
154185
}
@@ -163,6 +194,8 @@ function Assert-AddDeployWorkflow{
163194
[string] $Path
164195
)
165196
process{
197+
$Path = $Path | Convert-Path
198+
166199
$destination = $Path | Join-Path -ChildPath ".github" -AdditionalChildPath "workflows"
167200
Assert-ItemExist -Path ($destination | Join-Path -ChildPath "deploy_module_on_release.yml") -Comment "deploy_module_on_release.yml"
168201
}
@@ -176,6 +209,8 @@ function Assert-AddSampleCodes{
176209
[string] $Path
177210
)
178211
process{
212+
$Path = $Path | Convert-Path
213+
179214
Assert-ItemExist -Path ($Path | Join-Path -ChildPath "public" | Join-Path -ChildPath "samplePublicFunction.ps1") -Comment "public function"
180215
Assert-ItemExist -Path ($Path | Join-Path -ChildPath "private" | Join-Path -ChildPath "samplePrivateFunction.ps1") -Comment "private function"
181216
}
@@ -189,6 +224,8 @@ function Assert-AddTestSampleCodes{
189224
[string] $Path
190225
)
191226
process{
227+
$Path = $Path | Convert-Path
228+
192229
$name = $Path | Split-Path -LeafBase
193230
$testingModuleName = $Name + "Test"
194231
$testingModulePath = $path | Join-Path -ChildPath $testingModuleName
@@ -206,6 +243,8 @@ function Assert-AddTestLaunchJson{
206243
[string] $Path
207244
)
208245
process{
246+
$Path = $Path | Convert-Path
247+
209248
$launchFile = $Path | Join-Path -ChildPath ".vscode" -AdditionalChildPath "launch.json"
210249

211250
Assert-ItemExist -Path $launchFile -Comment "launch.json exists"
@@ -232,6 +271,8 @@ function Assert-AddTestTestScript{
232271
[string] $Path
233272
)
234273
process{
274+
$Path = $Path | Convert-Path
275+
235276

236277
$testps1Path = $Path | Join-Path -ChildPath "test.ps1"
237278

@@ -249,6 +290,8 @@ function Assert-AddModuleV3{
249290
[Parameter()][hashtable]$Expected
250291
)
251292
process{
293+
$Path = $Path | Convert-Path
294+
252295
$name = $Path | Split-Path -LeafBase
253296

254297
$psdname = $name + ".psd1"
@@ -318,6 +361,8 @@ function Assert-AddTestModuleV3{
318361
)
319362

320363
process{
364+
$Path = $Path | Convert-Path
365+
321366
$name = $Path | Split-Path -LeafBase
322367

323368
# $modulePath = $Path | Join-Path -ChildPath $Name
@@ -336,6 +381,8 @@ function Assert-AddTestAll {
336381
)
337382

338383
process{
384+
$Path = $Path | Convert-Path
385+
339386
$name = $Path | Split-Path -LeafBase
340387

341388
# $modulePath = $Path | Join-Path -ChildPath $Name
@@ -358,8 +405,10 @@ function Assert-AddAll{
358405
[string] $Path
359406
)
360407
process{
408+
$Path = $Path | Convert-Path
361409

362410
$Path | Assert-AddDevContainerJson
411+
$Path | Assert-AddGitRepository
363412
$Path | Assert-AddLicense
364413
$Path | Assert-AddReadMe
365414
$Path | Assert-AddToModuleAbout
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
2+
function TestingHelperTest_AddToModule_PipeCalls_NewModuleV3{
3+
4+
$result = New-TT_ModuleV3 -Name "MyModule" | Add-TT_ToModuleLicense -PassThru
5+
6+
$result | Assert-Addlicense
7+
}
8+
9+
function TestingHelperTest_AddToModule_PipeCalls_Folder{
10+
11+
New-TestingFolder -Path "folderName"
12+
13+
$result = Get-Item -path "folderName" | Add-TT_ToModuleLicense -PassThru
14+
$result | Assert-Addlicense
15+
}
16+
17+
function TestingHelperTest_AddToModule_PipeCalls_Module{
18+
19+
$moduleName = "AddToModule_PipeCalls_Module_" + (New-Guid).ToString().Substring(0,8)
20+
21+
$modulePath = New-TT_ModuleV3 -Name $moduleName
22+
Import-Module -Name $modulePath
23+
$module = Get-Module -Name $moduleName
24+
25+
$result = $module | Add-TT_ToModuleLicense -PassThru
26+
27+
$result | Assert-Addlicense
28+
29+
Remove-Module -Name $moduleName
30+
}
31+
32+
function TestingHelperTest_AddToModule_PipeCalls_Chain{
33+
34+
$modulePath = New-TT_ModuleV3 -Name "MyModule"
35+
36+
$result = $modulePath | Add-TT_ToModuleLicense -PassThru | Add-TT_ToModuleAbout
37+
38+
$result | Assert-Addlicense
39+
$result | Assert-AddToModuleAbout
40+
}
41+
42+
function TestingHelperTest_AddToModule_FULL_PipeCalls_Folder{
43+
44+
New-TestingFolder -Path "folderName"
45+
46+
$result = Add-TT_ToModuleAll -PassThru -Path "./folderName"
47+
$result | Assert-AddAll
48+
}
49+
50+
function TestingHelperTest_AddToModule_FULL_PipeCalls_GetItem{
51+
52+
New-TestingFolder -Path "folderName"
53+
54+
$result = Get-Item -path "folderName" | Add-TT_ToModuleAll -PassThru
55+
$result | Assert-AddAll
56+
}
57+
58+
function TestingHelperTest_AddToModule_FULL_PipeCalls_Module{
59+
60+
$modulePath = New-TT_ModuleV3 -Name "MyModule" -Description "Module Description" -Author "myName" -ModuleVersion "5.5.5"
61+
62+
Import-Module -Name $modulePath
63+
64+
$module = Get-Module -Name "MyModule"
65+
$result = $module | Add-TT_ToModuleAll -PassThru
66+
$result | Assert-AddAll
67+
68+
Remove-Module -Name "MyModule"
69+
}
70+
71+
function TestingHelperTest_AddToModuleGitRepository_PipeCalls_Folder{
72+
73+
New-TestingFolder -Path "folderName"
74+
75+
$result = Get-Item -path "folderName" | Add-TT_ToModuleGitRepository -PassThru
76+
$result | Assert-AddGitRepository
77+
78+
$result = Get-Item -path "folderName" | Add-TT_ToModuleGitRepository -PassThru @WarningParameters
79+
Assert-Contains -Expected "Git repository already exists." -Presented $warningVar
80+
81+
}
82+
83+
function TestingHelperTest_AddToModuleGitRepository_PipeCalls_Folder_Force{
84+
85+
New-TestingFolder -Path "folderName"
86+
87+
$result = Get-Item -path "folderName" | Add-TT_ToModuleGitRepository -PassThru
88+
$result | Assert-AddGitRepository
89+
90+
$result = Get-Item -path "folderName" | Add-TT_ToModuleGitRepository -Force -PassThru @WarningParameters
91+
Assert-Contains -Expected "Reinitialized existing Git repository." -Presented $warningVar
92+
}
93+
94+
function TestingHelperTest_AddToModuleGitRepository_PipeCalls_Folder_WhatIf_DoubleCall{
95+
96+
$folder = New-TestingFolder -Path "folderName" -PassThru
97+
98+
# WhatIf
99+
$result = $folder | Add-TT_ToModuleGitRepository -Whatif @WarningParameters
100+
Assert-IsNull -Object $result
101+
Assert-Count -Expected 0 -Presented $warningVar
102+
103+
# First call
104+
$result = $folder | Add-TT_ToModuleGitRepository @WarningParameters
105+
Assert-IsNull -Object $result
106+
Assert-Count -Expected 0 -Presented $warningVar
107+
108+
# Second call
109+
$result = $folder | Assert-AddGitRepository
110+
Assert-IsNull -Object $result
111+
Assert-Count -Expected 0 -Presented $warningVar
112+
113+
# Second call Whatif
114+
$result = $folder | Add-TT_ToModuleGitRepository -whatif @WarningParameters
115+
Assert-IsNull -Object $result
116+
Assert-Contains -Expected "Git repository already exists." -Presented $warningVar
117+
118+
# Second call -force -whatif
119+
$result = $folder | Add-TT_ToModuleGitRepository -whatif -force @WarningParameters
120+
Assert-IsNull -Object $result
121+
Assert-Count -Expected 0 -Presented $warningVar
122+
123+
# Second call -force
124+
$result = Get-Item -path "folderName" | Add-TT_ToModuleGitRepository -Force @WarningParameters
125+
Assert-IsNull -Object $result
126+
Assert-Contains -Expected "Reinitialized existing Git repository." -Presented $warningVar
127+
}
128+

TestingHelperTest/public/Tests-Add-moduleSectiond.ps1

Lines changed: 0 additions & 72 deletions
This file was deleted.

docs/Create-a-Module.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Apis to create a module with the sections that you need
3131
- Add-ToModuleReadme
3232
- Add-ToModuleLicense
3333
- Add-ToModuleDevContainerJson
34+
- Add-ToModuleGitRepository
3435

3536
## Add Helper scripts to create releases and deploy
3637

docs/api-and-asserts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- Add-ToModuleDeployScript
3737
- Add-ToModuleDeployWorkflow
3838
- Add-ToModuleDevContainerJson
39+
- Add-ToModuleGitRepository
3940
- Add-ToModuleLaunchJson
4041
- Add-ToModuleLicense
4142
- Add-ToModulePSScriptAnalyzerWorkflow

0 commit comments

Comments
 (0)