MCPcopy Create free account
hub / github.com/containers/image / TestUserAgent

Function TestUserAgent

docker/docker_client_test.go:154–184  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

152}
153
154func TestUserAgent(t *testing.T) {
155 const sentinelUA = "sentinel/1.0"
156
157 var expectedUA string
158 s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
159 got := r.Header.Get("User-Agent")
160 assert.Equal(t, expectedUA, got)
161 w.WriteHeader(http.StatusOK)
162 }))
163 defer s.Close()
164
165 for _, tc := range []struct {
166 sys *types.SystemContext
167 expected string
168 }{
169 // Can't both test nil and set DockerInsecureSkipTLSVerify :(
170 // {nil, defaultUA},
171 {&types.SystemContext{}, useragent.DefaultUserAgent},
172 {&types.SystemContext{DockerRegistryUserAgent: sentinelUA}, sentinelUA},
173 } {
174 // For this test against localhost, we don't care.
175 tc.sys.DockerInsecureSkipTLSVerify = types.OptionalBoolTrue
176
177 registry := strings.TrimPrefix(s.URL, "http://")
178
179 expectedUA = tc.expected
180 if err := CheckAuth(context.Background(), tc.sys, "", "", registry); err != nil {
181 t.Fatalf("unexpected error: %v", err)
182 }
183 }
184}
185
186var registrySuseComResp = http.Response{
187 Status: "401 Unauthorized",

Callers

nothing calls this directly

Calls 3

CheckAuthFunction · 0.85
GetMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…