(t *testing.T)
| 3603 | } |
| 3604 | |
| 3605 | func Test_GetLatestRelease(t *testing.T) { |
| 3606 | serverTool := GetLatestRelease(translations.NullTranslationHelper) |
| 3607 | tool := serverTool.Tool |
| 3608 | require.NoError(t, toolsnaps.Test(tool.Name, tool)) |
| 3609 | |
| 3610 | schema, ok := tool.InputSchema.(*jsonschema.Schema) |
| 3611 | require.True(t, ok, "InputSchema should be *jsonschema.Schema") |
| 3612 | |
| 3613 | assert.Equal(t, "get_latest_release", tool.Name) |
| 3614 | assert.NotEmpty(t, tool.Description) |
| 3615 | assert.Contains(t, schema.Properties, "owner") |
| 3616 | assert.Contains(t, schema.Properties, "repo") |
| 3617 | assert.ElementsMatch(t, schema.Required, []string{"owner", "repo"}) |
| 3618 | |
| 3619 | mockRelease := &github.RepositoryRelease{ |
| 3620 | ID: github.Ptr(int64(1)), |
| 3621 | TagName: github.Ptr("v1.0.0"), |
| 3622 | Name: github.Ptr("First Release"), |
| 3623 | } |
| 3624 | |
| 3625 | tests := []struct { |
| 3626 | name string |
| 3627 | mockedClient *http.Client |
| 3628 | requestArgs map[string]any |
| 3629 | expectError bool |
| 3630 | expectedResult *github.RepositoryRelease |
| 3631 | expectedErrMsg string |
| 3632 | }{ |
| 3633 | { |
| 3634 | name: "successful latest release fetch", |
| 3635 | mockedClient: NewMockedHTTPClient( |
| 3636 | WithRequestMatch( |
| 3637 | GetReposReleasesLatestByOwnerByRepo, |
| 3638 | mockRelease, |
| 3639 | ), |
| 3640 | ), |
| 3641 | requestArgs: map[string]any{ |
| 3642 | "owner": "owner", |
| 3643 | "repo": "repo", |
| 3644 | }, |
| 3645 | expectError: false, |
| 3646 | expectedResult: mockRelease, |
| 3647 | }, |
| 3648 | { |
| 3649 | name: "latest release fetch fails", |
| 3650 | mockedClient: NewMockedHTTPClient( |
| 3651 | WithRequestMatchHandler( |
| 3652 | GetReposReleasesLatestByOwnerByRepo, |
| 3653 | http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 3654 | w.WriteHeader(http.StatusNotFound) |
| 3655 | _, _ = w.Write([]byte(`{"message": "Not Found"}`)) |
| 3656 | }), |
| 3657 | ), |
| 3658 | ), |
| 3659 | requestArgs: map[string]any{ |
| 3660 | "owner": "owner", |
| 3661 | "repo": "repo", |
| 3662 | }, |
nothing calls this directly
no test coverage detected