37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
package agentapi
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// R-1247: GET /host/line-test decodes the agent's weekly line test, and an agent before the route is a typed 404 (the
|
|
// controller reads it as „not measured" → no qBittorrent limit).
|
|
func TestLineTestDecodesAndAnOlderAgentIs404(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("GET /host/line-test", func(w http.ResponseWriter, r *http.Request) {
|
|
_, _ = w.Write([]byte(`{"ok":true,"data":{"present":true,"mbps":90.7,"measured_at":"2026-10-24T06:31:00Z","method":"iperf3-tunnel"}}`))
|
|
})
|
|
s := httptest.NewTLSServer(mux)
|
|
defer s.Close()
|
|
st, err := clientFor(t, s, strings.TrimPrefix(s.URL, "https://")).LineTest(context.Background())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !st.Present || st.Mbps != 90.7 || !st.MeasuredAtTime().Equal(time.Date(2026, 10, 24, 6, 31, 0, 0, time.UTC)) {
|
|
t.Fatalf("state = %+v", st)
|
|
}
|
|
old := httptest.NewTLSServer(http.NewServeMux())
|
|
defer old.Close()
|
|
_, err = clientFor(t, old, strings.TrimPrefix(old.URL, "https://")).LineTest(context.Background())
|
|
var se *StatusError
|
|
if !errors.As(err, &se) || se.Code != http.StatusNotFound {
|
|
t.Fatalf("an older agent must answer a typed 404, got %v", err)
|
|
}
|
|
}
|