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

Function TestEncodeMultipleRecordsDraft02

go/signedexchange/mice/mice_test.go:116–175  ·  view source on GitHub ↗

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

(t *testing.T)

Source from the content-addressed store, hash-verified

114
115// https://tools.ietf.org/html/draft-thomson-http-mice-02#section-4.2
116func TestEncodeMultipleRecordsDraft02(t *testing.T) {
117 var buf bytes.Buffer
118 message := []byte("When I grow up, I want to be a watermelon")
119 mi, err := Draft02Encoding.Encode(&buf, message, 16)
120 if err != nil {
121 t.Fatal(err)
122 }
123 wantMI := "mi-sha256-draft2=IVa9shfs0nyKEhHqtB3WVNANJ2Njm5KjQLjRtnbkYJ4"
124 if mi != wantMI {
125 t.Errorf("e.MI(); got %v, want %v", mi, wantMI)
126 }
127
128 b := buf.Bytes()
129 if len(b) != 113 {
130 t.Errorf("unexpected buf length %d", len(b))
131 }
132
133 cases := []struct {
134 begin int
135 end int
136 want []byte
137 }{
138 {
139 begin: 0,
140 end: 8,
141 want: []byte{0, 0, 0, 0, 0, 0, 0, 16},
142 },
143 {
144 begin: 8,
145 end: 24,
146 want: message[0:16],
147 },
148 {
149 begin: 24,
150 end: 56,
151 want: mustRawEncodeBase64("OElbplJlPK-Rv6JNK6p5_515IaoPoZo-2elWL7OQ60A"),
152 },
153 {
154 begin: 56,
155 end: 72,
156 want: message[16:32],
157 },
158 {
159 begin: 72,
160 end: 104,
161 want: mustRawEncodeBase64("iPMpmgExHPrbEX3_RvwP4d16fWlK4l--p75PUu_KyN0"),
162 },
163 {
164 begin: 104,
165 end: len(b),
166 want: message[32:],
167 },
168 }
169 for _, c := range cases {
170 gotBytes := b[c.begin:c.end]
171 if !bytes.Equal(gotBytes, c.want) {
172 t.Errorf("b[%d:%d]: got %v, want %v", c.begin, c.end, gotBytes, c.want)
173 }

Callers

nothing calls this directly

Calls 2

mustRawEncodeBase64Function · 0.85
EncodeMethod · 0.45

Tested by

no test coverage detected