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

Function TestWithHTTPClient_SetsSuppliedClientOnPipe

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

Source from the content-addressed store, hash-verified

1769}
1770
1771func TestWithHTTPClient_SetsSuppliedClientOnPipe(t *testing.T) {
1772 t.Parallel()
1773 ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1774 fmt.Fprintln(w, "some data")
1775 }))
1776 defer ts.Close()
1777 req, err := http.NewRequest(http.MethodGet, ts.URL, http.NoBody)
1778 if err != nil {
1779 t.Fatal(err)
1780 }
1781 want := "some data\n"
1782 // Unless the pipe uses the supplied ts.Client, we'll get a
1783 // 'certificate is not trusted' error on making the request
1784 got, err := script.NewPipe().WithHTTPClient(ts.Client()).Do(req).String()
1785 if err != nil {
1786 t.Fatalf("unexpected error: %v", err)
1787 }
1788 if !cmp.Equal(want, got) {
1789 t.Error(cmp.Diff(want, got))
1790 }
1791}
1792
1793func TestWithReader_SetsSuppliedReaderOnPipe(t *testing.T) {
1794 t.Parallel()

Callers

nothing calls this directly

Calls 6

NewPipeFunction · 0.92
StringMethod · 0.80
DoMethod · 0.80
WithHTTPClientMethod · 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…