-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCoveralls.Tests.ps1
112 lines (109 loc) · 4.82 KB
/
Coveralls.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
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"
Describe "Get-CoveragePercentage" {
Context "Providing a correct return" {
BeforeAll {
$content = "{""created_at"":""2017-03-16T12:37:17Z"",""url"":null,""commit_message"":""Add fake data to CA_KEY when it's not present"",""branch"":""master"",""committer_name"":""Jan De Dobbeleer"",""committer_email"":""[email protected]"",""commit_sha"":""ba5947862030d86208d0181189c160df04e5c309"",""repo_name"":""JanJoris/coveralls"",""badge_url"":""https://s3.amazonaws.com/assets.coveralls.io/badges/coveralls_13.svg"",""coverage_change"":0.0,""covered_percent"":%percentage%}"
}
It "has a coverage percentage of 13" {
Mock Invoke-WebRequest { return @{ Content = $content.Replace('%percentage%', '13') }}
Get-CoveragePercentage -RepositoryLink coveralls | Should Be 13
}
It "has a coverage percentage of 28" {
Mock Invoke-WebRequest { return @{ Content = $content.Replace('%percentage%', '28') }}
Get-CoveragePercentage -RepositoryLink coveralls | Should Be 28
}
}
Context "Providing an exception return" {
It "throws an error when providing bogus info" {
{ Get-CoveragePercentage -RepositoryLink coveralls -ErrorAction Stop } | Should Throw
}
It "throws an error when providing a non-existing repository" {
{ Get-CoveragePercentage -RepositoryLink https://coveralls.io/coveralls/coveralls -ErrorAction Stop } | Should Throw
}
}
Context "Providing crappy data" {
It "has no content object to parse" {
Mock Invoke-WebRequest { return @{ NotContent = "I am so crappy" }}
{ Get-CoveragePercentage -RepositoryLink coveralls -ErrorAction Stop } | Should Throw
}
}
}
Describe "Get-CommandsForFile" {
Context "Receiving proper input" {
It "has 2 commands that match the file" {
$commands = @(
@{
File = "file.ps1"
Line = 1
},
@{
File = "file.ps1"
Line = 2
},
@{
File = "file2.ps1"
Line = 3
}
)
Mock Get-Item { return @{ FullName = 'file.ps1' }}
$result = Get-CommandsForFile -Commands $commands -File 'file.ps1'
$result.Count | Should be 2
}
It "has 0 commands that match the file" {
$commands = @(
@{
File = "file2.ps1"
Line = 1
},
@{
File = "file2.ps1"
Line = 2
}
)
Mock Get-Item { return @{ FullName = 'file.ps1' }}
$result = Get-CommandsForFile -Commands $commands -File 'file.ps1'
$result.Count | Should be 0
}
}
Context "Receiving crappy input" {
It "should not output any match" {
$commands = @{
Balony = "garbage"
Ohn0 = 1324343
}
Mock Get-Item { return @{ FullName = 'file.ps1' }}
$result = Get-CommandsForFile -Commands $commands -File 'file.ps1'
$result.Count | Should be 0
}
}
}
Describe "Format-FileCoverage" {
Context "Receiving proper input" {
It "outputs the expected information" {
$expected = New-Object -TypeName PSObject -Property @{
name = 'file.ps1'
source_digest = '123456789'
coverage = 'Test'
}
Mock Get-FileHash { return @{ Hash = '123456789' }}
Mock Get-Item -ParameterFilter { $Path -eq 'RootFolder' } { @{ FullName = 'root' } }
Mock Get-Item -ParameterFilter { $Path -eq 'File' } { @{ FullName = 'root\file.ps1' } }
$result = Format-FileCoverage -CoverageArray 'Test' -File 'File' -RootFolder 'RootFolder'
$result | Should MatchExactly $expected
}
It "handles the paths without an issue" {
$expected = New-Object -TypeName PSObject -Property @{
name = 'file.ps1'
source_digest = '123456789'
coverage = 'Test'
}
Mock Get-FileHash { return @{ Hash = '123456789' }}
Mock Get-Item -ParameterFilter { $Path -eq 'RootFolder' } { @{ FullName = 'root' } }
Mock Get-Item -ParameterFilter { $Path -eq 'File' } { @{ FullName = 'file.ps1' } }
$result = Format-FileCoverage -CoverageArray 'Test' -File 'File' -RootFolder 'RootFolder'
$result | Should MatchExactly $expected
}
}
}