package cli import ( "net/http" "net/http/httptest" "testing" "gitea.mynodes.xyz/ilker/llmgw/internal/mirror" ) func TestTheMirrorRefusesEverythingButReads(t *testing.T) { // Stated here rather than inherited from http.FileServer, so a handler // added later cannot quietly make the mirror writable — which would turn // it into a way to replace a model with another one that every node then // fetches without complaint. h := readOnly(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) })) for _, m := range []string{http.MethodGet, http.MethodHead} { rec := httptest.NewRecorder() h.ServeHTTP(rec, httptest.NewRequest(m, "/x.gguf", nil)) if rec.Code != http.StatusOK { t.Errorf("%s was refused: %d", m, rec.Code) } } for _, m := range []string{http.MethodPut, http.MethodPost, http.MethodDelete, http.MethodPatch} { rec := httptest.NewRecorder() h.ServeHTTP(rec, httptest.NewRequest(m, "/x.gguf", nil)) if rec.Code != http.StatusMethodNotAllowed { t.Errorf("%s was allowed: %d", m, rec.Code) } } } func TestTheFilenameIsTakenFromTheURLWhenNotGiven(t *testing.T) { for _, c := range []struct{ url, want string }{ {"https://h/a/b/model.gguf", "model.gguf"}, {"https://h/model.gguf?download=true", "model.gguf"}, {"model.gguf", "model.gguf"}, } { if got := mirror.LastPathElement(c.url); got != c.want { t.Errorf("mirror.LastPathElement(%q) = %q, want %q", c.url, got, c.want) } } }