| 1769 | } |
| 1770 | |
| 1771 | func 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 | |
| 1793 | func TestWithReader_SetsSuppliedReaderOnPipe(t *testing.T) { |
| 1794 | t.Parallel() |