MCPcopy
hub / github.com/bitfield/script / TestPostPostsToGivenURLUsingPipeAsRequestBody

Function TestPostPostsToGivenURLUsingPipeAsRequestBody

script_test.go:1108–1133  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1106}
1107
1108func 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
1135func TestRejectRegexp_DropsMatchingLinesFromInput(t *testing.T) {
1136 t.Parallel()

Callers

nothing calls this directly

Calls 5

EchoFunction · 0.92
StringMethod · 0.80
PostMethod · 0.80
ErrorMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…