Add a reorderpcap tool

This commit is contained in:
2026-10-05 20:35:47 +02:00
parent c11c893845
commit e70549337e
5 changed files with 46 additions and 28 deletions
+4 -4
View File
@@ -28,7 +28,7 @@ func testPcap(t *testing.T, packets int) []byte {
return buf.Bytes()
}
func postSplit(t *testing.T, srv *Server, filename string, file []byte, fields map[string]string) *httptest.ResponseRecorder {
func postUpload(t *testing.T, srv *Server, target, filename string, file []byte, fields map[string]string) *httptest.ResponseRecorder {
t.Helper()
var body bytes.Buffer
mw := multipart.NewWriter(&body)
@@ -43,7 +43,7 @@ func postSplit(t *testing.T, srv *Server, filename string, file []byte, fields m
fw.Write(file)
}
mw.Close()
req := httptest.NewRequest("POST", "/split", &body)
req := httptest.NewRequest("POST", target, &body)
req.Header.Set("Content-Type", mw.FormDataContentType())
rec := httptest.NewRecorder()
srv.ServeHTTP(rec, req)
@@ -68,7 +68,7 @@ func TestSplitHandler(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rec := postSplit(t, srv, `C:\caps\my capture.pcap`, in, tt.fields)
rec := postUpload(t, srv, "/split", `C:\caps\my capture.pcap`, in, tt.fields)
if rec.Code != http.StatusOK || rec.Header().Get("Content-Type") != "application/zip" {
t.Fatalf("status %d %s: %s", rec.Code, rec.Header().Get("Content-Type"), rec.Body)
}
@@ -120,7 +120,7 @@ func TestSplitHandlerErrors(t *testing.T) {
{"no mode", testPcap(t, 1), map[string]string{}, http.StatusBadRequest, "choose whether"},
}
for _, tt := range tests {
rec := postSplit(t, srv, "x.pcap", tt.file, tt.fields)
rec := postUpload(t, srv, "/split", "x.pcap", tt.file, tt.fields)
if rec.Code != tt.status || !strings.Contains(rec.Body.String(), tt.want) {
t.Errorf("%s: status %d, body %.300s", tt.name, rec.Code, rec.Body)
}