Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
rancoud committed Feb 15, 2024
1 parent dbb683a commit 0f26537
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ type requestTest struct {
}

func (r requestTest) assert(t *testing.T, req *http.Request) {
t.Helper()

assert.Equal(t, r.method, req.Method)
assert.Equal(t, r.host, req.Host)
assert.Equal(t, r.uri, req.URL.RequestURI())
}

func (rt *mockRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
defer rt.responsesMocked[rt.idxResponse].Body.Close()

rt.requestsTest[rt.idxResponse].assert(rt.test, req)

resp := rt.responsesMocked[rt.idxResponse]
Expand All @@ -42,6 +46,8 @@ func (rt *mockRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)
}

func TestMessageReactionsAll(t *testing.T) {
t.Parallel()

session, err := discordgo.New("fake-token")
require.NoError(t, err)

Expand All @@ -59,20 +65,23 @@ func TestMessageReactionsAll(t *testing.T) {
data1, _ := json.Marshal(expectedUsers[:2])
recorder1 := httptest.NewRecorder()
recorder1.Header().Add("Content-Type", "application/json")
recorder1.WriteString(string(data1))
_, err1 := recorder1.WriteString(string(data1))
require.NoError(t, err1)
expectedResponse1 := recorder1.Result()

// user 333
data2, _ := json.Marshal(expectedUsers[2:])
recorder2 := httptest.NewRecorder()
recorder2.Header().Add("Content-Type", "application/json")
recorder2.WriteString(string(data2))
_, err2 := recorder2.WriteString(string(data2))
require.NoError(t, err2)
expectedResponse2 := recorder2.Result()

// no user
recorder3 := httptest.NewRecorder()
recorder3.Header().Add("Content-Type", "application/json")
recorder3.WriteString("[]")
_, err3 := recorder3.WriteString("[]")
require.NoError(t, err3)
expectedResponse3 := recorder3.Result()

session.Client = createClient(t,
Expand All @@ -89,7 +98,10 @@ func TestMessageReactionsAll(t *testing.T) {
require.Equal(t, expectedUsers, actualUsers)
}

//nolint:funlen
func TestMessageReactionsAllErrors(t *testing.T) {
t.Parallel()

session, err := discordgo.New("fake-token")
require.NoError(t, err)

Expand All @@ -108,13 +120,15 @@ func TestMessageReactionsAllErrors(t *testing.T) {
data1, _ := json.Marshal(users[:2])
recorder1 := httptest.NewRecorder()
recorder1.Header().Add("Content-Type", "application/json")
recorder1.WriteString(string(data1))
_, err1 := recorder1.WriteString(string(data1))
require.NoError(t, err1)
expectedResponse1 := recorder1.Result()

// invalid json
recorder2 := httptest.NewRecorder()
recorder2.Header().Add("Content-Type", "application/json")
recorder2.WriteString("-")
_, err2 := recorder2.WriteString("-")
require.NoError(t, err2)
expectedResponse2 := recorder2.Result()

session.Client = createClient(t,
Expand All @@ -135,7 +149,8 @@ func TestMessageReactionsAllErrors(t *testing.T) {
data1, _ := json.Marshal(users[:2])
recorder1 := httptest.NewRecorder()
recorder1.Header().Add("Content-Type", "application/json")
recorder1.WriteString(string(data1))
_, err1 := recorder1.WriteString(string(data1))
require.NoError(t, err1)
expectedResponse1 := recorder1.Result()

// request failed
Expand Down

0 comments on commit 0f26537

Please sign in to comment.