MCPcopy Index your code
hub / github.com/docker/cli / TestNewAPIClientFromFlagsWithCustomHeadersFromEnv

Function TestNewAPIClientFromFlagsWithCustomHeadersFromEnv

cli/command/cli_test.go:87–120  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

85}
86
87func TestNewAPIClientFromFlagsWithCustomHeadersFromEnv(t *testing.T) {
88 var received http.Header
89 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
90 received = r.Header.Clone()
91 _, _ = w.Write([]byte("OK"))
92 }))
93 defer ts.Close()
94 host := strings.Replace(ts.URL, "http://", "tcp://", 1)
95 opts := &flags.ClientOptions{Hosts: []string{host}}
96 configFile := &configfile.ConfigFile{
97 HTTPHeaders: map[string]string{
98 "My-Header": "Custom-Value from config-file",
99 },
100 }
101
102 // envOverrideHTTPHeaders should override the HTTPHeaders from the config-file,
103 // so "My-Header" should not be present.
104 t.Setenv(envOverrideHTTPHeaders, `one=one-value,"two=two,value",three=,four=four-value,four=four-value-override`)
105 apiClient, err := NewAPIClientFromFlags(opts, configFile)
106 assert.NilError(t, err)
107 assert.Equal(t, apiClient.DaemonHost(), host)
108 assert.Equal(t, apiClient.ClientVersion(), client.MaxAPIVersion)
109
110 expectedHeaders := http.Header{
111 "One": []string{"one-value"},
112 "Two": []string{"two,value"},
113 "Three": []string{""},
114 "Four": []string{"four-value-override"},
115 "User-Agent": []string{UserAgent()},
116 }
117 _, err = apiClient.Ping(context.TODO(), client.PingOptions{})
118 assert.NilError(t, err)
119 assert.DeepEqual(t, received, expectedHeaders)
120}
121
122func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {
123 const customVersion = "v3.3"

Callers

nothing calls this directly

Calls 6

NewAPIClientFromFlagsFunction · 0.85
UserAgentFunction · 0.85
WriteMethod · 0.45
CloseMethod · 0.45
ClientVersionMethod · 0.45
PingMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…