remove auth for tests
This commit is contained in:
parent
03e1d64aac
commit
4f45f39bc6
|
|
@ -51,17 +51,6 @@ import (
|
|||
|
||||
const signinURLStr = "https://ollama.com/connect?name=%s&key=%s"
|
||||
|
||||
var (
|
||||
webServiceBase = func() *url.URL {
|
||||
u, err := url.Parse("https://ollama.com")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return u
|
||||
}()
|
||||
webServiceClient = api.NewClient(webServiceBase, http.DefaultClient)
|
||||
)
|
||||
|
||||
func shouldUseHarmony(model *Model) bool {
|
||||
if slices.Contains([]string{"gptoss", "gpt-oss"}, model.Config.ModelFamily) {
|
||||
// heuristic to check whether the template expects to be parsed via harmony:
|
||||
|
|
@ -799,6 +788,7 @@ func (s *Server) WebSearchHandler(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
webServiceClient := api.NewClient(&url.URL{Scheme: "https", Host: "ollama.com"}, http.DefaultClient)
|
||||
resp, err := webServiceClient.WebSearch(c.Request.Context(), &req)
|
||||
if err != nil {
|
||||
var authError api.AuthorizationError
|
||||
|
|
@ -845,6 +835,7 @@ func (s *Server) WebFetchHandler(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
webServiceClient := api.NewClient(&url.URL{Scheme: "https", Host: "ollama.com"}, http.DefaultClient)
|
||||
resp, err := webServiceClient.WebFetch(c.Request.Context(), &req)
|
||||
if err != nil {
|
||||
var authError api.AuthorizationError
|
||||
|
|
|
|||
|
|
@ -92,7 +92,14 @@ func (t *panicTransport) RoundTrip(r *http.Request) (*http.Response, error) {
|
|||
|
||||
var panicOnRoundTrip = &http.Client{Transport: &panicTransport{}}
|
||||
|
||||
type roundTripFunc func(*http.Request) (*http.Response, error)
|
||||
|
||||
func (f roundTripFunc) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) }
|
||||
|
||||
func TestRoutes(t *testing.T) {
|
||||
// Disable authentication for tests to avoid issues with missing private keys
|
||||
t.Setenv("OLLAMA_AUTH", "false")
|
||||
|
||||
type testCase struct {
|
||||
Name string
|
||||
Method string
|
||||
|
|
@ -613,9 +620,39 @@ func TestRoutes(t *testing.T) {
|
|||
t.Fatalf("parse remote server URL: %v", err)
|
||||
}
|
||||
|
||||
origWebClient := webServiceClient
|
||||
webServiceClient = api.NewClient(remoteURL, remoteSrv.Client())
|
||||
t.Cleanup(func() { webServiceClient = origWebClient })
|
||||
origTransport := http.DefaultTransport
|
||||
remoteClient := remoteSrv.Client()
|
||||
remoteTransport := remoteClient.Transport
|
||||
if remoteTransport == nil {
|
||||
t.Fatalf("remote client transport is nil")
|
||||
}
|
||||
|
||||
http.DefaultTransport = roundTripFunc(func(req *http.Request) (*http.Response, error) {
|
||||
if req.URL == nil {
|
||||
panic("unexpected nil request URL")
|
||||
}
|
||||
if req.URL.Host != "ollama.com" {
|
||||
panic(fmt.Sprintf("unexpected outbound request to %s", req.URL))
|
||||
}
|
||||
|
||||
clone := req.Clone(req.Context())
|
||||
cloneURL := remoteURL.ResolveReference(&url.URL{
|
||||
Path: req.URL.Path,
|
||||
RawPath: req.URL.RawPath,
|
||||
RawQuery: req.URL.RawQuery,
|
||||
})
|
||||
clone.URL = cloneURL
|
||||
clone.Host = cloneURL.Host
|
||||
|
||||
return remoteTransport.RoundTrip(clone)
|
||||
})
|
||||
|
||||
t.Cleanup(func() {
|
||||
if closer, ok := remoteTransport.(interface{ CloseIdleConnections() }); ok {
|
||||
closer.CloseIdleConnections()
|
||||
}
|
||||
http.DefaultTransport = origTransport
|
||||
})
|
||||
|
||||
s := &Server{}
|
||||
router, err := s.GenerateRoutes(rc)
|
||||
|
|
|
|||
Loading…
Reference in New Issue