ci / verify (push) Canceled after 0s
Add customer and operator login, BLE provisioning, device fleet controls, call memory, memoir generation, and refreshed family and maintenance portals. Include API contracts, migrations, firmware sources, tests, assets, and deployment documentation.
31 lines
1.3 KiB
Go
31 lines
1.3 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"bytes"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
"data-terminal-cloud/internal/devicefleet"
|
|
)
|
|
|
|
func TestServeFleetFirmwareContentSupportsRangeAndHead(t *testing.T) {
|
|
grant := devicefleet.DownloadGrant{SHA256: "abcd", CreatedAt: time.Unix(1_700_000_000, 0)}
|
|
|
|
rangeRequest := httptest.NewRequest(http.MethodGet, "/f/token", nil)
|
|
rangeRequest.Header.Set("Range", "bytes=2-5")
|
|
rangeResponse := httptest.NewRecorder()
|
|
serveFleetFirmwareContent(rangeResponse, rangeRequest, grant, bytes.NewReader([]byte("firmware")))
|
|
if rangeResponse.Code != http.StatusPartialContent || rangeResponse.Body.String() != "rmwa" || rangeResponse.Header().Get("Content-Range") != "bytes 2-5/8" {
|
|
t.Fatalf("range status=%d body=%q content-range=%q", rangeResponse.Code, rangeResponse.Body.String(), rangeResponse.Header().Get("Content-Range"))
|
|
}
|
|
|
|
headRequest := httptest.NewRequest(http.MethodHead, "/f/token", nil)
|
|
headResponse := httptest.NewRecorder()
|
|
serveFleetFirmwareContent(headResponse, headRequest, grant, bytes.NewReader([]byte("firmware")))
|
|
if headResponse.Code != http.StatusOK || headResponse.Body.Len() != 0 || headResponse.Header().Get("Content-Length") != "8" {
|
|
t.Fatalf("head status=%d body=%q length=%q", headResponse.Code, headResponse.Body.String(), headResponse.Header().Get("Content-Length"))
|
|
}
|
|
}
|