From 9a546a9782aab33b9f3b437a59e6770a65598fe3 Mon Sep 17 00:00:00 2001 From: Carlos A Becker Date: Thu, 17 Nov 2022 22:58:09 -0300 Subject: [PATCH] test: internal/client/github tests Signed-off-by: Carlos A Becker --- internal/client/github_test.go | 30 +++++++++++++++++++ .../client/testdata/github/milestones.json | 1 + 2 files changed, 31 insertions(+) create mode 100644 internal/client/testdata/github/milestones.json diff --git a/internal/client/github_test.go b/internal/client/github_test.go index 983404527..5ecd26eb8 100644 --- a/internal/client/github_test.go +++ b/internal/client/github_test.go @@ -323,3 +323,33 @@ func TestReleaseNotes(t *testing.T) { require.NoError(t, err) require.Equal(t, "**Full Changelog**: https://github.com/someone/something/compare/v1.0.0...v1.1.0", log) } + +func TestCloseMilestone(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + defer r.Body.Close() + t.Log(r.URL.Path) + + if r.URL.Path == "/repos/someone/something/milestones" { + r, err := os.Open("testdata/github/milestones.json") + require.NoError(t, err) + _, err = io.Copy(w, r) + require.NoError(t, err) + return + } + })) + defer srv.Close() + + ctx := context.New(config.Project{ + GitHubURLs: config.GitHubURLs{ + API: srv.URL + "/", + }, + }) + client, err := NewGitHub(ctx, "test-token") + require.NoError(t, err) + repo := Repo{ + Owner: "someone", + Name: "something", + } + + require.NoError(t, client.CloseMilestone(ctx, repo, "v1.13.0")) +} diff --git a/internal/client/testdata/github/milestones.json b/internal/client/testdata/github/milestones.json new file mode 100644 index 000000000..c1980343e --- /dev/null +++ b/internal/client/testdata/github/milestones.json @@ -0,0 +1 @@ +[{"url":"https://api.github.com/repos/goreleaser/goreleaser/milestones/15","html_url":"https://github.com/goreleaser/goreleaser/milestone/15","labels_url":"https://api.github.com/repos/goreleaser/goreleaser/milestones/15/labels","id":8544910,"node_id":"MI_kwDOBJgEXs4AgmKO","number":15,"title":"v1.13.0","description":"","creator":{"login":"caarlos0","id":245435,"node_id":"MDQ6VXNlcjI0NTQzNQ==","avatar_url":"https://avatars.githubusercontent.com/u/245435?v=4","gravatar_id":"","url":"https://api.github.com/users/caarlos0","html_url":"https://github.com/caarlos0","followers_url":"https://api.github.com/users/caarlos0/followers","following_url":"https://api.github.com/users/caarlos0/following{/other_user}","gists_url":"https://api.github.com/users/caarlos0/gists{/gist_id}","starred_url":"https://api.github.com/users/caarlos0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caarlos0/subscriptions","organizations_url":"https://api.github.com/users/caarlos0/orgs","repos_url":"https://api.github.com/users/caarlos0/repos","events_url":"https://api.github.com/users/caarlos0/events{/privacy}","received_events_url":"https://api.github.com/users/caarlos0/received_events","type":"User","site_admin":false},"open_issues":6,"closed_issues":69,"state":"open","created_at":"2022-10-15T19:46:55Z","updated_at":"2022-11-18T00:42:55Z","due_on":null,"closed_at":null}] \ No newline at end of file