| 1869 | } |
| 1870 | |
| 1871 | func TestDoContext(t *testing.T) { |
| 1872 | receivedCh := make(chan struct{}) |
| 1873 | block := make(chan struct{}) |
| 1874 | testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { |
| 1875 | close(receivedCh) |
| 1876 | <-block |
| 1877 | w.WriteHeader(http.StatusOK) |
| 1878 | })) |
| 1879 | defer testServer.Close() |
| 1880 | defer close(block) |
| 1881 | |
| 1882 | ctx, cancel := context.WithCancel(context.Background()) |
| 1883 | defer cancel() |
| 1884 | |
| 1885 | go func() { |
| 1886 | <-receivedCh |
| 1887 | cancel() |
| 1888 | }() |
| 1889 | |
| 1890 | c := testRESTClient(t, testServer) |
| 1891 | _, err := c.Verb("GET"). |
| 1892 | Context(ctx). |
| 1893 | Prefix("foo"). |
| 1894 | DoRaw() |
| 1895 | if err == nil { |
| 1896 | t.Fatal("Expected context cancellation error") |
| 1897 | } |
| 1898 | } |
| 1899 | |
| 1900 | func buildString(length int) string { |
| 1901 | s := make([]byte, length) |