MCPcopy
hub / github.com/docker/docker-agent / TestSessionIDHeader_GatewayBoundOnly

Function TestSessionIDHeader_GatewayBoundOnly

pkg/httpclient/client_test.go:124–170  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

122}
123
124func TestSessionIDHeader_GatewayBoundOnly(t *testing.T) {
125 t.Parallel()
126
127 tests := []struct {
128 name string
129 ctxSessionID string
130 opts []Opt
131 wantHeaderSent bool
132 }{
133 {
134 name: "session ID present, gateway-bound (X-Cagent-Forward set) → header sent",
135 ctxSessionID: "sess-abc",
136 opts: []Opt{WithProxiedBaseURL("https://gateway.example/v1")},
137 wantHeaderSent: true,
138 },
139 {
140 name: "session ID present, no X-Cagent-Forward → header skipped",
141 ctxSessionID: "sess-abc",
142 opts: nil,
143 wantHeaderSent: false,
144 },
145 {
146 name: "no session ID on context, gateway-bound → header skipped",
147 ctxSessionID: "",
148 opts: []Opt{WithProxiedBaseURL("https://gateway.example/v1")},
149 wantHeaderSent: false,
150 },
151 }
152
153 for _, tt := range tests {
154 t.Run(tt.name, func(t *testing.T) {
155 t.Parallel()
156
157 ctx := t.Context()
158 if tt.ctxSessionID != "" {
159 ctx = ContextWithSessionID(ctx, tt.ctxSessionID)
160 }
161 headers := doRequestWithCtx(t, ctx, tt.opts...)
162
163 if tt.wantHeaderSent {
164 assert.Equal(t, tt.ctxSessionID, headers.Get("X-Cagent-Session-Id"))
165 } else {
166 assert.Empty(t, headers.Get("X-Cagent-Session-Id"))
167 }
168 })
169 }
170}
171
172func TestContextWithSessionID_RoundTrip(t *testing.T) {
173 t.Parallel()

Callers

nothing calls this directly

Calls 6

WithProxiedBaseURLFunction · 0.85
ContextWithSessionIDFunction · 0.85
doRequestWithCtxFunction · 0.85
ContextMethod · 0.80
RunMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected