(t *testing.T)
| 122 | } |
| 123 | |
| 124 | func 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 | |
| 172 | func TestContextWithSessionID_RoundTrip(t *testing.T) { |
| 173 | t.Parallel() |
nothing calls this directly
no test coverage detected