NewMockServerT creates a new mock HTTP server and skips the test if binding fails.
(t *testing.T, opts ...MockServerOption)
| 153 | |
| 154 | // NewMockServerT creates a new mock HTTP server and skips the test if binding fails. |
| 155 | func 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. |
| 179 | func (m *MockServer) URL() string { |