MCPcopy Index your code
hub / github.com/google/go-github / TestBasicAuthTransport

Function TestBasicAuthTransport

github/github_test.go:4082–4114  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4080}
4081
4082func TestBasicAuthTransport(t *testing.T) {
4083 t.Parallel()
4084 client, mux, _ := setup(t)
4085
4086 username, password, otp := "u", "p", "123456"
4087
4088 mux.HandleFunc("/", func(_ http.ResponseWriter, r *http.Request) {
4089 u, p, ok := r.BasicAuth()
4090 if !ok {
4091 t.Error("request does not contain basic auth credentials")
4092 }
4093 if u != username {
4094 t.Errorf("request contained basic auth username %q, want %q", u, username)
4095 }
4096 if p != password {
4097 t.Errorf("request contained basic auth password %q, want %q", p, password)
4098 }
4099 if got, want := r.Header.Get(headerOTP), otp; got != want {
4100 t.Errorf("request contained OTP %q, want %q", got, want)
4101 }
4102 })
4103
4104 tp := &BasicAuthTransport{
4105 Username: username,
4106 Password: password,
4107 OTP: otp,
4108 }
4109 basicAuthClient := mustNewClient(t, WithHTTPClient(tp.Client()))
4110 basicAuthClient.baseURL = client.baseURL
4111 req, _ := basicAuthClient.NewRequest(t.Context(), "GET", ".", nil)
4112 _, err := basicAuthClient.Do(req, nil)
4113 assertNilError(t, err)
4114}
4115
4116func TestBasicAuthTransport_transport(t *testing.T) {
4117 t.Parallel()

Callers

nothing calls this directly

Calls 9

ClientMethod · 0.95
mustNewClientFunction · 0.85
WithHTTPClientFunction · 0.85
NewRequestMethod · 0.80
setupFunction · 0.70
assertNilErrorFunction · 0.70
ErrorMethod · 0.45
GetMethod · 0.45
DoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…