| 642 | } |
| 643 | |
| 644 | func TestGetMakesHTTPGetRequestToGivenURL(t *testing.T) { |
| 645 | t.Parallel() |
| 646 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 647 | if r.Method != http.MethodGet { |
| 648 | t.Fatalf("want HTTP method GET, got %q", r.Method) |
| 649 | } |
| 650 | fmt.Fprintln(w, "some data") |
| 651 | })) |
| 652 | defer ts.Close() |
| 653 | want := "some data\n" |
| 654 | got, err := script.Get(ts.URL).String() |
| 655 | if err != nil { |
| 656 | t.Fatalf("unexpected error: %v", err) |
| 657 | } |
| 658 | if !cmp.Equal(want, got) { |
| 659 | t.Error(cmp.Diff(want, got)) |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | func TestGetSetsErrorStatusWhenHTTPResponseStatusIsNotOK(t *testing.T) { |
| 664 | t.Parallel() |