(t *testing.T)
| 812 | } |
| 813 | |
| 814 | func 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 | |
| 841 | func TestHomeModelsErrorMessage(t *testing.T) { |
| 842 | if msg := homeModelsErrorMessage([]byte(`{"error":{"type":"invalid_credential","message":"Invalid API key"}}`)); msg != "Invalid API key" { |
nothing calls this directly
no test coverage detected