(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func Test_GetMe(t *testing.T) { |
| 20 | t.Parallel() |
| 21 | |
| 22 | serverTool := GetMe(translations.NullTranslationHelper) |
| 23 | tool := serverTool.Tool |
| 24 | require.NoError(t, toolsnaps.Test(tool.Name, tool)) |
| 25 | |
| 26 | // Verify some basic very important properties |
| 27 | assert.Equal(t, "get_me", tool.Name) |
| 28 | assert.True(t, tool.Annotations.ReadOnlyHint, "get_me tool should be read-only") |
| 29 | |
| 30 | // Setup mock user response |
| 31 | mockUser := &github.User{ |
| 32 | Login: github.Ptr("testuser"), |
| 33 | Name: github.Ptr("Test User"), |
| 34 | Email: github.Ptr("test@example.com"), |
| 35 | Bio: github.Ptr("GitHub user for testing"), |
| 36 | Company: github.Ptr("Test Company"), |
| 37 | Location: github.Ptr("Test Location"), |
| 38 | HTMLURL: github.Ptr("https://github.com/testuser"), |
| 39 | CreatedAt: &github.Timestamp{Time: time.Now().Add(-365 * 24 * time.Hour)}, |
| 40 | Type: github.Ptr("User"), |
| 41 | Hireable: github.Ptr(true), |
| 42 | TwitterUsername: github.Ptr("testuser_twitter"), |
| 43 | Plan: &github.Plan{ |
| 44 | Name: github.Ptr("pro"), |
| 45 | }, |
| 46 | } |
| 47 | |
| 48 | tests := []struct { |
| 49 | name string |
| 50 | mockedClient *http.Client |
| 51 | clientErr string // if set, GetClient returns this error |
| 52 | requestArgs map[string]any |
| 53 | expectToolError bool |
| 54 | expectedUser *github.User |
| 55 | expectedToolErrMsg string |
| 56 | }{ |
| 57 | { |
| 58 | name: "successful get user", |
| 59 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 60 | GetUser: mockResponse(t, http.StatusOK, mockUser), |
| 61 | }), |
| 62 | requestArgs: map[string]any{}, |
| 63 | expectToolError: false, |
| 64 | expectedUser: mockUser, |
| 65 | }, |
| 66 | { |
| 67 | name: "successful get user with reason", |
| 68 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 69 | GetUser: mockResponse(t, http.StatusOK, mockUser), |
| 70 | }), |
| 71 | requestArgs: map[string]any{ |
| 72 | "reason": "Testing API", |
| 73 | }, |
| 74 | expectToolError: false, |
| 75 | expectedUser: mockUser, |
| 76 | }, |
nothing calls this directly
no test coverage detected