MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / TestRangeRequest

Method TestRangeRequest

storage/testsuite/reader.go:127–152  ·  view source on GitHub ↗

TestRangeRequest verifies that Range header returns partial content

()

Source from the content-addressed store, hash-verified

125
126// TestRangeRequest verifies that Range header returns partial content
127func (s *ReaderSuite) TestRangeRequest() {
128 ctx := s.T().Context()
129 reqHeader := make(http.Header)
130 reqHeader.Set(httpheaders.Range, "bytes=10-19")
131
132 response, err := s.Storage().GetObject(ctx, reqHeader, s.TestContainer, s.TestObjectKey, "")
133 s.Require().NoError(err)
134
135 if !s.SkipPartialContentChecks {
136 s.Require().Equal(http.StatusPartialContent, response.Status)
137
138 expectedRange := fmt.Sprintf("bytes 10-19/%d", len(s.TestData))
139 s.Require().Equal(expectedRange, response.Headers.Get(httpheaders.ContentRange))
140 }
141
142 s.Require().Equal("10", response.Headers.Get(httpheaders.ContentLength))
143 s.Require().NotNil(response.Body)
144
145 // Read and verify the actual content (bytes 10-19 from testData)
146 buf := make([]byte, 10)
147 n, _ := response.Body.Read(buf)
148 s.Require().Equal(10, n)
149 s.Require().Equal(s.TestData[10:20], buf)
150
151 response.Body.Close()
152}
153
154// TestObjectNotFound verifies that requesting a non-existent object returns 404
155func (s *ReaderSuite) TestObjectNotFound() {

Callers

nothing calls this directly

Calls 6

TMethod · 0.80
GetObjectMethod · 0.65
GetMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected