From e35112a89ea931332aa9c87d246785365547a930 Mon Sep 17 00:00:00 2001 From: Ian Rees Date: Mon, 8 Jan 2024 19:46:07 -0800 Subject: [PATCH] Fix error coords (#199) * Fix coord issue * Bump to tl head --- actions/validate_test.go | 77 +++++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 8 ++-- internal/testutil/fs.go | 21 ++++++++++ test/data/rt/CT-vp-error.json | 29 +++++++++++++ 5 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 actions/validate_test.go create mode 100644 internal/testutil/fs.go create mode 100644 test/data/rt/CT-vp-error.json diff --git a/actions/validate_test.go b/actions/validate_test.go new file mode 100644 index 00000000..1a019427 --- /dev/null +++ b/actions/validate_test.go @@ -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)) + }) + }) + } +} diff --git a/go.mod b/go.mod index 1f869962..bb7e664d 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 999bc0a7..847f67de 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/testutil/fs.go b/internal/testutil/fs.go new file mode 100644 index 00000000..ae8d5892 --- /dev/null +++ b/internal/testutil/fs.go @@ -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 +} diff --git a/test/data/rt/CT-vp-error.json b/test/data/rt/CT-vp-error.json new file mode 100644 index 00000000..aca95ec2 --- /dev/null +++ b/test/data/rt/CT-vp-error.json @@ -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" + } + } + ] + } \ No newline at end of file