Improve (#356) to support registration of wildcard URLs (#359)

* Improve (#356) to support registration of wildcard URLs

* Add TestAzureChatCompletions & TestAzureChatCompletionsWithCustomDeploymentName

* Remove TestAzureChatCompletionsWithCustomDeploymentName

---------

Co-authored-by: coggsflod <richard.coggins@officedepot.com>
This commit is contained in:
Rich Coggins
2023-06-14 10:19:18 -04:00
committed by GitHub
parent 3f4e3bb0ca
commit 646989cc5b
2 changed files with 27 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ import (
"log"
"net/http"
"net/http/httptest"
"regexp"
)
const testAPI = "this-is-my-secure-token-do-not-steal!!"
@@ -36,11 +37,14 @@ func (ts *ServerTest) OpenAITestServer() *httptest.Server {
return
}
handlerCall, ok := ts.handlers[r.URL.Path]
if !ok {
http.Error(w, "the resource path doesn't exist", http.StatusNotFound)
return
// Handle /path/* routes.
for route, handler := range ts.handlers {
pattern, _ := regexp.Compile(route)
if pattern.MatchString(r.URL.Path) {
handler(w, r)
return
}
}
handlerCall(w, r)
http.Error(w, "the resource path doesn't exist", http.StatusNotFound)
}))
}