test: expand route coverage
Some checks failed
ci / test (push) Has been cancelled
build / goreleaser (push) Has been cancelled

This commit is contained in:
Peter Steinberger 2026-01-02 23:01:29 +01:00
parent 859a7ea3b8
commit 16c0093b92
2 changed files with 53 additions and 0 deletions

View File

@ -306,6 +306,40 @@ func TestRunRouteHuman(t *testing.T) {
}
}
func TestRunRouteValidationError(t *testing.T) {
var stdout bytes.Buffer
var stderr bytes.Buffer
exitCode := Run([]string{
"route",
"coffee",
"--from", "A",
"--to", "B",
"--mode", "FLY",
"--api-key", "test-key",
}, &stdout, &stderr)
if exitCode != 2 {
t.Fatalf("expected validation error exit code 2, got %d", exitCode)
}
}
func TestRunRouteMissingFrom(t *testing.T) {
var stdout bytes.Buffer
var stderr bytes.Buffer
exitCode := Run([]string{
"route",
"coffee",
"--to", "B",
"--api-key", "test-key",
}, &stdout, &stderr)
if exitCode != 2 {
t.Fatalf("expected validation error exit code 2, got %d", exitCode)
}
}
func TestRunDetailsJSON(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/places/place-1" {

View File

@ -95,6 +95,25 @@ func TestSampleWaypointsSinglePoint(t *testing.T) {
}
}
func TestSampleWaypointsZeroTotal(t *testing.T) {
points := []LatLng{{Lat: 1, Lng: 1}, {Lat: 1, Lng: 1}}
waypoints := sampleWaypoints(points, 3)
if len(waypoints) != 1 {
t.Fatalf("expected 1 waypoint")
}
if waypoints[0] != points[0] {
t.Fatalf("unexpected waypoint: %#v", waypoints[0])
}
}
func TestSampleWaypointsMaxExceedsPoints(t *testing.T) {
points := []LatLng{{Lat: 0, Lng: 0}, {Lat: 0, Lng: 0}, {Lat: 0, Lng: 1}}
waypoints := sampleWaypoints(points, 5)
if len(waypoints) != 2 {
t.Fatalf("expected 2 waypoints, got %d", len(waypoints))
}
}
func TestPointAtDistanceBounds(t *testing.T) {
points := []LatLng{{Lat: 0, Lng: 0}, {Lat: 0, Lng: 2}}
cumulative := cumulativeDistances(points)