| 1106 | } |
| 1107 | |
| 1108 | func TestPostPostsToGivenURLUsingPipeAsRequestBody(t *testing.T) { |
| 1109 | t.Parallel() |
| 1110 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 1111 | if r.Method != http.MethodPost { |
| 1112 | t.Errorf("want HTTP method POST, got %q", r.Method) |
| 1113 | } |
| 1114 | want := []byte("request data") |
| 1115 | got, err := io.ReadAll(r.Body) |
| 1116 | if err != nil { |
| 1117 | t.Fatal("reading request body", err) |
| 1118 | } |
| 1119 | if !cmp.Equal(want, got) { |
| 1120 | t.Fatal(cmp.Diff(want, string(got))) |
| 1121 | } |
| 1122 | fmt.Fprintln(w, "response data") |
| 1123 | })) |
| 1124 | defer ts.Close() |
| 1125 | want := "response data\n" |
| 1126 | got, err := script.Echo("request data").Post(ts.URL).String() |
| 1127 | if err != nil { |
| 1128 | t.Fatalf("unexpected error: %v", err) |
| 1129 | } |
| 1130 | if !cmp.Equal(want, got) { |
| 1131 | t.Error(cmp.Diff(want, got)) |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | func TestRejectRegexp_DropsMatchingLinesFromInput(t *testing.T) { |
| 1136 | t.Parallel() |