MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / TestHomeModelsAuthStatus

Function TestHomeModelsAuthStatus

internal/api/server_test.go:814–839  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

812}
813
814func TestHomeModelsAuthStatus(t *testing.T) {
815 cases := []struct {
816 name string
817 raw string
818 wantStatus int
819 wantHandled bool
820 }{
821 {"no credentials", `{"error":{"type":"no_credentials","message":"Missing API key"}}`, http.StatusUnauthorized, true},
822 {"invalid credential", `{"error":{"type":"invalid_credential","message":"Invalid API key"}}`, http.StatusUnauthorized, true},
823 {"internal error maps to bad gateway", `{"error":{"type":"internal_error","message":"boom"}}`, http.StatusBadGateway, true},
824 {"models payload not an error", `{"openai":[{"id":"gpt-5.5"}]}`, 0, false},
825 {"empty payload not an error", `{}`, 0, false},
826 }
827
828 for _, tc := range cases {
829 t.Run(tc.name, func(t *testing.T) {
830 status, handled := homeModelsAuthStatus([]byte(tc.raw))
831 if handled != tc.wantHandled {
832 t.Fatalf("handled = %v, want %v (status=%d)", handled, tc.wantHandled, status)
833 }
834 if handled && status != tc.wantStatus {
835 t.Fatalf("status = %d, want %d", status, tc.wantStatus)
836 }
837 })
838 }
839}
840
841func TestHomeModelsErrorMessage(t *testing.T) {
842 if msg := homeModelsErrorMessage([]byte(`{"error":{"type":"invalid_credential","message":"Invalid API key"}}`)); msg != "Invalid API key" {

Callers

nothing calls this directly

Calls 2

homeModelsAuthStatusFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected