@@ -176,3 +176,81 @@ func (s) TestHeaderListSizeDialOptionServerOption(t *testing.T) {
176176 t .Fatalf ("Unexpected s.opts.MaxHeaderListSizeDialOption.MaxHeaderListSize: %d != %d" , serverHeaderListSize , maxHeaderListSize )
177177 }
178178}
179+
180+ func (s ) TestFormatAcceptedCompressors (t * testing.T ) {
181+ tests := []struct {
182+ name string
183+ input []string
184+ want string
185+ }{
186+ {
187+ name : "empty input" ,
188+ input : []string {},
189+ want : "" ,
190+ },
191+ {
192+ name : "nil input" ,
193+ input : nil ,
194+ want : "" ,
195+ },
196+ {
197+ name : "single valid compressor" ,
198+ input : []string {"gzip" },
199+ want : "gzip" ,
200+ },
201+ {
202+ name : "multiple valid compressors" ,
203+ input : []string {"gzip" , "gzip" }, // Note: need to test with actually different compressors when available
204+ want : "gzip" , // deduplicates
205+ },
206+ {
207+ name : "compressor with whitespace" ,
208+ input : []string {" gzip " , " gzip" },
209+ want : "gzip" ,
210+ },
211+ {
212+ name : "empty strings" ,
213+ input : []string {"" , " " , "" },
214+ want : "" ,
215+ },
216+ {
217+ name : "unregistered compressor" ,
218+ input : []string {"unknown" },
219+ want : "" ,
220+ },
221+ {
222+ name : "mix of valid and invalid" ,
223+ input : []string {"unknown" , "gzip" , "notreal" },
224+ want : "gzip" ,
225+ },
226+ {
227+ name : "duplicates with whitespace" ,
228+ input : []string {"gzip" , " gzip" , "gzip " },
229+ want : "gzip" ,
230+ },
231+ {
232+ name : "empty string mixed with valid" ,
233+ input : []string {"" , "gzip" , " " , "gzip" },
234+ want : "gzip" ,
235+ },
236+ {
237+ name : "whitespace only" ,
238+ input : []string {" " , "\t " , " " },
239+ want : "" ,
240+ },
241+ {
242+ name : "preserves order after deduplication" ,
243+ input : []string {"gzip" , "gzip" },
244+ want : "gzip" ,
245+ },
246+ }
247+
248+ for _ , tt := range tests {
249+ t .Run (tt .name , func (t * testing.T ) {
250+ got := formatAcceptedCompressors (tt .input )
251+ if got != tt .want {
252+ t .Errorf ("formatAcceptedCompressors(%v) = %q, want %q" , tt .input , got , tt .want )
253+ }
254+ })
255+ }
256+ }
0 commit comments