-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
366 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
internal/schema/postgres/migrations/20231205072045_validation_reports.up.pgsql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
BEGIN; | ||
|
||
CREATE TABLE tl_validation_reports ( | ||
id bigserial primary key NOT NULL, | ||
created_at timestamp without time zone DEFAULT now() NOT NULL, | ||
updated_at timestamp without time zone DEFAULT now() NOT NULL, | ||
reported_at timestamp without time zone NOT NULL, | ||
feed_version_id bigint REFERENCES feed_versions(id) NOT NULL, | ||
file text | ||
); | ||
CREATE INDEX ON tl_validation_reports(feed_version_id); | ||
|
||
CREATE TABLE tl_validation_trip_update_stats ( | ||
id bigserial primary key NOT NULL, | ||
validation_report_id bigint REFERENCES tl_validation_reports(id) NOT NULL, | ||
agency_id text NOT NULL, | ||
route_id text NOT NULL, | ||
trip_scheduled_ids jsonb, | ||
trip_scheduled_count int NOT NULL, | ||
trip_match_count int NOT NULL | ||
); | ||
CREATE INDEX ON tl_validation_trip_update_stats(validation_report_id); | ||
|
||
CREATE TABLE tl_validation_vehicle_position_stats ( | ||
id bigserial primary key NOT NULL, | ||
validation_report_id bigint REFERENCES tl_validation_reports(id) NOT NULL, | ||
agency_id text NOT NULL, | ||
route_id text NOT NULL, | ||
trip_scheduled_ids jsonb, | ||
trip_scheduled_count int NOT NULL, | ||
trip_match_count int NOT NULL | ||
); | ||
CREATE INDEX ON tl_validation_vehicle_position_stats(validation_report_id); | ||
|
||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package validator | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/interline-io/transitland-lib/internal/testdb" | ||
"github.com/interline-io/transitland-lib/internal/testutil" | ||
"github.com/interline-io/transitland-lib/tlcsv" | ||
"github.com/interline-io/transitland-lib/tldb" | ||
) | ||
|
||
func TestSaveValidationReport(t *testing.T) { | ||
reader, err := tlcsv.NewReader(testutil.RelPath("test/data/rt/ct.zip")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
buf, err := os.ReadFile(testutil.RelPath(filepath.Join("test/data/rt", r.URL.Path))) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
w.Write(buf) | ||
})) | ||
|
||
tz, _ := time.LoadLocation("America/Los_Angeles") | ||
now := time.Date(2023, 11, 7, 17, 05, 0, 0, tz) | ||
opts := Options{ | ||
IncludeRealtimeJson: true, | ||
EvaluateAt: now, | ||
ValidateRealtimeMessages: []string{ | ||
ts.URL + "/ct-trip-updates.pb.json", | ||
ts.URL + "/ct-vehicle-positions.pb.json", | ||
}, | ||
} | ||
|
||
v, _ := NewValidator(reader, opts) | ||
result, err := v.Validate() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
testdb.TempSqlite(func(atx tldb.Adapter) error { | ||
if err := SaveValidationReport(atx, result, now, 1, true, true, ""); err != nil { | ||
t.Fatal(err) | ||
} | ||
return nil | ||
}) | ||
} |
Oops, something went wrong.