(t *testing.T)
| 184 | } |
| 185 | |
| 186 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…