Files
zeekayandHanzo Dev 3e48473192 feat(http): route every listener on zap-proto/zip v1.17.2
The Data API, MCP and debug listeners each hand-rolled a net/http.ServeMux.
They now declare routes on one zip.App built by internal/util/zipapp, so ZAP
is the transport and HTTP is a view of the same routes. zipapp keeps the
net/http error rendering (plain-text 404/405, nosniff) so no client sees a
new response shape; zipapp_test asserts that parity directly.

zip.AdaptNetHTTP is the single escape hatch for the handlers that are genuinely
net/http (pprof, expvar, statsviz, promhttp) — there is no second adapter.

This work existed only locally: main's history was rewritten this morning and
took it with it, so it is replayed here against current main rather than
merged from the pre-rewrite lineage, and lands straight on the fleet-standard
v1.17.2 instead of the v1.12.0 it was written against. zip v1.17.x requires
go >= 1.26.5, hence the directive bump, and pulls zap-proto/http v0.3.1 —
peers must be on v0.3.x to talk to it.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-27 18:01:51 -07:00

68 lines
2.0 KiB
Go

// Copyright 2021 DocDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package server
import (
"encoding/json"
"fmt"
"testing"
"github.com/AlekSi/pointer"
"github.com/FerretDB/wire/wirebson"
"github.com/FerretDB/wire/wiretest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPrepareRequest(t *testing.T) {
for name, tc := range map[string]struct {
pairs []any
expected *wirebson.Document
err error
}{
"Simple": {
pairs: []any{"foo", "bar"},
expected: wirebson.MustDocument("foo", "bar"),
},
"RawMessage": {
pairs: []any{"foo", pointer.To(json.RawMessage(`{"foo":"bar"}`))},
expected: wirebson.MustDocument("foo", wirebson.MustDocument("foo", "bar")),
},
"RawMessageArray": {
pairs: []any{"foo", pointer.To(json.RawMessage(`["foo","bar"]`))},
expected: wirebson.MustDocument("foo", wirebson.MustArray("foo", "bar")),
},
"Float32": {
pairs: []any{"foo", pointer.To(float32(1))},
expected: wirebson.MustDocument("foo", float64(1)),
},
"EmptyRawMessage": {
pairs: []any{"foo", pointer.To(json.RawMessage{})},
err: fmt.Errorf("server.go:260 (server.prepareRequest): Invalid object: []"),
},
} {
t.Run(name, func(t *testing.T) {
actual, err := prepareRequest(tc.pairs...)
if tc.err != nil {
assert.EqualError(t, err, tc.err.Error())
return
}
require.NoError(t, err)
wiretest.AssertEqual(t, tc.expected, actual.Document())
})
}
}