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

Function TestRoundTripper

plugin/pkg/client/auth/exec/exec_test.go:501–617  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

499}
500
501func TestRoundTripper(t *testing.T) {
502 wantToken := ""
503
504 n := time.Now()
505 now := func() time.Time { return n }
506
507 env := []string{""}
508 environ := func() []string {
509 s := make([]string, len(env))
510 copy(s, env)
511 return s
512 }
513
514 setOutput := func(s string) {
515 env[0] = "TEST_OUTPUT=" + s
516 }
517
518 handler := func(w http.ResponseWriter, r *http.Request) {
519 gotToken := ""
520 parts := strings.Split(r.Header.Get("Authorization"), " ")
521 if len(parts) > 1 && strings.EqualFold(parts[0], "bearer") {
522 gotToken = parts[1]
523 }
524
525 if wantToken != gotToken {
526 http.Error(w, "Unauthorized", http.StatusUnauthorized)
527 return
528 }
529 fmt.Fprintln(w, "ok")
530 }
531 server := httptest.NewServer(http.HandlerFunc(handler))
532
533 c := api.ExecConfig{
534 Command: "./testdata/test-plugin.sh",
535 APIVersion: "client.authentication.k8s.io/v1alpha1",
536 }
537 a, err := newAuthenticator(newCache(), &c)
538 if err != nil {
539 t.Fatal(err)
540 }
541 a.environ = environ
542 a.now = now
543 a.stderr = ioutil.Discard
544
545 tc := &transport.Config{}
546 if err := a.UpdateTransportConfig(tc); err != nil {
547 t.Fatal(err)
548 }
549 client := http.Client{
550 Transport: tc.WrapTransport(http.DefaultTransport),
551 }
552
553 get := func(t *testing.T, statusCode int) {
554 t.Helper()
555 resp, err := client.Get(server.URL)
556 if err != nil {
557 t.Fatal(err)
558 }

Callers

nothing calls this directly

Calls 10

newAuthenticatorFunction · 0.85
newCacheFunction · 0.85
UpdateTransportConfigMethod · 0.80
NowMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.65
WrapTransportMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected