openai/openai-go
Publicmirrored from https://github.com/openai/openai-goAvailable
internal/requestconfig/requestconfig_test.go
50lines · modecode
| 1 | package requestconfig |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestFormatPathEscapesPathParams(t *testing.T) { |
| 6 | tests := map[string]struct { |
| 7 | format string |
| 8 | params []string |
| 9 | want string |
| 10 | }{ |
| 11 | "slash": { |
| 12 | format: "vector_stores/%s", |
| 13 | params: []string{"../videos/vid_123"}, |
| 14 | want: "vector_stores/..%2Fvideos%2Fvid_123", |
| 15 | }, |
| 16 | "query and fragment": { |
| 17 | format: "vector_stores/%s", |
| 18 | params: []string{"vs_123/files/file_456?limit=1#frag"}, |
| 19 | want: "vector_stores/vs_123%2Ffiles%2Ffile_456%3Flimit=1%23frag", |
| 20 | }, |
| 21 | "encoded dot segments": { |
| 22 | format: "vector_stores/%s", |
| 23 | params: []string{"%2e%2e/videos/vid_123"}, |
| 24 | want: "vector_stores/%252e%252e%2Fvideos%2Fvid_123", |
| 25 | }, |
| 26 | "bare dot": { |
| 27 | format: "vector_stores/%s", |
| 28 | params: []string{"."}, |
| 29 | want: "vector_stores/%2E", |
| 30 | }, |
| 31 | "bare dot dot": { |
| 32 | format: "vector_stores/%s", |
| 33 | params: []string{".."}, |
| 34 | want: "vector_stores/%2E%2E", |
| 35 | }, |
| 36 | "multiple params": { |
| 37 | format: "organization/projects/%s/api_keys/%s", |
| 38 | params: []string{"proj_123/../../admin_api_keys/key_456?", "ignored"}, |
| 39 | want: "organization/projects/proj_123%2F..%2F..%2Fadmin_api_keys%2Fkey_456%3F/api_keys/ignored", |
| 40 | }, |
| 41 | } |
| 42 | |
| 43 | for name, test := range tests { |
| 44 | t.Run(name, func(t *testing.T) { |
| 45 | if got := FormatPath(test.format, test.params...); got != test.want { |
| 46 | t.Fatalf("FormatPath() = %q, want %q", got, test.want) |
| 47 | } |
| 48 | }) |
| 49 | } |
| 50 | } |
| 51 | |