forked from startersclan/docker-sourceservers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generate-GitBranches.Tests.ps1
142 lines (118 loc) · 5.56 KB
/
Generate-GitBranches.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
Get-Module Pester -ListAvailable
Describe "Generate-GitBranches.ps1" {
BeforeEach {
$testDrive = "TestDrive:"
$sourceRepo = $PSScriptRoot
$games = Get-Content $PSScriptRoot/games.json -Encoding utf8 | ConvertFrom-Json -AsHashtable
$remote = 'origin'
$remoteUrl = git remote get-url $
$expectedFiles = @(
'.env'
'.gitignore'
'.gitlab-ci.yml'
'.state'
'build.sh'
'build/Dockerfile'
'notify.sh'
'update/Dockerfile'
)
}
AfterEach {
cd $sourceRepo
Remove-Item $testDrive/* -Recurse -Force
}
It "Parameter validation" {
{
cd $PSScriptRoot
& ./Generate-GitBranches.ps1 -Repo '' -ErrorAction Stop
} | Should -Throw
}
Context 'Same repo' {
BeforeEach {
$sameRepo = "$testDrive/$( (Get-Item $sourceRepo).Name )"
Copy-Item $sourceRepo $sameRepo -Recurse -Force
cd $sameRepo
git config user.name "bot"
git config user.email "[email protected]"
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
foreach ($b in $branches) {
git branch -D $b
}
}
It "Creates and updates branches of a same repo (dry-run)" {
$currentRef = git rev-parse --short HEAD
if ($LASTEXITCODE) { throw }
& ./Generate-GitBranches.ps1 -Repo . -ErrorAction Stop -WhatIf 6>$null # Create
git checkout $currentRef
& ./Generate-GitBranches.ps1 -Repo . -ErrorAction Stop -WhatIf 6>$null # Update
cd $sameRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
$branches.Count | Should -Be 0
}
It "Creates and updates branches of a same repo" {
$currentRef = git rev-parse --short HEAD
if ($LASTEXITCODE) { throw }
& ./Generate-GitBranches.ps1 -Repo $sameRepo -ErrorAction Stop 6>$null # Create
git checkout $currentRef
& ./Generate-GitBranches.ps1 -Repo $sameRepo -ErrorAction Stop 6>$null # Update
cd $sameRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
$branches.Count | Should -Be $games.Count
foreach ($b in $branches) {
git ls-tree -r --name-only $b | Should -Be $expectedFiles
}
}
It "Creates and updates branches of a same repo of (one game)" {
& $sourceRepo/Generate-GitBranches.ps1 -Repo $sameRepo -GamePlatform steam -GameEngine hlds -Game valve -ErrorAction Stop 6>$null # Create
& $sourceRepo/Generate-GitBranches.ps1 -Repo $sameRepo -Remote $remote -Pull -GamePlatform steam -GameEngine hlds -Game valve -ErrorAction Stop 6>$null # Update
cd $sameRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
$branches.Count | Should -Be 1
foreach ($b in $branches) {
git ls-tree -r --name-only $b | Should -Be $expectedFiles
}
}
}
Context 'Different repo' {
BeforeEach {
$differentRepo = "$testDrive/$( (Get-Item $sourceRepo).Name )"
New-Item $differentRepo -ItemType Directory > $null
cd $differentRepo
git init --initial-branch master
git config user.name "bot"
git config user.email "[email protected]"
git commit --allow-empty -m 'Init'
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
foreach ($b in $branches) {
git branch -D $b
}
}
It "Creates and updates branches of a different repo (dry-run)" {
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -ErrorAction Stop 6>$null -WhatIf # Create
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -ErrorAction Stop 6>$null -WhatIf # Update
cd $differentRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
$branches.Count | Should -Be 0
}
It "Creates and updates branches of a different repo" {
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -ErrorAction Stop 6>$null # Create
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -ErrorAction Stop 6>$null # Update
cd $differentRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
$branches.Count | Should -Be $games.Count
foreach ($b in $branches) {
git ls-tree -r --name-only $b | Should -Be $expectedFiles
}
}
It "Creates and updates branches of a different repo (one game)" {
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -GamePlatform steam -GameEngine hlds -Game valve -ErrorAction Stop 6>$null # Create
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -GamePlatform steam -GameEngine hlds -Game valve -ErrorAction Stop 6>$null # Update
cd $differentRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
$branches.Count | Should -Be 1
foreach ($b in $branches) {
git ls-tree -r --name-only $b | Should -Be $expectedFiles
}
}
}
}