Skip to content

Commit 5c39e51

Browse files
3u13rnebril
authored andcommitted
commenter: test disable reactions
Add a test to assert that calling the react functions on the commenter doesn't result in calls against the GitHub API. Signed-off-by: Leonard Cohnen <leonard.cohnen@gmail.com>
1 parent 9ed8448 commit 5c39e51

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Authors of Cilium
3+
4+
package handlers
5+
6+
import (
7+
"context"
8+
"net/http"
9+
"net/http/httptest"
10+
"testing"
11+
12+
"github.com/google/go-github/v88/github"
13+
"github.com/rs/zerolog"
14+
"github.com/stretchr/testify/assert"
15+
)
16+
17+
func TestGithubCommenter_ReactionsDisabled(t *testing.T) {
18+
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
19+
t.Errorf("unexpected reaction request to %s", r.URL.Path)
20+
}))
21+
defer mockServer.Close()
22+
23+
mockURL := new(mockServer.URL + "/")
24+
client, err := github.NewClient(github.WithURLs(mockURL, mockURL))
25+
assert.NoError(t, err)
26+
27+
commenter := NewGithubCommenter(client, "owner", "repo", zerolog.Nop())
28+
commenter.setReactionsEnabled(false)
29+
30+
// Assert that calling the reaction functions doesn't result in a call to
31+
// the GitHub API when reactions are disabled.
32+
assert.NoError(t, commenter.reactToComment(context.Background(), 1, "eyes"))
33+
assert.NoError(t, commenter.reactToPR(context.Background(), 1, "rocket"))
34+
}

0 commit comments

Comments
 (0)