MCPcopy
hub / github.com/SurgeDM/Surge / NewMockServerT

Function NewMockServerT

internal/testutil/mock_server.go:155–176  ·  view source on GitHub ↗

NewMockServerT creates a new mock HTTP server and skips the test if binding fails.

(t *testing.T, opts ...MockServerOption)

Source from the content-addressed store, hash-verified

153
154// NewMockServerT creates a new mock HTTP server and skips the test if binding fails.
155func NewMockServerT(t *testing.T, opts ...MockServerOption) *MockServer {
156 t.Helper()
157 m := &MockServer{
158 FileSize: types.MB,
159 SupportsRanges: true,
160 ContentType: "application/octet-stream",
161 Filename: "testfile.bin",
162 RandomData: false,
163 }
164
165 for _, opt := range opts {
166 opt(m)
167 }
168
169 m.data = make([]byte, m.FileSize)
170 if m.RandomData {
171 _, _ = rand.Read(m.data)
172 }
173
174 m.Server = NewHTTPServerT(t, http.HandlerFunc(m.handleRequest))
175 return m
176}
177
178// URL returns the server's URL.
179func (m *MockServer) URL() string {

Calls 2

NewHTTPServerTFunction · 0.85
ReadMethod · 0.45