| 27 | } |
| 28 | |
| 29 | func TestHandler_Handle_GET(t *testing.T) { |
| 30 | h := &handler{} |
| 31 | r := httptest.NewRequest("GET", "/test/path?foo=bar", nil) |
| 32 | r.Header.Set("X-Custom", "value") |
| 33 | r.Host = "example.com" |
| 34 | |
| 35 | inc, err := h.Handle(r) |
| 36 | if err != nil { |
| 37 | t.Fatal(err) |
| 38 | } |
| 39 | if inc.Type != "http-dump" { |
| 40 | t.Errorf("Type = %q, want %q", inc.Type, "http-dump") |
| 41 | } |
| 42 | if inc.UUID == "" { |
| 43 | t.Error("UUID should be generated") |
| 44 | } |
| 45 | |
| 46 | var payload map[string]any |
| 47 | json.Unmarshal(inc.Payload, &payload) |
| 48 | |
| 49 | if payload["host"] != "example.com" { |
| 50 | t.Errorf("host = %v", payload["host"]) |
| 51 | } |
| 52 | |
| 53 | req, _ := payload["request"].(map[string]any) |
| 54 | if req == nil { |
| 55 | t.Fatal("request is nil") |
| 56 | } |
| 57 | if req["method"] != "GET" { |
| 58 | t.Errorf("method = %v", req["method"]) |
| 59 | } |
| 60 | if req["uri"] != "test/path" { |
| 61 | t.Errorf("uri = %v", req["uri"]) |
| 62 | } |
| 63 | |
| 64 | query, _ := req["query"].(map[string]any) |
| 65 | if query["foo"] != "bar" { |
| 66 | t.Errorf("query.foo = %v", query["foo"]) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | func TestHandler_Handle_POST_JSON(t *testing.T) { |
| 71 | h := &handler{} |