| 1 | package provider |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestEndpointOverrideRepeatsBase(t *testing.T) { |
| 6 | const base = "http://127.0.0.1:8000/v1" |
| 7 | cases := []struct { |
| 8 | name string |
| 9 | override string |
| 10 | bases []string |
| 11 | want bool |
| 12 | }{ |
| 13 | {"identical", base, []string{base}, true}, |
| 14 | {"trailing slash", base + "/", []string{base}, true}, |
| 15 | {"base with trailing slash", base, []string{base + "/"}, true}, |
| 16 | {"surrounding space", " " + base + " ", []string{base}, true}, |
| 17 | {"scheme and host case", "HTTP://LocalHost:8000/v1", []string{"http://localhost:8000/v1"}, true}, |
| 18 | {"second base", "https://api.example.com/v1", []string{"https://api.example.com", "https://api.example.com/v1"}, true}, |
| 19 | {"path case differs", "http://127.0.0.1:8000/V1", []string{base}, false}, |
| 20 | {"query", base + "?token=1", []string{base}, false}, |
| 21 | {"empty query", base + "?", []string{base}, false}, |
| 22 | {"fragment", base + "#debug", []string{base}, false}, |
| 23 | {"deeper path", base + "/chat/completions", []string{base}, false}, |
| 24 | {"other host", "http://127.0.0.2:8000/v1", []string{base}, false}, |
| 25 | {"other port", "http://127.0.0.1:8001/v1", []string{base}, false}, |
| 26 | {"other scheme", "https://127.0.0.1:8000/v1", []string{base}, false}, |
| 27 | {"empty override", "", []string{base}, false}, |
| 28 | {"relative override", "127.0.0.1:8000/v1", []string{base}, false}, |
| 29 | {"no bases", base, nil, false}, |
| 30 | } |
| 31 | for _, tc := range cases { |
| 32 | t.Run(tc.name, func(t *testing.T) { |
| 33 | if got := EndpointOverrideRepeatsBase(tc.override, tc.bases...); got != tc.want { |
| 34 | t.Fatalf("EndpointOverrideRepeatsBase(%q, %q) = %v, want %v", tc.override, tc.bases, got, tc.want) |
| 35 | } |
| 36 | }) |
| 37 | } |
| 38 | } |
| 39 |