MCPcopy
hub / github.com/kubernetes/client-go / TestDoContext

Function TestDoContext

rest/request_test.go:1871–1898  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1869}
1870
1871func 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
1900func buildString(length int) string {
1901 s := make([]byte, length)

Callers

nothing calls this directly

Calls 6

testRESTClientFunction · 0.85
PrefixMethod · 0.80
ContextMethod · 0.80
CloseMethod · 0.65
DoRawMethod · 0.65
VerbMethod · 0.65

Tested by

no test coverage detected