mirror of
https://gh-proxy.org/https://github.com/klinsmaya/multica.git
synced 2026-11-10 02:16:45 +08:00
* test: remove implementation-only coverage Co-authored-by: multica-agent <[email protected]> * test: remove remaining implementation-only coverage Co-authored-by: multica-agent <[email protected]> * test: restore compatibility and fragment navigation coverage Co-authored-by: multica-agent <[email protected]> * test: preserve behavioral cleanup contracts Co-authored-by: multica-agent <[email protected]> --------- Co-authored-by: Sol-Boy <[email protected]> Co-authored-by: multica-agent <[email protected]>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestClientMetadataExtractsHeaders(t *testing.T) {
|
|
var gotPlatform, gotVersion, gotOS string
|
|
handler := ClientMetadata(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
|
|
gotPlatform, gotVersion, gotOS = ClientMetadataFromContext(r.Context())
|
|
}))
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
req.Header.Set(HeaderClientPlatform, "desktop")
|
|
req.Header.Set(HeaderClientVersion, "1.2.3")
|
|
req.Header.Set(HeaderClientOS, "macos")
|
|
|
|
handler.ServeHTTP(httptest.NewRecorder(), req)
|
|
|
|
if gotPlatform != "desktop" {
|
|
t.Errorf("platform: got %q, want desktop", gotPlatform)
|
|
}
|
|
if gotVersion != "1.2.3" {
|
|
t.Errorf("version: got %q, want 1.2.3", gotVersion)
|
|
}
|
|
if gotOS != "macos" {
|
|
t.Errorf("os: got %q, want macos", gotOS)
|
|
}
|
|
}
|
|
|
|
func TestClientMetadataMissingHeadersReturnEmpty(t *testing.T) {
|
|
var gotPlatform, gotVersion, gotOS string
|
|
handler := ClientMetadata(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
|
|
gotPlatform, gotVersion, gotOS = ClientMetadataFromContext(r.Context())
|
|
}))
|
|
|
|
handler.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest(http.MethodGet, "/", nil))
|
|
|
|
if gotPlatform != "" || gotVersion != "" || gotOS != "" {
|
|
t.Errorf("expected empty metadata, got (%q,%q,%q)", gotPlatform, gotVersion, gotOS)
|
|
}
|
|
}
|