Skip to content

Commit

Permalink
Minor refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Mar 25, 2018
1 parent 9cda7d9 commit d03e78c
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ import (
)

const (
// Test files are stored at https://gist.github.com/AlekSi/d4369aa13cf1fc5ddfac3e91b67b2f7b
// 8604f36a7357adfbd6b5292c2ea4972d9d0bfd3d is the latest commit.
GistURL = "https://gist.githubusercontent.com/AlekSi/d4369aa13cf1fc5ddfac3e91b67b2f7b/raw/8604f36a7357adfbd6b5292c2ea4972d9d0bfd3d/"

// Originally downloaded from http://download.geofabrik.de/europe/great-britain/england/greater-london.html
// Stored at https://gist.github.com/AlekSi/d4369aa13cf1fc5ddfac3e91b67b2f7b
London = "greater-london-140324.osm.pbf"
LondonURL = "https://gist.githubusercontent.com/AlekSi/d4369aa13cf1fc5ddfac3e91b67b2f7b/raw/f87959d6c9466547d9759971e071a15049b67ae2/greater-london-140324.osm.pbf"
London = "greater-london-140324.osm.pbf"

// Same file as above, but without 'DenseNodes'. This has been generated using the below command (using osmium-tool http://osmcode.org/osmium-tool/)
// "osmium cat -o greater-london-140324-nondense.osm.pbf greater-london-140324.osm.pbf -f osm.pbf,pbf_dense_nodes=false"
LondonNonDense = "greater-london-140324-nondense.osm.pbf"
LondonNonDenseURL = "https://gist.githubusercontent.com/AlekSi/d4369aa13cf1fc5ddfac3e91b67b2f7b/raw/8604f36a7357adfbd6b5292c2ea4972d9d0bfd3d/greater-london-140324-nondense.osm.pbf"
LondonNonDense = "greater-london-140324-nondense.osm.pbf"
)

func parseTime(s string) time.Time {
Expand Down Expand Up @@ -146,7 +147,7 @@ func init() {
}
}

func downloadTestOSMFile(fileName string, downloadURL string, t *testing.T) {
func downloadTestOSMFile(fileName string, t *testing.T) {
_, err := os.Stat(fileName)
if err == nil {
return
Expand All @@ -155,7 +156,7 @@ func downloadTestOSMFile(fileName string, downloadURL string, t *testing.T) {
t.Fatal(err)
}

resp, err := http.Get(downloadURL)
resp, err := http.Get(GistURL + fileName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -204,8 +205,8 @@ func checkHeader(a *Header) bool {
return true
}

func decodePBF(PBFfileName string, fileDownloadURL string, t *testing.T) {
downloadTestOSMFile(PBFfileName, fileDownloadURL, t)
func decodePBF(PBFfileName string, t *testing.T) {
downloadTestOSMFile(PBFfileName, t)

f, err := os.Open(PBFfileName)
if err != nil {
Expand Down Expand Up @@ -294,14 +295,15 @@ func decodePBF(PBFfileName string, fileDownloadURL string, t *testing.T) {
}

func TestDecodePBFWithDenseNodes(t *testing.T) {
decodePBF(London, LondonURL, t)
decodePBF(London, t)
}

func TestDecodePBFWithNodes(t *testing.T) {
decodePBF(LondonNonDense, LondonNonDenseURL, t)
decodePBF(LondonNonDense, t)
}

func TestDecodeConcurrent(t *testing.T) {
downloadTestOSMFile(London, LondonURL, t)
downloadTestOSMFile(London, t)

f, err := os.Open(London)
if err != nil {
Expand Down

0 comments on commit d03e78c

Please sign in to comment.