...
1
16
17 package kubernetes_test
18
19 import (
20 "bytes"
21 "context"
22 "io"
23 "net/http"
24 "testing"
25
26 appsv1 "k8s.io/api/apps/v1"
27 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28 "k8s.io/apimachinery/pkg/util/dump"
29 "k8s.io/client-go/kubernetes"
30 "k8s.io/client-go/kubernetes/scheme"
31 "k8s.io/client-go/rest"
32 manualfake "k8s.io/client-go/rest/fake"
33 )
34
35 func TestListTimeout(t *testing.T) {
36 fakeClient := &manualfake.RESTClient{
37 GroupVersion: appsv1.SchemeGroupVersion,
38 NegotiatedSerializer: scheme.Codecs,
39 Client: manualfake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
40 if req.URL.Query().Get("timeout") != "21s" {
41 t.Fatal(dump.Pretty(req.URL.Query()))
42 }
43 return &http.Response{StatusCode: http.StatusNotFound, Body: io.NopCloser(&bytes.Buffer{})}, nil
44 }),
45 }
46 clientConfig := &rest.Config{
47 APIPath: "/apis",
48 ContentConfig: rest.ContentConfig{
49 NegotiatedSerializer: scheme.Codecs,
50 GroupVersion: &appsv1.SchemeGroupVersion,
51 },
52 }
53 restClient, _ := rest.RESTClientFor(clientConfig)
54 restClient.Client = fakeClient.Client
55 realClient := kubernetes.New(restClient)
56
57 timeout := int64(21)
58 realClient.AppsV1().DaemonSets("").List(context.TODO(), metav1.ListOptions{TimeoutSeconds: &timeout})
59 realClient.AppsV1().DaemonSets("").Watch(context.TODO(), metav1.ListOptions{TimeoutSeconds: &timeout})
60 }
61
View as plain text