MCPcopy Create free account
hub / github.com/WICG/webpackage / TestEncodeMultipleRecordsDraft03

Function TestEncodeMultipleRecordsDraft03

go/signedexchange/mice/mice_test.go:178–237  ·  view source on GitHub ↗

https://tools.ietf.org/html/draft-thomson-http-mice-03#section-4.2

(t *testing.T)

Source from the content-addressed store, hash-verified

176
177// https://tools.ietf.org/html/draft-thomson-http-mice-03#section-4.2
178func TestEncodeMultipleRecordsDraft03(t *testing.T) {
179 var buf bytes.Buffer
180 message := []byte("When I grow up, I want to be a watermelon")
181 mi, err := Draft03Encoding.Encode(&buf, message, 16)
182 if err != nil {
183 t.Fatal(err)
184 }
185 wantMI := "mi-sha256-03=IVa9shfs0nyKEhHqtB3WVNANJ2Njm5KjQLjRtnbkYJ4="
186 if mi != wantMI {
187 t.Errorf("e.MI(); got %v, want %v", mi, wantMI)
188 }
189
190 b := buf.Bytes()
191 if len(b) != 113 {
192 t.Errorf("unexpected buf length %d", len(b))
193 }
194
195 cases := []struct {
196 begin int
197 end int
198 want []byte
199 }{
200 {
201 begin: 0,
202 end: 8,
203 want: []byte{0, 0, 0, 0, 0, 0, 0, 16},
204 },
205 {
206 begin: 8,
207 end: 24,
208 want: message[0:16],
209 },
210 {
211 begin: 24,
212 end: 56,
213 want: mustStdEncodeBase64("OElbplJlPK+Rv6JNK6p5/515IaoPoZo+2elWL7OQ60A="),
214 },
215 {
216 begin: 56,
217 end: 72,
218 want: message[16:32],
219 },
220 {
221 begin: 72,
222 end: 104,
223 want: mustStdEncodeBase64("iPMpmgExHPrbEX3/RvwP4d16fWlK4l++p75PUu/KyN0="),
224 },
225 {
226 begin: 104,
227 end: len(b),
228 want: message[32:],
229 },
230 }
231 for _, c := range cases {
232 gotBytes := b[c.begin:c.end]
233 if !bytes.Equal(gotBytes, c.want) {
234 t.Errorf("b[%d:%d]: got %v, want %v", c.begin, c.end, gotBytes, c.want)
235 }

Callers

nothing calls this directly

Calls 2

mustStdEncodeBase64Function · 0.85
EncodeMethod · 0.45

Tested by

no test coverage detected