github.com/anthropics/anthropic-sdk-go@v1.70.1/internal/stainlessheader/stainlessheader_test.go (about) 1 package stainlessheader 2 3 import ( 4 "net/http" 5 "testing" 6 ) 7 8 func TestAppendHeaderValue(t *testing.T) { 9 cases := []struct { 10 name string 11 h http.Header 12 add Value 13 want string 14 }{ 15 { 16 name: "empty", 17 h: http.Header{}, 18 add: BetaToolRunner, 19 want: "BetaToolRunner", 20 }, 21 { 22 name: "appends to existing", 23 h: http.Header{"X-Stainless-Helper": []string{"mcp_tool"}}, 24 add: BetaToolRunner, 25 want: "mcp_tool, BetaToolRunner", 26 }, 27 { 28 name: "dedups", 29 h: http.Header{"X-Stainless-Helper": []string{"compaction"}}, 30 add: Compaction, 31 want: "compaction", 32 }, 33 { 34 name: "collapses multiple lines", 35 h: http.Header{"X-Stainless-Helper": []string{"a", "b, c"}}, 36 add: Compaction, 37 want: "a, b, c, compaction", 38 }, 39 { 40 name: "trims whitespace", 41 h: http.Header{"X-Stainless-Helper": []string{" a , b "}}, 42 add: Compaction, 43 want: "a, b, compaction", 44 }, 45 } 46 for _, tc := range cases { 47 t.Run(tc.name, func(t *testing.T) { 48 AppendHeaderValue(tc.h, tc.add) 49 if got := tc.h.Get(Header); got != tc.want { 50 t.Errorf("got %q, want %q", got, tc.want) 51 } 52 if vals := tc.h.Values(Header); len(vals) != 1 { 53 t.Errorf("expected exactly one header line, got %d: %v", len(vals), vals) 54 } 55 }) 56 } 57 }