MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestParseProtoReader

Function TestParseProtoReader

pkg/util/http_test.go:142–206  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

140}
141
142func TestParseProtoReader(t *testing.T) {
143 // 47 bytes compressed and 53 uncompressed
144 req := &cortexpb.PreallocWriteRequest{
145 WriteRequest: cortexpb.WriteRequest{
146 Timeseries: []cortexpb.PreallocTimeseries{
147 {
148 TimeSeries: &cortexpb.TimeSeries{
149 Labels: []cortexpb.LabelAdapter{
150 {Name: "foo", Value: "bar"},
151 },
152 Samples: []cortexpb.Sample{
153 {Value: 10, TimestampMs: 1},
154 {Value: 20, TimestampMs: 2},
155 {Value: 30, TimestampMs: 3},
156 },
157 Exemplars: []cortexpb.Exemplar{},
158 Histograms: []cortexpb.WrappedHistogram{},
159 },
160 },
161 },
162 },
163 }
164
165 for _, tt := range []struct {
166 name string
167 compression util.CompressionType
168 maxSize int
169 expectErr bool
170 useBytesBuffer bool
171 }{
172 {"rawSnappy", util.RawSnappy, 57, false, false},
173 {"noCompression", util.NoCompression, 57, false, false},
174 {"too big rawSnappy", util.RawSnappy, 10, true, false},
175 {"too big decoded rawSnappy", util.RawSnappy, 50, true, false},
176 {"too big noCompression", util.NoCompression, 10, true, false},
177
178 {"bytesbuffer rawSnappy", util.RawSnappy, 57, false, true},
179 {"bytesbuffer noCompression", util.NoCompression, 57, false, true},
180 {"bytesbuffer too big rawSnappy", util.RawSnappy, 10, true, true},
181 {"bytesbuffer too big decoded rawSnappy", util.RawSnappy, 50, true, true},
182 {"bytesbuffer too big noCompression", util.NoCompression, 10, true, true},
183 } {
184 t.Run(tt.name, func(t *testing.T) {
185 w := httptest.NewRecorder()
186 assert.Nil(t, util.SerializeProtoResponse(w, req, tt.compression))
187 var fromWire cortexpb.PreallocWriteRequest
188
189 reader := w.Result().Body
190 if tt.useBytesBuffer {
191 buf := bytes.Buffer{}
192 _, err := buf.ReadFrom(reader)
193 assert.Nil(t, err)
194 reader = bytesBuffered{Buffer: &buf}
195 }
196
197 err := util.ParseProtoReader(context.Background(), reader, 0, tt.maxSize, &fromWire, tt.compression)
198 if tt.expectErr {
199 assert.NotNil(t, err)

Callers

nothing calls this directly

Calls 4

SerializeProtoResponseFunction · 0.92
ParseProtoReaderFunction · 0.92
RunMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected