-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from mmadariaga/added-code-coverage
Added code coverage
- Loading branch information
Showing
5 changed files
with
347 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
coverage/coverage.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
set -e | ||
SCRIPT_DIR=$(dirname $(realpath $0)) | ||
|
||
pushd ${SCRIPT_DIR}/../ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
SCRIPT_DIR=$(dirname $(realpath $0)) | ||
|
||
pushd ${SCRIPT_DIR}/../ | ||
go test -coverprofile=coverage/coverage.out ./internal/application/... ./internal/domain/... | ||
go tool cover -html=coverage/coverage.out -o=coverage/coverage.html | ||
rm coverage/coverage.out | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
<title>pong: Go Coverage Report</title> | ||
<style> | ||
body { | ||
background: black; | ||
color: rgb(80, 80, 80); | ||
} | ||
body, pre, #legend span { | ||
font-family: Menlo, monospace; | ||
font-weight: bold; | ||
} | ||
#topbar { | ||
background: black; | ||
position: fixed; | ||
top: 0; left: 0; right: 0; | ||
height: 42px; | ||
border-bottom: 1px solid rgb(80, 80, 80); | ||
} | ||
#content { | ||
margin-top: 50px; | ||
} | ||
#nav, #legend { | ||
float: left; | ||
margin-left: 10px; | ||
} | ||
#legend { | ||
margin-top: 12px; | ||
} | ||
#nav { | ||
margin-top: 10px; | ||
} | ||
#legend span { | ||
margin: 0 5px; | ||
} | ||
.cov0 { color: rgb(192, 0, 0) } | ||
.cov1 { color: rgb(128, 128, 128) } | ||
.cov2 { color: rgb(116, 140, 131) } | ||
.cov3 { color: rgb(104, 152, 134) } | ||
.cov4 { color: rgb(92, 164, 137) } | ||
.cov5 { color: rgb(80, 176, 140) } | ||
.cov6 { color: rgb(68, 188, 143) } | ||
.cov7 { color: rgb(56, 200, 146) } | ||
.cov8 { color: rgb(44, 212, 149) } | ||
.cov9 { color: rgb(32, 224, 152) } | ||
.cov10 { color: rgb(20, 236, 155) } | ||
|
||
</style> | ||
</head> | ||
<body> | ||
<div id="topbar"> | ||
<div id="nav"> | ||
<select id="files"> | ||
|
||
<option value="file0">github.com/mmadariaga/go-api/internal/application/pong/Pong.go (100.0%)</option> | ||
|
||
<option value="file1">github.com/mmadariaga/go-api/internal/application/races/GetRacesByYear.go (100.0%)</option> | ||
|
||
<option value="file2">github.com/mmadariaga/go-api/internal/domain/service/GetDriversByRace.go (100.0%)</option> | ||
|
||
<option value="file3">github.com/mmadariaga/go-api/internal/domain/service/GetPodiumByRace.go (100.0%)</option> | ||
|
||
</select> | ||
</div> | ||
<div id="legend"> | ||
<span>not tracked</span> | ||
|
||
<span class="cov0">not covered</span> | ||
<span class="cov8">covered</span> | ||
|
||
</div> | ||
</div> | ||
<div id="content"> | ||
|
||
<pre class="file" id="file0" style="display: none">package application_pong | ||
|
||
func Pong() string <span class="cov8" title="1">{ | ||
return "pong" | ||
}</span> | ||
</pre> | ||
|
||
<pre class="file" id="file1" style="display: none">package application_races | ||
|
||
import ( | ||
domain_model "github.com/mmadariaga/go-api/internal/domain/model" | ||
domain_service "github.com/mmadariaga/go-api/internal/domain/service" | ||
) | ||
|
||
type Response struct { | ||
domain_model.Race | ||
Podium [3]domain_model.Podium `json:"podium"` | ||
} | ||
|
||
type GetRacesByYearDependencies interface { | ||
domain_service.GetPodiumByRaceDependencies | ||
FetchRacesByYear(year int) ([]domain_model.Race, error) | ||
} | ||
|
||
func GetRacesByYear( | ||
year int, | ||
dependencies GetRacesByYearDependencies, | ||
) ([]Response, error) <span class="cov8" title="1">{ | ||
|
||
races, error := dependencies.FetchRacesByYear(year) | ||
if error != nil </span><span class="cov8" title="1">{ | ||
return nil, error | ||
}</span> | ||
|
||
<span class="cov8" title="1">podiumsByRace, error := domain_service.GetPodiumByRace( | ||
races, | ||
dependencies, | ||
) | ||
if error != nil </span><span class="cov8" title="1">{ | ||
return nil, error | ||
}</span> | ||
|
||
<span class="cov8" title="1">response := make([]Response, 0, len(races)) | ||
for _, race := range races </span><span class="cov8" title="1">{ | ||
|
||
podium := podiumsByRace[race.Id] | ||
|
||
response = append( | ||
response, | ||
Response{ | ||
Race: domain_model.Race{ | ||
Id: race.Id, | ||
Year: race.Year, | ||
StartDate: race.StartDate, | ||
CountryName: race.CountryName, | ||
CircuitName: race.CircuitName, | ||
}, | ||
Podium: podium, | ||
}, | ||
) | ||
}</span> | ||
|
||
<span class="cov8" title="1">return response, nil</span> | ||
} | ||
</pre> | ||
|
||
<pre class="file" id="file2" style="display: none">package domain_service | ||
|
||
import ( | ||
domain_model "github.com/mmadariaga/go-api/internal/domain/model" | ||
) | ||
|
||
type GetDriversByRaceDependencies interface { | ||
FetchDriversByRace(raceId int) ([]domain_model.Driver, error) | ||
} | ||
|
||
func GetDriversByRace(races []domain_model.Race, dependencies GetDriversByRaceDependencies) (map[int][]domain_model.Driver, error) <span class="cov8" title="1">{ | ||
|
||
driversByRace := make(map[int][]domain_model.Driver) | ||
|
||
for _, race := range races </span><span class="cov8" title="1">{ | ||
result, error := dependencies.FetchDriversByRace(race.Id) | ||
if error != nil </span><span class="cov8" title="1">{ | ||
return nil, error | ||
}</span> | ||
|
||
<span class="cov8" title="1">driversByRace[race.Id] = result</span> | ||
} | ||
|
||
<span class="cov8" title="1">return driversByRace, nil</span> | ||
} | ||
</pre> | ||
|
||
<pre class="file" id="file3" style="display: none">package domain_service | ||
|
||
import ( | ||
domain_model "github.com/mmadariaga/go-api/internal/domain/model" | ||
) | ||
|
||
type GetPodiumByRaceDependencies interface { | ||
GetDriversByRaceDependencies | ||
FetchPodiumByRace(raceId int, drivers []domain_model.Driver) ([3]domain_model.Podium, error) | ||
} | ||
|
||
func GetPodiumByRace( | ||
races []domain_model.Race, | ||
dependencies GetPodiumByRaceDependencies, | ||
) (map[int][3]domain_model.Podium, error) <span class="cov8" title="1">{ | ||
|
||
podiumsByRace := make(map[int][3]domain_model.Podium) | ||
|
||
drivers, error := GetDriversByRace(races, dependencies) | ||
if error != nil </span><span class="cov8" title="1">{ | ||
return nil, error | ||
}</span> | ||
|
||
<span class="cov8" title="1">for _, race := range races </span><span class="cov8" title="1">{ | ||
result, error := dependencies.FetchPodiumByRace(race.Id, drivers[race.Id]) | ||
if error != nil </span><span class="cov8" title="1">{ | ||
return nil, error | ||
}</span> | ||
|
||
<span class="cov8" title="1">podiumsByRace[race.Id] = result</span> | ||
} | ||
|
||
<span class="cov8" title="1">return podiumsByRace, nil</span> | ||
} | ||
</pre> | ||
|
||
</div> | ||
</body> | ||
<script> | ||
(function() { | ||
var files = document.getElementById('files'); | ||
var visible; | ||
files.addEventListener('change', onChange, false); | ||
function select(part) { | ||
if (visible) | ||
visible.style.display = 'none'; | ||
visible = document.getElementById(part); | ||
if (!visible) | ||
return; | ||
files.value = part; | ||
visible.style.display = 'block'; | ||
location.hash = part; | ||
} | ||
function onChange() { | ||
select(files.value); | ||
window.scrollTo(0, 0); | ||
} | ||
if (location.hash != "") { | ||
select(location.hash.substr(1)); | ||
} | ||
if (!visible) { | ||
select("file0"); | ||
} | ||
})(); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters