Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a working test case for parseNodes() #30

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions decode_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ func (dec *dataDecoder) parseNodes(pb *OSMPBF.PrimitiveBlock, nodes []*OSMPBF.No
info := extractInfo(st, node.GetInfo(), dateGranularity)

dec.q = append(dec.q, &Node{id, latitude, longitude, tags, info})

panic("Please test this first")
}

}
Expand Down
28 changes: 20 additions & 8 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const (
// 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"

// 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"
)

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

func downloadTestOSMFile(t *testing.T) {
_, err := os.Stat(London)
func downloadTestOSMFile(fileName string, downloadURL string, t *testing.T) {
_, err := os.Stat(fileName)
if err == nil {
return
}
if !os.IsNotExist(err) {
t.Fatal(err)
}

resp, err := http.Get(LondonURL)
resp, err := http.Get(downloadURL)
if err != nil {
t.Fatal(err)
}
Expand All @@ -160,7 +165,7 @@ func downloadTestOSMFile(t *testing.T) {
t.Fatalf("expected 200, got %d", resp.StatusCode)
}

out, err := os.Create(London)
out, err := os.Create(fileName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -199,10 +204,10 @@ func checkHeader(a *Header) bool {
return true
}

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

f, err := os.Open(London)
f, err := os.Open(PBFfileName)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -288,8 +293,15 @@ func TestDecode(t *testing.T) {
}
}

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

func TestDecodePBFWithNodes(t *testing.T) {
decodePBF(LondonNonDense, LondonNonDenseURL, t)
}
func TestDecodeConcurrent(t *testing.T) {
downloadTestOSMFile(t)
downloadTestOSMFile(London, LondonURL, t)

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