Skip to content

Commit

Permalink
lint tests: check all errors
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmach committed Jan 6, 2023
1 parent cc0ada4 commit 64f4429
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 115 deletions.
17 changes: 13 additions & 4 deletions encoding/ewkb/ewkb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (

func TestMarshal(t *testing.T) {
for _, g := range orb.AllGeometries {
Marshal(g, 0, binary.BigEndian)
_, err := Marshal(g, 0, binary.BigEndian)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -39,7 +42,10 @@ func BenchmarkEncode_Point(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
e.Encode(g)
err := e.Encode(g)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -53,7 +59,10 @@ func BenchmarkEncode_LineString(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
e.Encode(g)
err := e.Encode(g)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand Down Expand Up @@ -129,7 +138,7 @@ func compare(t testing.TB, e orb.Geometry, s int, b []byte) {
// pass in srid
buf.Reset()
en.SetSRID(10101)
en.Encode(e, s)
err = en.Encode(e, s)
if err != nil {
t.Errorf("encode with srid error: %v", err)
}
Expand Down
5 changes: 4 additions & 1 deletion encoding/internal/wkbcommon/wkb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import (

func TestMarshal(t *testing.T) {
for _, g := range orb.AllGeometries {
Marshal(g, 0, binary.BigEndian)
_, err := Marshal(g, 0, binary.BigEndian)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
}

Expand Down
9 changes: 7 additions & 2 deletions encoding/mvt/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@ func ExampleMarshal() {

// encoding using the Mapbox Vector Tile protobuf encoding.
data, err := mvt.Marshal(layers) // this data is NOT gzipped.
_ = data

// error checking
if err != nil {
log.Fatalf("marshal error: %v", err)
}

// Sometimes MVT data is stored and transferred gzip compressed. In that case:
data, err = mvt.MarshalGzipped(layers)
_ = data

// error checking
if err != nil {
log.Fatalf("marshal error: %v", err)
}

_ = data
}
10 changes: 8 additions & 2 deletions encoding/mvt/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,10 @@ func BenchmarkMarshal(b *testing.B) {
b.ResetTimer()

for i := 0; i < b.N; i++ {
Marshal(layers)
_, err := Marshal(layers)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -573,7 +576,10 @@ func BenchmarkUnmarshal(b *testing.B) {
b.ResetTimer()

for i := 0; i < b.N; i++ {
Unmarshal(data)
_, err := Unmarshal(data)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand Down
15 changes: 12 additions & 3 deletions encoding/wkb/wkb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (

func TestMarshal(t *testing.T) {
for _, g := range orb.AllGeometries {
Marshal(g, binary.BigEndian)
_, err := Marshal(g, binary.BigEndian)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -29,7 +32,10 @@ func BenchmarkEncode_Point(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
e.Encode(g)
err := e.Encode(g)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -43,7 +49,10 @@ func BenchmarkEncode_LineString(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
e.Encode(g)
err := e.Encode(g)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand Down
11 changes: 9 additions & 2 deletions geojson/example_pointer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package geojson_test

import (
"fmt"
"log"

"github.com/paulmach/orb"
"github.com/paulmach/orb/geojson"
Expand All @@ -26,12 +27,18 @@ func Example_centroid() {
// feature with center {0.5, 0.5} but centroid {0.25, 0.25}
f := geojson.NewFeature(orb.MultiPoint{{0, 0}, {0, 0}, {0, 0}, {1, 1}})
f.Properties["centroid"] = "0.25"
qt.Add(CentroidPoint{f})
err := qt.Add(CentroidPoint{f})
if err != nil {
log.Fatalf("unexpected error: %v", err)
}

// feature with centroid {0.6, 0.6}
f = geojson.NewFeature(orb.Point{0.6, 0.6})
f.Properties["centroid"] = "0.6"
qt.Add(CentroidPoint{f})
err = qt.Add(CentroidPoint{f})
if err != nil {
log.Fatalf("unexpected error: %v", err)
}

feature := qt.Find(orb.Point{0.5, 0.5}).(CentroidPoint).Feature
fmt.Printf("centroid=%s", feature.Properties["centroid"])
Expand Down
19 changes: 14 additions & 5 deletions geojson/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ func ExampleFeature_Point() {
f.Properties["key"] = "value"

qt := quadtree.New(f.Geometry.Bound().Pad(1))
qt.Add(f) // add the feature to a quadtree
err := qt.Add(f) // add the feature to a quadtree
if err != nil {
log.Fatalf("unexpected error: %v", err)
}

// type assert the feature back into a Feature from
// the orb.Pointer interface.
Expand All @@ -39,7 +42,10 @@ func ExampleFeatureCollection_foreignMembers() {
}`)

fc := geojson.NewFeatureCollection()
json.Unmarshal(rawJSON, &fc)
err := json.Unmarshal(rawJSON, &fc)
if err != nil {
log.Fatalf("invalid json: %v", err)
}

fmt.Println(fc.Features[0].Geometry)
fmt.Println(fc.ExtraMembers["title"])
Expand Down Expand Up @@ -90,7 +96,10 @@ func ExampleFeatureCollection_foreignMembersCustom() {
}`)

fc := &MyFeatureCollection{}
json.Unmarshal(rawJSON, &fc)
err := json.Unmarshal(rawJSON, &fc)
if err != nil {
log.Fatalf("invalid json: %v", err)
}

fmt.Println(fc.FeatureCollection.Features[0].Geometry)
fmt.Println(fc.Features[0].Geometry)
Expand Down Expand Up @@ -151,13 +160,13 @@ func ExampleFeatureCollection_MarshalJSON() {
fc := geojson.NewFeatureCollection()
fc.Append(geojson.NewFeature(orb.Point{1, 2}))

data, err := fc.MarshalJSON()
_, err := fc.MarshalJSON()
if err != nil {
log.Fatalf("marshal error: %v", err)
}

// standard lib encoding/json package will also work
data, err = json.MarshalIndent(fc, "", " ")
data, err := json.MarshalIndent(fc, "", " ")
if err != nil {
log.Fatalf("marshal error: %v", err)
}
Expand Down
10 changes: 8 additions & 2 deletions geojson/geometry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,10 @@ func BenchmarkGeometryMarshalJSON(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
g.MarshalJSON()
_, err := g.MarshalJSON()
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -375,6 +378,9 @@ func BenchmarkGeometryUnmarshalJSON(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
g.UnmarshalJSON(data)
err := g.UnmarshalJSON(data)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
50 changes: 40 additions & 10 deletions maptile/tilecover/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ func BenchmarkPoint(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
Geometry(p, 6)
_, err := Geometry(p, 6)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -22,7 +25,10 @@ func BenchmarkRoad_z6(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
Geometry(g, 6)
_, err := Geometry(g, 6)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -32,7 +38,10 @@ func BenchmarkRoad_z18(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
Geometry(g, 18)
_, err := Geometry(g, 18)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -42,7 +51,10 @@ func BenchmarkRoad_z28(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
Geometry(g, 28)
_, err := Geometry(g, 28)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -52,7 +64,10 @@ func BenchmarkRussia_z6(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
Geometry(g, 6)
_, err := Geometry(g, 6)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -62,7 +77,10 @@ func BenchmarkRussia_z8(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
Geometry(g, 8)
_, err := Geometry(g, 8)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -72,7 +90,10 @@ func BenchmarkRussia_z10(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
Geometry(g, 10)
_, err := Geometry(g, 10)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -94,7 +115,10 @@ func BenchmarkRussiaLine_z6(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
Geometry(g, 6)
_, err := Geometry(g, 6)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -105,7 +129,10 @@ func BenchmarkRussiaLine_z8(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
Geometry(g, 8)
_, err := Geometry(g, 8)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}

Expand All @@ -116,6 +143,9 @@ func BenchmarkRussiaLine_z10(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
Geometry(g, 10)
_, err := Geometry(g, 10)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
5 changes: 4 additions & 1 deletion maptile/tilecover/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (

func TestGeometry(t *testing.T) {
for _, g := range orb.AllGeometries {
Geometry(g, 1)
_, err := Geometry(g, 1)
if err != nil {
t.Fatalf("unexpected error for %T: %v", g, err)
}
}
}
Loading

0 comments on commit 64f4429

Please sign in to comment.