MCPcopy
hub / github.com/pocketbase/pocketbase / TestFormDataToMultipart

Function TestFormDataToMultipart

plugins/jsvm/form_data_test.go:186–225  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

184}
185
186func TestFormDataToMultipart(t *testing.T) {
187 t.Parallel()
188
189 f, err := filesystem.NewFileFromBytes([]byte("abc"), "test")
190 if err != nil {
191 t.Fatal(err)
192 }
193
194 data := FormData{}
195 data.Append("a", 1) // should be casted
196 data.Append("b", "test1")
197 data.Append("b", "test2")
198 data.Append("c", f)
199
200 body, mp, err := data.toMultipart()
201 if err != nil {
202 t.Fatal(err)
203 }
204 bodyStr := body.String()
205
206 // content type checks
207 contentType := mp.FormDataContentType()
208 expectedContentType := "multipart/form-data; boundary="
209 if !strings.Contains(contentType, expectedContentType) {
210 t.Fatalf("Expected to find content-type %s in %s", expectedContentType, contentType)
211 }
212
213 // body checks
214 expectedBodyParts := []string{
215 "Content-Disposition: form-data; name=\"a\"\r\n\r\n1",
216 "Content-Disposition: form-data; name=\"b\"\r\n\r\ntest1",
217 "Content-Disposition: form-data; name=\"b\"\r\n\r\ntest2",
218 "Content-Disposition: form-data; name=\"c\"; filename=\"test\"\r\nContent-Type: application/octet-stream\r\n\r\nabc",
219 }
220 for _, part := range expectedBodyParts {
221 if !strings.Contains(bodyStr, part) {
222 t.Fatalf("Expected to find %s in body\n%s", part, bodyStr)
223 }
224 }
225}

Callers

nothing calls this directly

Calls 4

AppendMethod · 0.95
toMultipartMethod · 0.95
NewFileFromBytesFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…