Skip to content

Commit

Permalink
Fix error coords (#199)
Browse files Browse the repository at this point in the history
* Fix coord issue

* Bump to tl head
  • Loading branch information
irees authored Jan 9, 2024
1 parent 24f53db commit e35112a
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 5 deletions.
77 changes: 77 additions & 0 deletions actions/validate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package actions

import (
"context"
"testing"

"github.com/interline-io/transitland-server/internal/testconfig"
"github.com/interline-io/transitland-server/internal/testutil"
"github.com/interline-io/transitland-server/model"
"github.com/stretchr/testify/assert"
)

func TestValidateUpload(t *testing.T) {
tcs := []struct {
name string
serveFile string
rtUrls []string
expectError bool
f func(*testing.T, *model.ValidationResult)
}{
{
name: "ct",
serveFile: "test/data/external/caltrain.zip",
rtUrls: []string{"test/data/rt/CT-vp-error.json"},
f: func(t *testing.T, result *model.ValidationResult) {
if len(result.Errors) != 1 {
t.Fatal("expected errors")
return
}
if len(result.Errors[0].Errors) != 1 {
t.Fatal("expected errors")
return
}
g := result.Errors[0].Errors[0]
gg := g.Geometries
if len(gg) != 2 {
t.Fatal("expected 2 geometries")
}
assert.Equal(t, len(gg[0].Geometry.FlatCoords()), 1112)
assert.Equal(t, len(gg[1].Geometry.FlatCoords()), 2)
},
},
}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
// Setup http
ts := testutil.NewTestFileserver()
defer ts.Close()

// Setup job
testconfig.ConfigTxRollback(t, testconfig.Options{}, func(cfg model.Config) {
cfg.Checker = nil // disable checker for this test
ctx := model.WithConfig(context.Background(), cfg)
// Run job
feedUrl := ts.URL + "/" + tc.serveFile
var rturls []string
for _, v := range tc.rtUrls {
rturls = append(rturls, ts.URL+"/"+v)
}
result, err := ValidateUpload(ctx, nil, &feedUrl, rturls)
if err != nil && !tc.expectError {
_ = result
t.Fatal("unexpected error", err)
} else if err == nil && tc.expectError {
t.Fatal("expected responseError")
} else if err != nil && tc.expectError {
return
}
if tc.f != nil {
tc.f(t, result)
}
// jj, _ := json.MarshalIndent(result, "", " ")
// fmt.Println(string(jj))
})
})
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/graph-gophers/dataloader/v7 v7.1.0
github.com/hypirion/go-filecache v0.0.0-20160810125507-e3e6ef6981f0
github.com/interline-io/log v0.0.0-20231211003339-8bdc406adcd2
github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231202005632-a9ea742322f7
github.com/interline-io/transitland-lib v0.14.1-0.20240109033825-0d199706b8eb
github.com/interline-io/transitland-mw v0.0.0-20231220044449-a6aac07a9d9e
github.com/jellydator/ttlcache/v2 v2.11.1
github.com/jmoiron/sqlx v1.3.5
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/interline-io/log v0.0.0-20231211003339-8bdc406adcd2 h1:ScRM8Kr6UwAvblyGMdupRwEy7eWCROPLWmGJf1J1aOk=
github.com/interline-io/log v0.0.0-20231211003339-8bdc406adcd2/go.mod h1:chJaM8SKcHI6ivoeFuZ8M8axTjSV4TPmuQ+sAyAHa34=
github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231202005632-a9ea742322f7 h1:rwkKzYzl05Q4TM++L9RIJbXPjIvURoMN5vEr8dvUV/Q=
github.com/interline-io/transitland-lib v0.14.0-rc1.0.20231202005632-a9ea742322f7/go.mod h1:UcfuCX6DyKt/yn5GECFn3jQ6NcZEjt5XyPjf8a3tXZ4=
github.com/interline-io/transitland-mw v0.0.0-20231220044108-68bdd4c22c0c h1:orFgIOZXD989tkOBASbU/u2ksHLTYKMrOdKBk+U1wlY=
github.com/interline-io/transitland-mw v0.0.0-20231220044108-68bdd4c22c0c/go.mod h1:QyssKyKXwbTWhFT9O08nVj+gScPntMvLh1qMGNr1Ksw=
github.com/interline-io/transitland-lib v0.14.1-0.20240109032839-7988636829e2 h1:GYiCu6h+8hfEka4kHueSXnk8KEdxGjGgL8K0Y20M0Rc=
github.com/interline-io/transitland-lib v0.14.1-0.20240109032839-7988636829e2/go.mod h1:TwGmZjX/iJRaYWKKosU/TIn8Dt4dywYCAXqmZwAA6qo=
github.com/interline-io/transitland-lib v0.14.1-0.20240109033825-0d199706b8eb h1:TeyCU2enrDL40wGz4KujogH4gfzr4cuSyC2axdjM/Go=
github.com/interline-io/transitland-lib v0.14.1-0.20240109033825-0d199706b8eb/go.mod h1:TwGmZjX/iJRaYWKKosU/TIn8Dt4dywYCAXqmZwAA6qo=
github.com/interline-io/transitland-mw v0.0.0-20231220044449-a6aac07a9d9e h1:MZnYbL21CKMWQkNBaG6xnWjU7J7uXErlBM4RwXjIfRQ=
github.com/interline-io/transitland-mw v0.0.0-20231220044449-a6aac07a9d9e/go.mod h1:QyssKyKXwbTWhFT9O08nVj+gScPntMvLh1qMGNr1Ksw=
github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww=
Expand Down
21 changes: 21 additions & 0 deletions internal/testutil/fs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package testutil

import (
"fmt"
"net/http"
"net/http/httptest"
"os"
)

func NewTestFileserver() *httptest.Server {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.URL.Path)
buf, err := os.ReadFile(RelPath(r.URL.Path))
if err != nil {
http.Error(w, "404", 404)
return
}
w.Write(buf)
}))
return ts
}
29 changes: 29 additions & 0 deletions test/data/rt/CT-vp-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"header": {
"gtfsRealtimeVersion": "1.0",
"incrementality": "FULL_DATASET",
"timestamp": "1699405559"
},
"entity": [
{
"id": "124",
"vehicle": {
"trip": {
"tripId": "221",
"routeId": "L1",
"directionId": 1
},
"vehicle": {
"id": "124",
"label": "",
"licensePlate": ""
},
"position": {
"latitude": 37.368795,
"longitude": -121.996072
},
"timestamp": "1699405549"
}
}
]
}

0 comments on commit e35112a

Please sign in to comment.